Skip to content

Commit

Permalink
chore: update codebase using Rector (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarlovi authored Jan 29, 2024
1 parent 4c8456e commit a641342
Show file tree
Hide file tree
Showing 36 changed files with 165 additions and 211 deletions.
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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#'
1 change: 1 addition & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<directory name="./"/>
<ignoreFiles allowMissingFiles="true">
<file name=".php-cs-fixer.dist.php"/>
<file name="rector.php"/>
<file name="src/Xezilaires/Test/ExampleBundle/XezilairesExampleBundle.php"/>
<directory name="src/Bridge/*/var/"/>
<directory name="src/Bridge/*/vendor/"/>
Expand Down
45 changes: 45 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

/*
* This file is part of the xezilaires project.
*
* (c) sigwin.hr
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

use Rector\Config\RectorConfig;
use Rector\Doctrine\Set\DoctrineSetList;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Symfony\Set\SymfonySetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->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,
]);
};
7 changes: 2 additions & 5 deletions src/Bridge/PhpSpreadsheet/RowIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/Bridge/PhpSpreadsheet/Spreadsheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

final class Spreadsheet implements SpreadsheetInterface
{
private \SplFileObject $file;

/**
* @psalm-suppress PropertyNotSetInConstructor
*/
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
{
/**
Expand Down
2 changes: 2 additions & 0 deletions src/Bridge/PhpSpreadsheet/Test/RowIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
*
* @small
*/
#[\PHPUnit\Framework\Attributes\Small]
#[\PHPUnit\Framework\Attributes\CoversClass(RowIterator::class)]
final class RowIteratorTest extends TestCase
{
public function testCanPerformValidCorrectly(): void
Expand Down
7 changes: 2 additions & 5 deletions src/Bridge/Spout/RowIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/Bridge/Spout/Spreadsheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ final class Spreadsheet implements SpreadsheetInterface
*/
private static array $indexCache = [];

private \SplFileObject $file;

/**
* @psalm-suppress PropertyNotSetInConstructor
*/
Expand All @@ -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
Expand Down
33 changes: 20 additions & 13 deletions src/Bridge/Spout/Test/Functional/SpreadsheetIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand Down
8 changes: 4 additions & 4 deletions src/Bridge/Spout/Test/RowIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*
* @small
*/
#[\PHPUnit\Framework\Attributes\Small]
#[\PHPUnit\Framework\Attributes\CoversClass(RowIterator::class)]
final class RowIteratorTest extends TestCase
{
/**
Expand All @@ -49,22 +51,20 @@ public static function provideCanDetermineHighestRowProperlyCases(): iterable
}

/**
* @dataProvider provideCanSeekProperlyCases
*
* @param array<string, int> $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);
$iterator->seek($seekToRow);
}

/**
* @dataProvider provideCanDetermineHighestRowProperlyCases
*
* @param array<string, int> $counts
* @param array<string, 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
Expand Down
2 changes: 2 additions & 0 deletions src/Bridge/Spout/Test/SpreadsheetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
*
* @small
*/
#[\PHPUnit\Framework\Attributes\Small]
#[\PHPUnit\Framework\Attributes\CoversClass(Spreadsheet::class)]
final class SpreadsheetTest extends TestCase
{
use FixtureTrait;
Expand Down
9 changes: 1 addition & 8 deletions src/Bridge/Symfony/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
10 changes: 1 addition & 9 deletions src/Bridge/Symfony/Command/SerializeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
10 changes: 1 addition & 9 deletions src/Bridge/Symfony/Command/ValidateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit a641342

Please sign in to comment.