From a641342167c5d23547285737ad8a6ecd813c8817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Mon, 29 Jan 2024 12:45:19 +0100 Subject: [PATCH] chore: update codebase using Rector (#186) --- phpstan.neon.dist | 1 + psalm.xml.dist | 1 + rector.php | 45 +++++++++++++++++++ src/Bridge/PhpSpreadsheet/RowIterator.php | 7 +-- src/Bridge/PhpSpreadsheet/Spreadsheet.php | 5 +-- .../Functional/SpreadsheetIteratorTest.php | 21 +++++++-- .../PhpSpreadsheet/Test/RowIteratorTest.php | 2 + src/Bridge/Spout/RowIterator.php | 7 +-- src/Bridge/Spout/Spreadsheet.php | 5 +-- .../Functional/SpreadsheetIteratorTest.php | 33 ++++++++------ src/Bridge/Spout/Test/RowIteratorTest.php | 8 ++-- src/Bridge/Spout/Test/SpreadsheetTest.php | 2 + src/Bridge/Symfony/AppKernel.php | 9 +--- .../Symfony/Command/SerializeCommand.php | 10 +---- .../Symfony/Command/ValidateCommand.php | 10 +---- .../XezilairesExtensionTest.php | 13 +++--- .../Test/Functional/XezilairesBundleTest.php | 30 ++++++------- src/Bridge/Symfony/Validator.php | 7 +-- src/Xezilaires/Attribute/ArrayReference.php | 8 +--- src/Xezilaires/Attribute/ColumnReference.php | 5 +-- src/Xezilaires/Attribute/HeaderReference.php | 5 +-- src/Xezilaires/Attribute/Options.php | 14 +----- src/Xezilaires/Exception/MappingException.php | 3 -- src/Xezilaires/Metadata/ArrayReference.php | 10 +---- src/Xezilaires/Metadata/ColumnReference.php | 7 +-- src/Xezilaires/Metadata/HeaderReference.php | 7 +-- src/Xezilaires/ReverseIterator.php | 12 +---- .../Serializer/ObjectSerializer.php | 8 +--- src/Xezilaires/SpreadsheetIterator.php | 14 +----- src/Xezilaires/SpreadsheetIteratorFactory.php | 13 +----- src/Xezilaires/Test/FakeIterator.php | 2 +- src/Xezilaires/Test/FilterIteratorTest.php | 2 + .../Test/Functional/FunctionalTestCase.php | 23 ++-------- src/Xezilaires/Test/Metadata/MappingTest.php | 12 +++-- src/Xezilaires/Test/Model/Category.php | 4 +- .../Test/SpreadsheetIteratorTest.php | 11 +++++ 36 files changed, 165 insertions(+), 211 deletions(-) create mode 100644 rector.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 99e50a4..e08b3f3 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -18,6 +18,7 @@ parameters: - src/Xezilaires/vendor/ - var/ - vendor/ + - rector.php ignoreErrors: # false positive PHPStan 1.x - '#Return type \(bool\) of method class@anonymous/src/Xezilaires/Test/FixtureTrait.php:28::getRealPath#' diff --git a/psalm.xml.dist b/psalm.xml.dist index 9c433db..f570e28 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -16,6 +16,7 @@ + diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..420b9a5 --- /dev/null +++ b/rector.php @@ -0,0 +1,45 @@ +paths([ + __DIR__.'/src', + ]); + $rectorConfig->skip([ + __DIR__.'/src/Xezilaires/var', + __DIR__.'/src/Xezilaires/vendor', + __DIR__.'/src/Bridge/PhpSpreadsheet/var', + __DIR__.'/src/Bridge/PhpSpreadsheet/vendor', + __DIR__.'/src/Bridge/Spout/var', + __DIR__.'/src/Bridge/Spout/vendor', + __DIR__.'/src/Bridge/Symfony/var', + __DIR__.'/src/Bridge/Symfony/vendor', + ]); + $rectorConfig->sets([ + DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES, + LevelSetList::UP_TO_PHP_82, + PHPUnitSetList::PHPUNIT_90, + PHPUnitSetList::PHPUNIT_91, + PHPUnitSetList::PHPUNIT_100, + SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES, + SymfonySetList::SYMFONY_63, + SymfonySetList::SYMFONY_CODE_QUALITY, + SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION, + ]); +}; diff --git a/src/Bridge/PhpSpreadsheet/RowIterator.php b/src/Bridge/PhpSpreadsheet/RowIterator.php index 51eebf0..6d95a11 100644 --- a/src/Bridge/PhpSpreadsheet/RowIterator.php +++ b/src/Bridge/PhpSpreadsheet/RowIterator.php @@ -21,13 +21,10 @@ /** * @internal */ -final class RowIterator implements Iterator +final readonly class RowIterator implements Iterator { - private PhpSpreadsheetRowIterator $iterator; - - public function __construct(PhpSpreadsheetRowIterator $iterator) + public function __construct(private PhpSpreadsheetRowIterator $iterator) { - $this->iterator = $iterator; } public function current(): object diff --git a/src/Bridge/PhpSpreadsheet/Spreadsheet.php b/src/Bridge/PhpSpreadsheet/Spreadsheet.php index 1b84c49..461b8ef 100644 --- a/src/Bridge/PhpSpreadsheet/Spreadsheet.php +++ b/src/Bridge/PhpSpreadsheet/Spreadsheet.php @@ -25,8 +25,6 @@ final class Spreadsheet implements SpreadsheetInterface { - private \SplFileObject $file; - /** * @psalm-suppress PropertyNotSetInConstructor */ @@ -37,9 +35,8 @@ final class Spreadsheet implements SpreadsheetInterface */ private Iterator $iterator; - public function __construct(\SplFileObject $file) + public function __construct(private readonly \SplFileObject $file) { - $this->file = $file; } public static function fromFile(\SplFileObject $file): SpreadsheetInterface diff --git a/src/Bridge/PhpSpreadsheet/Test/Functional/SpreadsheetIteratorTest.php b/src/Bridge/PhpSpreadsheet/Test/Functional/SpreadsheetIteratorTest.php index 99d519b..ad9496a 100644 --- a/src/Bridge/PhpSpreadsheet/Test/Functional/SpreadsheetIteratorTest.php +++ b/src/Bridge/PhpSpreadsheet/Test/Functional/SpreadsheetIteratorTest.php @@ -14,6 +14,8 @@ namespace Xezilaires\Bridge\PhpSpreadsheet\Test\Functional; use Xezilaires\Bridge\PhpSpreadsheet\Spreadsheet; +use Xezilaires\Metadata\Attribute\AttributeDriver; +use Xezilaires\ReverseIterator; use Xezilaires\Spreadsheet as SpreadsheetInterface; use Xezilaires\Test\Functional\FunctionalTestCase; @@ -28,13 +30,26 @@ * @uses \Xezilaires\Metadata\Mapping * @uses \Xezilaires\Serializer\ObjectSerializer * - * @group functional - * @group phpspreadsheet - * * @internal * * @small */ +#[\PHPUnit\Framework\Attributes\Small] +#[\PHPUnit\Framework\Attributes\CoversClass(\Xezilaires\Bridge\PhpSpreadsheet\RowIterator::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(Spreadsheet::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Xezilaires\SpreadsheetIterator::class)] +#[\PHPUnit\Framework\Attributes\Group('functional')] +#[\PHPUnit\Framework\Attributes\Group('phpspreadsheet')] +#[\PHPUnit\Framework\Attributes\UsesClass(\Xezilaires\Metadata\ArrayReference::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(\Xezilaires\Metadata\ColumnReference::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(\Xezilaires\Metadata\HeaderReference::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(\Xezilaires\Metadata\Mapping::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(\Xezilaires\Serializer\ObjectSerializer::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(\Xezilaires\Attribute\ArrayReference::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(\Xezilaires\Attribute\ColumnReference::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(\Xezilaires\Attribute\HeaderReference::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(ReverseIterator::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(AttributeDriver::class)] final class SpreadsheetIteratorTest extends FunctionalTestCase { /** diff --git a/src/Bridge/PhpSpreadsheet/Test/RowIteratorTest.php b/src/Bridge/PhpSpreadsheet/Test/RowIteratorTest.php index 6fcaa6a..3438599 100644 --- a/src/Bridge/PhpSpreadsheet/Test/RowIteratorTest.php +++ b/src/Bridge/PhpSpreadsheet/Test/RowIteratorTest.php @@ -26,6 +26,8 @@ * * @small */ +#[\PHPUnit\Framework\Attributes\Small] +#[\PHPUnit\Framework\Attributes\CoversClass(RowIterator::class)] final class RowIteratorTest extends TestCase { public function testCanPerformValidCorrectly(): void diff --git a/src/Bridge/Spout/RowIterator.php b/src/Bridge/Spout/RowIterator.php index e58325f..3089310 100644 --- a/src/Bridge/Spout/RowIterator.php +++ b/src/Bridge/Spout/RowIterator.php @@ -22,21 +22,18 @@ */ final class RowIterator implements Iterator { - private RowIteratorInterface $iterator; - - private int $firstRow; + private readonly RowIteratorInterface $iterator; /** * @psalm-suppress PropertyNotSetInConstructor */ private int $highestRow; - public function __construct(RowIteratorInterface $iterator, int $firstRow) + public function __construct(RowIteratorInterface $iterator, private readonly int $firstRow) { $iterator->rewind(); $this->iterator = $iterator; - $this->firstRow = $firstRow; } public function current(): object diff --git a/src/Bridge/Spout/Spreadsheet.php b/src/Bridge/Spout/Spreadsheet.php index 0e5dac7..9d4faf7 100644 --- a/src/Bridge/Spout/Spreadsheet.php +++ b/src/Bridge/Spout/Spreadsheet.php @@ -30,8 +30,6 @@ final class Spreadsheet implements SpreadsheetInterface */ private static array $indexCache = []; - private \SplFileObject $file; - /** * @psalm-suppress PropertyNotSetInConstructor */ @@ -44,9 +42,8 @@ final class Spreadsheet implements SpreadsheetInterface */ private Iterator $iterator; - public function __construct(\SplFileObject $file) + public function __construct(private readonly \SplFileObject $file) { - $this->file = $file; } public static function fromFile(\SplFileObject $file): SpreadsheetInterface diff --git a/src/Bridge/Spout/Test/Functional/SpreadsheetIteratorTest.php b/src/Bridge/Spout/Test/Functional/SpreadsheetIteratorTest.php index 816a51c..8ab772a 100644 --- a/src/Bridge/Spout/Test/Functional/SpreadsheetIteratorTest.php +++ b/src/Bridge/Spout/Test/Functional/SpreadsheetIteratorTest.php @@ -14,27 +14,34 @@ namespace Xezilaires\Bridge\Spout\Test\Functional; use Xezilaires\Bridge\Spout\Spreadsheet; +use Xezilaires\Metadata\Attribute\AttributeDriver; +use Xezilaires\ReverseIterator; use Xezilaires\Spreadsheet as SpreadsheetInterface; use Xezilaires\Test\Functional\FunctionalTestCase; /** - * @covers \Xezilaires\Bridge\Spout\RowIterator - * @covers \Xezilaires\Bridge\Spout\Spreadsheet - * @covers \Xezilaires\SpreadsheetIterator - * - * @uses \Xezilaires\Metadata\ArrayReference - * @uses \Xezilaires\Metadata\ColumnReference - * @uses \Xezilaires\Metadata\HeaderReference - * @uses \Xezilaires\Metadata\Mapping - * @uses \Xezilaires\Serializer\ObjectSerializer - * - * @group functional - * @group spout - * * @internal * + * @coversNothing + * * @small */ +#[\PHPUnit\Framework\Attributes\Small] +#[\PHPUnit\Framework\Attributes\CoversClass(\Xezilaires\Bridge\Spout\RowIterator::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(Spreadsheet::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Xezilaires\SpreadsheetIterator::class)] +#[\PHPUnit\Framework\Attributes\Group('functional')] +#[\PHPUnit\Framework\Attributes\Group('spout')] +#[\PHPUnit\Framework\Attributes\UsesClass(\Xezilaires\Metadata\ArrayReference::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(\Xezilaires\Metadata\ColumnReference::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(\Xezilaires\Metadata\HeaderReference::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(\Xezilaires\Metadata\Mapping::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(\Xezilaires\Serializer\ObjectSerializer::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(\Xezilaires\Attribute\ArrayReference::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(\Xezilaires\Attribute\ColumnReference::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(\Xezilaires\Attribute\HeaderReference::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(AttributeDriver::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(ReverseIterator::class)] final class SpreadsheetIteratorTest extends FunctionalTestCase { /** diff --git a/src/Bridge/Spout/Test/RowIteratorTest.php b/src/Bridge/Spout/Test/RowIteratorTest.php index 21ce701..c5df406 100644 --- a/src/Bridge/Spout/Test/RowIteratorTest.php +++ b/src/Bridge/Spout/Test/RowIteratorTest.php @@ -24,6 +24,8 @@ * * @small */ +#[\PHPUnit\Framework\Attributes\Small] +#[\PHPUnit\Framework\Attributes\CoversClass(RowIterator::class)] final class RowIteratorTest extends TestCase { /** @@ -49,10 +51,9 @@ public static function provideCanDetermineHighestRowProperlyCases(): iterable } /** - * @dataProvider provideCanSeekProperlyCases - * * @param array $counts */ + #[\PHPUnit\Framework\Attributes\DataProvider('provideCanSeekProperlyCases')] public function testCanSeekProperly(int $startRow, int $currentRow, int $seekToRow, array $counts): void { $iterator = new RowIterator($this->mockIterator($currentRow, $counts), $startRow); @@ -60,11 +61,10 @@ public function testCanSeekProperly(int $startRow, int $currentRow, int $seekToR } /** - * @dataProvider provideCanDetermineHighestRowProperlyCases - * * @param array $counts * @param array $calls */ + #[\PHPUnit\Framework\Attributes\DataProvider('provideCanDetermineHighestRowProperlyCases')] public function testCanDetermineHighestRowProperly(int $startRow, int $currentRow, int $highestRow, array $counts, array $calls): void { // Spout bug workaround: we're calling prev() to realign the counter diff --git a/src/Bridge/Spout/Test/SpreadsheetTest.php b/src/Bridge/Spout/Test/SpreadsheetTest.php index 0057b0b..257a958 100644 --- a/src/Bridge/Spout/Test/SpreadsheetTest.php +++ b/src/Bridge/Spout/Test/SpreadsheetTest.php @@ -26,6 +26,8 @@ * * @small */ +#[\PHPUnit\Framework\Attributes\Small] +#[\PHPUnit\Framework\Attributes\CoversClass(Spreadsheet::class)] final class SpreadsheetTest extends TestCase { use FixtureTrait; diff --git a/src/Bridge/Symfony/AppKernel.php b/src/Bridge/Symfony/AppKernel.php index 837b2a1..aa2b774 100644 --- a/src/Bridge/Symfony/AppKernel.php +++ b/src/Bridge/Symfony/AppKernel.php @@ -25,19 +25,12 @@ */ final class AppKernel extends Kernel { - /** - * @var BundleInterface[] - */ - private array $customBundles; - /** * @param BundleInterface[] $customBundles */ - public function __construct(array $customBundles) + public function __construct(private readonly array $customBundles) { parent::__construct('prod', false); - - $this->customBundles = $customBundles; } /** diff --git a/src/Bridge/Symfony/Command/SerializeCommand.php b/src/Bridge/Symfony/Command/SerializeCommand.php index 2200c71..c049e44 100644 --- a/src/Bridge/Symfony/Command/SerializeCommand.php +++ b/src/Bridge/Symfony/Command/SerializeCommand.php @@ -30,22 +30,14 @@ )] final class SerializeCommand extends Command { - private IteratorFactory $iteratorFactory; - - private Serializer $serializer; - - public function __construct(IteratorFactory $iteratorFactory, Serializer $serializer) + public function __construct(private readonly IteratorFactory $iteratorFactory, private readonly Serializer $serializer) { parent::__construct(); - - $this->iteratorFactory = $iteratorFactory; - $this->serializer = $serializer; } protected function configure(): void { $this - ->setName('xezilaires:serialize') ->addArgument('class', InputArgument::REQUIRED, 'Process the rows as class') ->addArgument('path', InputArgument::REQUIRED, 'Path to file to process') ->addOption('bundle', 'B', InputOption::VALUE_REQUIRED, 'Custom project-specific bundle to load') diff --git a/src/Bridge/Symfony/Command/ValidateCommand.php b/src/Bridge/Symfony/Command/ValidateCommand.php index 450006d..6b73184 100644 --- a/src/Bridge/Symfony/Command/ValidateCommand.php +++ b/src/Bridge/Symfony/Command/ValidateCommand.php @@ -31,22 +31,14 @@ )] final class ValidateCommand extends Command { - private IteratorFactory $iteratorFactory; - - private Validator $validator; - - public function __construct(IteratorFactory $iteratorFactory, Validator $validator) + public function __construct(private readonly IteratorFactory $iteratorFactory, private readonly Validator $validator) { parent::__construct(); - - $this->iteratorFactory = $iteratorFactory; - $this->validator = $validator; } protected function configure(): void { $this - ->setName('xezilaires:serialize') ->addArgument('class', InputArgument::REQUIRED, 'Process the rows as class') ->addArgument('paths', InputArgument::REQUIRED | InputArgument::IS_ARRAY, 'Path(s) to file(s) to process') ->addOption('bundle', 'B', InputOption::VALUE_REQUIRED, 'Custom project-specific bundle to load') diff --git a/src/Bridge/Symfony/Test/Functional/DependencyInjection/XezilairesExtensionTest.php b/src/Bridge/Symfony/Test/Functional/DependencyInjection/XezilairesExtensionTest.php index 9a74dc0..e4b8b00 100644 --- a/src/Bridge/Symfony/Test/Functional/DependencyInjection/XezilairesExtensionTest.php +++ b/src/Bridge/Symfony/Test/Functional/DependencyInjection/XezilairesExtensionTest.php @@ -25,15 +25,16 @@ use Xezilaires\Serializer\ObjectSerializer; /** - * @covers \Xezilaires\Bridge\Symfony\DependencyInjection\XezilairesExtension - * - * @group functional - * @group symfony - * * @internal * - * @medium + * @coversNothing + * + * @small */ +#[\PHPUnit\Framework\Attributes\Medium] +#[\PHPUnit\Framework\Attributes\CoversClass(XezilairesExtension::class)] +#[\PHPUnit\Framework\Attributes\Group('functional')] +#[\PHPUnit\Framework\Attributes\Group('symfony')] final class XezilairesExtensionTest extends AbstractExtensionTestCase { public function testContainerHasValidator(): void diff --git a/src/Bridge/Symfony/Test/Functional/XezilairesBundleTest.php b/src/Bridge/Symfony/Test/Functional/XezilairesBundleTest.php index 415de88..0e8ac1e 100644 --- a/src/Bridge/Symfony/Test/Functional/XezilairesBundleTest.php +++ b/src/Bridge/Symfony/Test/Functional/XezilairesBundleTest.php @@ -30,24 +30,24 @@ use Xezilaires\Validator; /** - * @covers \Xezilaires\Bridge\Symfony\XezilairesBundle - * - * @uses \Xezilaires\Bridge\Spout\Spreadsheet - * @uses \Xezilaires\Bridge\Symfony\DependencyInjection\XezilairesExtension - * @uses \Xezilaires\Bridge\Symfony\Validator - * @uses \Xezilaires\Metadata\ColumnReference - * @uses \Xezilaires\Metadata\Mapping - * @uses \Xezilaires\Serializer\ObjectSerializer - * @uses \Xezilaires\SpreadsheetIterator - * @uses \Xezilaires\SpreadsheetIteratorFactory - * - * @group functional - * @group symfony - * * @internal * - * @medium + * @coversNothing + * + * @small */ +#[\PHPUnit\Framework\Attributes\Medium] +#[\PHPUnit\Framework\Attributes\CoversClass(XezilairesBundle::class)] +#[\PHPUnit\Framework\Attributes\Group('functional')] +#[\PHPUnit\Framework\Attributes\Group('symfony')] +#[\PHPUnit\Framework\Attributes\UsesClass(\Xezilaires\Bridge\Spout\Spreadsheet::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(\Xezilaires\Bridge\Symfony\DependencyInjection\XezilairesExtension::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(\Xezilaires\Bridge\Symfony\Validator::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(ColumnReference::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(Mapping::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(ObjectSerializer::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(SpreadsheetIterator::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(SpreadsheetIteratorFactory::class)] final class XezilairesBundleTest extends KernelTestCase { use FixtureTrait; diff --git a/src/Bridge/Symfony/Validator.php b/src/Bridge/Symfony/Validator.php index eb9bd38..7d562d3 100644 --- a/src/Bridge/Symfony/Validator.php +++ b/src/Bridge/Symfony/Validator.php @@ -16,13 +16,10 @@ use Symfony\Component\Validator\ConstraintViolationListInterface; use Symfony\Component\Validator\Validator\ValidatorInterface; -final class Validator implements \Xezilaires\Validator +final readonly class Validator implements \Xezilaires\Validator { - private ValidatorInterface $validator; - - public function __construct(ValidatorInterface $validator) + public function __construct(private ValidatorInterface $validator) { - $this->validator = $validator; } public function validate(object $object): ConstraintViolationListInterface diff --git a/src/Xezilaires/Attribute/ArrayReference.php b/src/Xezilaires/Attribute/ArrayReference.php index 7d1ae2a..e4da7cd 100644 --- a/src/Xezilaires/Attribute/ArrayReference.php +++ b/src/Xezilaires/Attribute/ArrayReference.php @@ -16,16 +16,10 @@ #[\Attribute(\Attribute::TARGET_PROPERTY)] final class ArrayReference { - /** - * @var Reference[] - */ - public array $references; - /** * @param Reference[] $references */ - public function __construct(array $references) + public function __construct(public array $references) { - $this->references = $references; } } diff --git a/src/Xezilaires/Attribute/ColumnReference.php b/src/Xezilaires/Attribute/ColumnReference.php index 652e9b6..bafacba 100644 --- a/src/Xezilaires/Attribute/ColumnReference.php +++ b/src/Xezilaires/Attribute/ColumnReference.php @@ -16,10 +16,7 @@ #[\Attribute(\Attribute::TARGET_PROPERTY)] final class ColumnReference implements Reference { - public string $column; - - public function __construct(string $column) + public function __construct(public string $column) { - $this->column = $column; } } diff --git a/src/Xezilaires/Attribute/HeaderReference.php b/src/Xezilaires/Attribute/HeaderReference.php index a1c820f..8ffd387 100644 --- a/src/Xezilaires/Attribute/HeaderReference.php +++ b/src/Xezilaires/Attribute/HeaderReference.php @@ -16,10 +16,7 @@ #[\Attribute(\Attribute::TARGET_PROPERTY)] final class HeaderReference implements Reference { - public string $header; - - public function __construct(string $header) + public function __construct(public string $header) { - $this->header = $header; } } diff --git a/src/Xezilaires/Attribute/Options.php b/src/Xezilaires/Attribute/Options.php index 204e704..c829f4a 100644 --- a/src/Xezilaires/Attribute/Options.php +++ b/src/Xezilaires/Attribute/Options.php @@ -16,19 +16,7 @@ #[\Attribute(\Attribute::TARGET_CLASS)] final class Options { - public int $start; - - public int $end; - - public int $header; - - public bool $reverse; - - public function __construct(int $start = 0, int $end = \PHP_INT_MAX, int $header = 0, bool $reverse = false) + public function __construct(public int $start = 0, public int $end = \PHP_INT_MAX, public int $header = 0, public bool $reverse = false) { - $this->start = $start; - $this->end = $end; - $this->header = $header; - $this->reverse = $reverse; } } diff --git a/src/Xezilaires/Exception/MappingException.php b/src/Xezilaires/Exception/MappingException.php index ed7a1a0..eadc572 100644 --- a/src/Xezilaires/Exception/MappingException.php +++ b/src/Xezilaires/Exception/MappingException.php @@ -72,9 +72,6 @@ public static function unexpectedReference(): self return new self('Unexpected reference type'); } - /** - * @param ExceptionInterface&\Throwable $exception - */ public static function invalidOption(ExceptionInterface $exception): self { return new self($exception->getMessage(), 0, $exception); diff --git a/src/Xezilaires/Metadata/ArrayReference.php b/src/Xezilaires/Metadata/ArrayReference.php index 56112de..da6fd7d 100644 --- a/src/Xezilaires/Metadata/ArrayReference.php +++ b/src/Xezilaires/Metadata/ArrayReference.php @@ -13,19 +13,13 @@ namespace Xezilaires\Metadata; -final class ArrayReference implements Reference +final readonly class ArrayReference implements Reference { - /** - * @var Reference[] - */ - private array $references; - /** * @param Reference[] $references */ - public function __construct(array $references) + public function __construct(private array $references) { - $this->references = $references; } /** diff --git a/src/Xezilaires/Metadata/ColumnReference.php b/src/Xezilaires/Metadata/ColumnReference.php index bde7bcf..bd70f34 100644 --- a/src/Xezilaires/Metadata/ColumnReference.php +++ b/src/Xezilaires/Metadata/ColumnReference.php @@ -13,13 +13,10 @@ namespace Xezilaires\Metadata; -final class ColumnReference implements Reference +final readonly class ColumnReference implements Reference { - private string $column; - - public function __construct(string $column) + public function __construct(private string $column) { - $this->column = $column; } public function getReference(): string diff --git a/src/Xezilaires/Metadata/HeaderReference.php b/src/Xezilaires/Metadata/HeaderReference.php index 612aea5..c176638 100644 --- a/src/Xezilaires/Metadata/HeaderReference.php +++ b/src/Xezilaires/Metadata/HeaderReference.php @@ -13,13 +13,10 @@ namespace Xezilaires\Metadata; -final class HeaderReference implements Reference +final readonly class HeaderReference implements Reference { - private string $header; - - public function __construct(string $header) + public function __construct(private string $header) { - $this->header = $header; } public function getReference(): string diff --git a/src/Xezilaires/ReverseIterator.php b/src/Xezilaires/ReverseIterator.php index 36cfffb..f6089dd 100644 --- a/src/Xezilaires/ReverseIterator.php +++ b/src/Xezilaires/ReverseIterator.php @@ -15,20 +15,10 @@ final class ReverseIterator implements Iterator { - private Iterator $iterator; - - private int $startIndex; - - private int $endIndex; - private int $index; - public function __construct(Iterator $iterator, int $startIndex, int $endIndex) + public function __construct(private readonly Iterator $iterator, private readonly int $startIndex, private readonly int $endIndex) { - $this->iterator = $iterator; - $this->startIndex = $startIndex; - $this->endIndex = $endIndex; - $this->rewind(); } diff --git a/src/Xezilaires/Serializer/ObjectSerializer.php b/src/Xezilaires/Serializer/ObjectSerializer.php index 9af42f9..e8c76a4 100644 --- a/src/Xezilaires/Serializer/ObjectSerializer.php +++ b/src/Xezilaires/Serializer/ObjectSerializer.php @@ -20,17 +20,11 @@ final class ObjectSerializer implements Denormalizer, Serializer { - /** - * @var DenormalizerInterface&SerializerInterface - */ - private $serializer; - /** * @param DenormalizerInterface&SerializerInterface $serializer */ - public function __construct($serializer) + public function __construct(private $serializer) { - $this->serializer = $serializer; } public function denormalize(array $data, string $class, ?string $format = null, array $context = []): object diff --git a/src/Xezilaires/SpreadsheetIterator.php b/src/Xezilaires/SpreadsheetIterator.php index 006903c..983e268 100644 --- a/src/Xezilaires/SpreadsheetIterator.php +++ b/src/Xezilaires/SpreadsheetIterator.php @@ -23,14 +23,6 @@ final class SpreadsheetIterator implements Iterator { - private Spreadsheet $spreadsheet; - - private Mapping $mapping; - - private Denormalizer $denormalizer; - - private array $context; - /** * @psalm-suppress PropertyNotSetInConstructor */ @@ -45,12 +37,8 @@ final class SpreadsheetIterator implements Iterator private int $index = 0; - public function __construct(Spreadsheet $spreadsheet, Mapping $mapping, Denormalizer $denormalizer, array $context = []) + public function __construct(private readonly Spreadsheet $spreadsheet, private readonly Mapping $mapping, private readonly Denormalizer $denormalizer, private readonly array $context = []) { - $this->spreadsheet = $spreadsheet; - $this->mapping = $mapping; - $this->denormalizer = $denormalizer; - $this->context = $context; } public function current(): object diff --git a/src/Xezilaires/SpreadsheetIteratorFactory.php b/src/Xezilaires/SpreadsheetIteratorFactory.php index 7628c1a..42a789b 100644 --- a/src/Xezilaires/SpreadsheetIteratorFactory.php +++ b/src/Xezilaires/SpreadsheetIteratorFactory.php @@ -15,22 +15,13 @@ use Xezilaires\Metadata\Mapping; -final class SpreadsheetIteratorFactory implements IteratorFactory +final readonly class SpreadsheetIteratorFactory implements IteratorFactory { - private Denormalizer $denormalizer; - - /** - * @var array> - */ - private array $spreadsheetClasses; - /** * @param array> $spreadsheetClasses */ - public function __construct(Denormalizer $denormalizer, array $spreadsheetClasses) + public function __construct(private Denormalizer $denormalizer, private array $spreadsheetClasses) { - $this->denormalizer = $denormalizer; - $this->spreadsheetClasses = $spreadsheetClasses; } /** diff --git a/src/Xezilaires/Test/FakeIterator.php b/src/Xezilaires/Test/FakeIterator.php index 36b7215..6c6aa42 100644 --- a/src/Xezilaires/Test/FakeIterator.php +++ b/src/Xezilaires/Test/FakeIterator.php @@ -20,7 +20,7 @@ */ final class FakeIterator implements Iterator { - private \ArrayIterator $iterator; + private readonly \ArrayIterator $iterator; /** * @param array $items diff --git a/src/Xezilaires/Test/FilterIteratorTest.php b/src/Xezilaires/Test/FilterIteratorTest.php index c3bbb13..3708474 100644 --- a/src/Xezilaires/Test/FilterIteratorTest.php +++ b/src/Xezilaires/Test/FilterIteratorTest.php @@ -23,6 +23,8 @@ * * @small */ +#[\PHPUnit\Framework\Attributes\Small] +#[\PHPUnit\Framework\Attributes\CoversClass(FilterIterator::class)] final class FilterIteratorTest extends TestCase { public function testCanFilterOutIteratorItems(): void diff --git a/src/Xezilaires/Test/Functional/FunctionalTestCase.php b/src/Xezilaires/Test/Functional/FunctionalTestCase.php index 86d7a7e..604ea54 100644 --- a/src/Xezilaires/Test/Functional/FunctionalTestCase.php +++ b/src/Xezilaires/Test/Functional/FunctionalTestCase.php @@ -13,6 +13,7 @@ namespace Xezilaires\Test\Functional; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; use Symfony\Component\Serializer\Serializer; @@ -23,6 +24,7 @@ use Xezilaires\Metadata\ColumnReference; use Xezilaires\Metadata\HeaderReference; use Xezilaires\Metadata\Mapping; +use Xezilaires\ReverseIterator; use Xezilaires\Serializer\ObjectSerializer; use Xezilaires\Spreadsheet; use Xezilaires\SpreadsheetIterator; @@ -34,6 +36,7 @@ /** * @internal */ +#[UsesClass(ReverseIterator::class)] abstract class FunctionalTestCase extends TestCase { use FixtureTrait; @@ -112,9 +115,6 @@ public function testCanLoadFlatFixtureWithArrayReference(): void ], $iterator); } - /** - * @uses \Xezilaires\Attribute\HeaderReference - */ public function testCanLoadSparseFixtureWithHeaderReference(): void { $iterator = $this->createIterator( @@ -143,12 +143,6 @@ public function testCanLoadSparseFixtureWithHeaderReference(): void * @throws \ReflectionException * @throws \RuntimeException * @throws \ReflectionException - * - * @uses \Xezilaires\Attribute\ArrayReference - * @uses \Xezilaires\Attribute\ColumnReference - * @uses \Xezilaires\Attribute\HeaderReference - *@uses \Xezilaires\Attribute\Options - * @uses \Xezilaires\Metadata\Attribute\AttributeDriver */ public function testCanLoadSparseFixtureWithAttributes(): void { @@ -171,11 +165,6 @@ public function testCanLoadSparseFixtureWithAttributes(): void * @throws \ReflectionException * @throws \RuntimeException * @throws \ReflectionException - * - * @uses \Xezilaires\Attribute\ColumnReference - * @uses \Xezilaires\Attribute\HeaderReference - * @uses \Xezilaires\Attribute\Options - *@uses \Xezilaires\Metadata\Attribute\AttributeDriver */ public function testCanLoadSparseFixtureWithNativeAttributes(): void { @@ -340,9 +329,6 @@ public function testCanRewindIterator(): void self::assertSame($current->price, $actual->price); } - /** - * @uses \Xezilaires\ReverseIterator - */ public function testCanLoadFlatFixtureInReverse(): void { $iterator = $this->createIterator( @@ -391,9 +377,6 @@ public function testCanLoadIteratorSequentially(): void ], $iterator); } - /** - * @uses \Xezilaires\ReverseIterator - */ public function testCanLoadReverseIteratorSequentially(): void { $iterator = $this->createIterator( diff --git a/src/Xezilaires/Test/Metadata/MappingTest.php b/src/Xezilaires/Test/Metadata/MappingTest.php index 6689ca4..e2809c8 100644 --- a/src/Xezilaires/Test/Metadata/MappingTest.php +++ b/src/Xezilaires/Test/Metadata/MappingTest.php @@ -29,11 +29,11 @@ * * @small */ +#[\PHPUnit\Framework\Attributes\Small] +#[\PHPUnit\Framework\Attributes\CoversClass(Mapping::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(ColumnReference::class)] final class MappingTest extends TestCase { - /** - * @uses \Xezilaires\Metadata\ColumnReference - */ public function testMappingHasDefaultOptions(): void { $mapping = new Mapping(Product::class, ['name' => new ColumnReference('A')]); @@ -45,12 +45,11 @@ public function testMappingHasDefaultOptions(): void } /** - * @dataProvider provideCanCreateValidMappingCases - * * @param class-string $className * @param array $columns * @param null|array $options */ + #[\PHPUnit\Framework\Attributes\DataProvider('provideCanCreateValidMappingCases')] public function testCanCreateValidMapping(string $className, array $columns, ?array $options = null): void { $mapping = new Mapping($className, $columns, $options); @@ -66,13 +65,12 @@ public function testCanCreateValidMapping(string $className, array $columns, ?ar } /** - * @dataProvider provideCannotCreateInvalidMappingCases - * * @psalm-suppress MixedArgumentTypeCoercion intentionally testing invalid mappings * * @param array $columns * @param null|array $options */ + #[\PHPUnit\Framework\Attributes\DataProvider('provideCannotCreateInvalidMappingCases')] public function testCannotCreateInvalidMapping( string $exceptionMessage, string $className, diff --git a/src/Xezilaires/Test/Model/Category.php b/src/Xezilaires/Test/Model/Category.php index 4750bc5..c1f4e78 100644 --- a/src/Xezilaires/Test/Model/Category.php +++ b/src/Xezilaires/Test/Model/Category.php @@ -13,11 +13,11 @@ namespace Xezilaires\Test\Model; -final class Category +final class Category implements \Stringable { public int $id; - public ?int $parent; + public ?int $parent = null; public string $name; diff --git a/src/Xezilaires/Test/SpreadsheetIteratorTest.php b/src/Xezilaires/Test/SpreadsheetIteratorTest.php index b8a395b..54382ff 100644 --- a/src/Xezilaires/Test/SpreadsheetIteratorTest.php +++ b/src/Xezilaires/Test/SpreadsheetIteratorTest.php @@ -22,6 +22,7 @@ use Xezilaires\Metadata\ColumnReference; use Xezilaires\Metadata\HeaderReference; use Xezilaires\Metadata\Mapping; +use Xezilaires\ReverseIterator; use Xezilaires\Spreadsheet; use Xezilaires\SpreadsheetIterator; @@ -37,6 +38,16 @@ * * @small */ +#[\PHPUnit\Framework\Attributes\Small] +#[\PHPUnit\Framework\Attributes\CoversClass(Mapping::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(SpreadsheetIterator::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(ArrayReference::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(ColumnReference::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(HeaderReference::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(ReverseIterator::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(\Xezilaires\Attribute\ArrayReference::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(\Xezilaires\Attribute\ColumnReference::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(\Xezilaires\Attribute\HeaderReference::class)] final class SpreadsheetIteratorTest extends TestCase { public function testCanPerformValidCorrectly(): void