Skip to content

Commit

Permalink
breaking change: bump to Laravel 9 or Laravel 10. Minimum PHP version…
Browse files Browse the repository at this point in the history
…: 8.1. Updated php-cs-fixer, and implemented fix and analyse script with phpstan
  • Loading branch information
mauriziofonte committed Mar 8, 2023
1 parent f20ec74 commit 7a2a887
Show file tree
Hide file tree
Showing 18 changed files with 54 additions and 35 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
build
composer.lock
docs
vendor
vendor/
.test/
.php_cs.cache
.phpunit.result.cache
.php-cs-fixer.cache
8 changes: 5 additions & 3 deletions .php_cs.dist.php → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

$finder = Symfony\Component\Finder\Finder::create()
$finder = PhpCsFixer\Finder::create()
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
Expand All @@ -10,7 +9,8 @@
->ignoreDotFiles(true)
->ignoreVCS(true);

return (new PhpCsFixer\Config())
$config = new PhpCsFixer\Config();
$config
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
Expand Down Expand Up @@ -38,3 +38,5 @@
'single_trait_insert_per_statement' => true,
])
->setFinder($finder);

return $config;
15 changes: 10 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@
],
"require": {
"php": "^8.1",
"ext-openssl": ">1.0.2",
"illuminate/support": "^9.0 || ^10.0",
"nesbot/carbon": "^2.0",
"spatie/laravel-package-tools": "^1.14"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.4",
"phpstan/phpstan": "^1.9",
"mockery/mockery": "^1.3.3",
"orchestra/testbench": "^6.0",
"phpunit/phpunit": "^9.3",
"spatie/phpunit-snapshot-assertions": "^4.0",
"spatie/temporary-directory": "^1.2.4"
"orchestra/testbench": "^7.0",
"phpunit/phpunit": "^9.5",
"spatie/phpunit-snapshot-assertions": "^4.2",
"spatie/temporary-directory": "^2.1"
},
"config": {
"sort-packages": true
Expand All @@ -58,6 +61,8 @@
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"test": "vendor/bin/phpunit"
"test": "vendor/bin/phpunit",
"fix": "@php vendor/bin/php-cs-fixer fix",
"analyse": "@php vendor/bin/phpstan analyse src --level 4"
}
}
12 changes: 8 additions & 4 deletions src/Sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@

class Sitemap implements Responsable, Renderable
{
/** @var \Spatie\Sitemap\Tags\Url[] */
/** @var \Mfonte\Sitemap\Tags\Url[] */
protected $tags = [];

public static function create()
{
return new static();
}

final public function __construct()
{
}

/**
* @param $tag string|Url|Sitemapable
*/
Expand Down Expand Up @@ -68,14 +72,14 @@ public function hasUrl(string $url): bool
public function hasImages() : bool
{
return (bool) collect($this->tags)->first(function (Tag $tag) {
return $tag->getType() === 'url' && !empty($tag->images);
return $tag->getType() === 'url' && ! empty($tag->images);
});
}

public function hasNews() : bool
{
return (bool) collect($this->tags)->first(function (Tag $tag) {
return $tag->getType() === 'url' && !empty($tag->news);
return $tag->getType() === 'url' && ! empty($tag->news);
});
}

Expand Down Expand Up @@ -116,4 +120,4 @@ public function toResponse($request)
'Content-Type' => 'text/xml',
]);
}
}
}
6 changes: 5 additions & 1 deletion src/SitemapIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@

class SitemapIndex implements Responsable, Renderable
{
/** @var \Spatie\Sitemap\Tags\Sitemap[] */
/** @var \Mfonte\Sitemap\Tags\Sitemap[] */
protected array $tags = [];

public static function create()
{
return new static();
}

final public function __construct()
{
}

/**
* @param $tag string|Sitemap
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Tags/Alternate.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static function create(string $url, string $locale = '')
return new static($url, $locale);
}

public function __construct(string $url, $locale = '')
final public function __construct(string $url, $locale = '')
{
$this->setUrl($url);

Expand All @@ -35,4 +35,4 @@ public function setLocale(string $locale = '')

return $this;
}
}
}
4 changes: 2 additions & 2 deletions src/Tags/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static function create(
return new static($url, $caption, $geo_location, $title, $license);
}

public function __construct(
final public function __construct(
string $url,
string $caption = '',
string $geo_location = '',
Expand Down Expand Up @@ -82,4 +82,4 @@ public function setLicense(string $license = '')

return $this;
}
}
}
5 changes: 2 additions & 3 deletions src/Tags/News.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static function create(
return new static($name, $language, $publication_date, $title);
}

public function __construct(
final public function __construct(
string $name,
string $language,
?DateTimeInterface $publication_date,
Expand Down Expand Up @@ -58,7 +58,6 @@ public function setLanguage(string $language)

return $this;
}


public function setPublicationDate(?DateTimeInterface $publication_date = null)
{
Expand All @@ -75,4 +74,4 @@ public function setTitle(string $title)

return $this;
}
}
}
5 changes: 3 additions & 2 deletions src/Tags/Sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

class Sitemap extends Tag
{
public string $url;
/** @var string */
public $url;

/** @var Carbon */
public $lastModificationDate;
Expand All @@ -17,7 +18,7 @@ public static function create(string $url)
return new static($url);
}

public function __construct(string $url)
final public function __construct(string $url)
{
$this->url = $url;

Expand Down
3 changes: 3 additions & 0 deletions src/Tags/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

abstract class Tag
{
/** @var string */
public $url;

public function getType(): string
{
return mb_strtolower(class_basename(static::class));
Expand Down
6 changes: 3 additions & 3 deletions src/Tags/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static function create(string $url)
return new static($url);
}

public function __construct(string $url)
final public function __construct(string $url)
{
$this->url = $url;

Expand Down Expand Up @@ -114,7 +114,7 @@ public function path(): string
}

/**
* @param integer|null $index
* @param int|null $index
*
* @return array|string|null
*/
Expand All @@ -138,4 +138,4 @@ public function segment(int $index): ?string
{
return $this->segments()[$index - 1] ?? null;
}
}
}
2 changes: 1 addition & 1 deletion tests/AlternateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ public function locale_can_be_set()

$this->assertEquals('en', $this->alternate->locale);
}
}
}
2 changes: 1 addition & 1 deletion tests/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ public function license_can_be_set()

$this->assertEquals('some_random_photographer', $this->image->license);
}
}
}
2 changes: 1 addition & 1 deletion tests/NewsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ public function title_can_be_set()

$this->assertEquals('a_beautiful_title', $this->news->title);
}
}
}
2 changes: 1 addition & 1 deletion tests/SitemapIndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,4 @@ public function an_instance_can_return_a_response()

$this->assertInstanceOf(Response::class, $this->index->toResponse(new Request));
}
}
}
2 changes: 1 addition & 1 deletion tests/SitemapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,4 @@ public function toSitemapTag()

$this->assertMatchesXmlSnapshot($this->sitemap->render());
}
}
}
4 changes: 2 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Mfonte\Sitemap\Test;

use Carbon\Carbon;
use Orchestra\Testbench\TestCase as OrchestraTestCase;
use Mfonte\Sitemap\SitemapServiceProvider;
use Orchestra\Testbench\TestCase as OrchestraTestCase;
use Spatie\Snapshots\MatchesSnapshots;
use Spatie\TemporaryDirectory\TemporaryDirectory;

Expand Down Expand Up @@ -33,4 +33,4 @@ protected function getPackageProviders($app)
SitemapServiceProvider::class,
];
}
}
}
4 changes: 2 additions & 2 deletions tests/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Mfonte\Sitemap\Test;

use Carbon\Carbon;
use Mfonte\Sitemap\Tags\Alternate;
use Mfonte\Sitemap\Tags\Image;
use Mfonte\Sitemap\Tags\News;
use Mfonte\Sitemap\Tags\Alternate;
use Mfonte\Sitemap\Tags\Url;

class UrlTest extends TestCase
Expand Down Expand Up @@ -218,4 +218,4 @@ public function it_will_return_null_for_a_non_existing_segment()
{
$this->assertNull(Url::create('http://example.com/part1/part2/part3')->segment(5));
}
}
}

0 comments on commit 7a2a887

Please sign in to comment.