diff --git a/.gitattributes b/.gitattributes index 18ea6a59c..1c8e1637b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9,6 +9,7 @@ docs export-ignore Makefile export-ignore phpunit.xml.dist export-ignore bin/console export-ignore +rector.php export-ignore phpstan.neon.dist export-ignore phpstan-baseline.neon export-ignore phpstan-console-application.php export-ignore diff --git a/.github/workflows/qa.yaml b/.github/workflows/qa.yaml index c10ad8def..9f3348a08 100644 --- a/.github/workflows/qa.yaml +++ b/.github/workflows/qa.yaml @@ -66,3 +66,28 @@ jobs: - name: Psalm run: vendor/bin/psalm --no-progress --show-info=false --stats --output-format=github --threads=$(nproc) --shepherd --php-version=8.1 + + rector: + name: Rector + + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Install PHP with extensions + uses: shivammathur/setup-php@v2 + with: + php-version: '8.1' + coverage: none + tools: composer:v2 + + - name: Install Composer dependencies (highest) + uses: ramsey/composer-install@v2 + with: + dependency-versions: highest + composer-options: --prefer-dist --prefer-stable + + - name: Rector + run: vendor/bin/rector --no-progress-bar --dry-run diff --git a/Makefile b/Makefile index d7221e853..6f553c20b 100644 --- a/Makefile +++ b/Makefile @@ -119,3 +119,7 @@ phpstan: psalm: vendor/bin/psalm --php-version=8.1 .PHONY: psalm + +rector: + vendor/bin/rector +.PHONY: rector diff --git a/composer.json b/composer.json index d3e596c8b..9add33f7d 100644 --- a/composer.json +++ b/composer.json @@ -63,8 +63,9 @@ "phpstan/phpstan-strict-rules": "^1.0", "phpstan/phpstan-symfony": "^1.0", "phpunit/phpunit": "^9.5", - "psalm/plugin-phpunit": "^0.16", + "psalm/plugin-phpunit": "^0.17", "psalm/plugin-symfony": "^3.0", + "rector/rector": "^0.13", "sonata-project/admin-bundle": "^4.9", "sonata-project/block-bundle": "^4.11", "sonata-project/doctrine-orm-admin-bundle": "^4.0", diff --git a/rector.php b/rector.php new file mode 100644 index 000000000..37a5a4fd1 --- /dev/null +++ b/rector.php @@ -0,0 +1,41 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + + /* + * DO NOT EDIT THIS FILE! + * + * It's auto-generated by sonata-project/dev-kit package. + */ + +use Rector\Config\RectorConfig; +use Rector\Php70\Rector\FunctionLike\ExceptionHandlerTypehintRector; +use Rector\Php71\Rector\FuncCall\CountOnNullRector; +use Rector\Set\ValueObject\LevelSetList; + +return static function (RectorConfig $rectorConfig): void { + $rectorConfig->paths([ + __DIR__.'/src', + __DIR__.'/tests', + ]); + + $rectorConfig->sets([ + LevelSetList::UP_TO_PHP_74, + ]); + + $rectorConfig->importNames(); + $rectorConfig->disableImportShortClasses(); + $rectorConfig->skip([ + CountOnNullRector::class, + ExceptionHandlerTypehintRector::class, + ]); +}; diff --git a/src/Admin/Model/UserAdmin.php b/src/Admin/Model/UserAdmin.php index 6817fd534..338acda88 100644 --- a/src/Admin/Model/UserAdmin.php +++ b/src/Admin/Model/UserAdmin.php @@ -20,11 +20,12 @@ use Sonata\AdminBundle\Form\FormMapper; use Sonata\AdminBundle\Show\ShowMapper; use Sonata\UserBundle\Form\Type\RolesMatrixType; +use Sonata\UserBundle\Model\UserInterface; use Sonata\UserBundle\Model\UserManagerInterface; use Symfony\Component\Form\Extension\Core\Type\TextType; /** - * @phpstan-extends AbstractAdmin<\Sonata\UserBundle\Model\UserInterface> + * @phpstan-extends AbstractAdmin */ class UserAdmin extends AbstractAdmin { @@ -108,8 +109,9 @@ protected function configureFormFields(FormMapper $form): void protected function configureExportFields(): array { // Avoid sensitive properties to be exported. - return array_filter(parent::configureExportFields(), static function (string $v): bool { - return !\in_array($v, ['password', 'salt'], true); - }); + return array_filter( + parent::configureExportFields(), + static fn (string $v): bool => !\in_array($v, ['password', 'salt'], true) + ); } } diff --git a/src/Form/Type/ResettingFormType.php b/src/Form/Type/ResettingFormType.php index c4a4460b9..99905211d 100644 --- a/src/Form/Type/ResettingFormType.php +++ b/src/Form/Type/ResettingFormType.php @@ -13,6 +13,7 @@ namespace Sonata\UserBundle\Form\Type; +use Sonata\UserBundle\Model\UserInterface; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\PasswordType; use Symfony\Component\Form\Extension\Core\Type\RepeatedType; @@ -22,12 +23,12 @@ final class ResettingFormType extends AbstractType { /** - * @phpstan-var class-string<\Sonata\UserBundle\Model\UserInterface> + * @phpstan-var class-string */ private string $class; /** - * @phpstan-param class-string<\Sonata\UserBundle\Model\UserInterface> $class + * @phpstan-param class-string $class */ public function __construct(string $class) { diff --git a/src/Model/UserManagerInterface.php b/src/Model/UserManagerInterface.php index 719294a6b..2ef0d8e6c 100644 --- a/src/Model/UserManagerInterface.php +++ b/src/Model/UserManagerInterface.php @@ -16,7 +16,7 @@ use Sonata\Doctrine\Model\ManagerInterface; /** - * @phpstan-extends ManagerInterface<\Sonata\UserBundle\Model\UserInterface> + * @phpstan-extends ManagerInterface */ interface UserManagerInterface extends ManagerInterface { diff --git a/tests/Action/LoginActionTest.php b/tests/Action/LoginActionTest.php index 5ba27945b..ca48ff503 100644 --- a/tests/Action/LoginActionTest.php +++ b/tests/Action/LoginActionTest.php @@ -145,14 +145,14 @@ public function testUnauthenticated(string $lastUsername, ?AuthenticationExcepti ]; $session ->method('get') - ->willReturnCallback(static function (string $key) use ($sessionParameters) { - return $sessionParameters[$key] ?? null; - }); + ->willReturnCallback( + static fn (string $key) => $sessionParameters[$key] ?? null + ); $session ->method('has') - ->willReturnCallback(static function (string $key) use ($sessionParameters): bool { - return isset($sessionParameters[$key]); - }); + ->willReturnCallback( + static fn (string $key): bool => isset($sessionParameters[$key]) + ); $request = new Request(); $request->setSession($session); diff --git a/tests/Action/ResetActionTest.php b/tests/Action/ResetActionTest.php index d79bc3aec..544b49a9e 100644 --- a/tests/Action/ResetActionTest.php +++ b/tests/Action/ResetActionTest.php @@ -240,9 +240,7 @@ public function testPostedReset(): void $this->translator ->method('trans') - ->willReturnCallback(static function (string $message): string { - return $message; - }); + ->willReturnCallback(static fn (string $message): string => $message); $this->userManager ->method('findUserByConfirmationToken') diff --git a/tests/Functional/Action/LoginActionTest.php b/tests/Functional/Action/LoginActionTest.php index 0f532da49..2a414df98 100644 --- a/tests/Functional/Action/LoginActionTest.php +++ b/tests/Functional/Action/LoginActionTest.php @@ -17,6 +17,7 @@ use Sonata\UserBundle\Tests\App\AppKernel; use Sonata\UserBundle\Tests\App\Entity\User; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use Symfony\Component\HttpKernel\KernelInterface; final class LoginActionTest extends WebTestCase { @@ -65,7 +66,7 @@ public function testItSubmitsLoginFormWithDisabledUser(): void } /** - * @return class-string<\Symfony\Component\HttpKernel\KernelInterface> + * @return class-string */ protected static function getKernelClass(): string { diff --git a/tests/Functional/Action/LogoutActionTest.php b/tests/Functional/Action/LogoutActionTest.php index 244a796dd..f228008be 100644 --- a/tests/Functional/Action/LogoutActionTest.php +++ b/tests/Functional/Action/LogoutActionTest.php @@ -15,6 +15,7 @@ use Sonata\UserBundle\Tests\App\AppKernel; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use Symfony\Component\HttpKernel\KernelInterface; final class LogoutActionTest extends WebTestCase { @@ -28,7 +29,7 @@ public function testItLogouts(): void } /** - * @return class-string<\Symfony\Component\HttpKernel\KernelInterface> + * @return class-string */ protected static function getKernelClass(): string { diff --git a/tests/Functional/Action/RequestActionTest.php b/tests/Functional/Action/RequestActionTest.php index 81d4268c5..f85b21119 100644 --- a/tests/Functional/Action/RequestActionTest.php +++ b/tests/Functional/Action/RequestActionTest.php @@ -17,6 +17,7 @@ use Sonata\UserBundle\Tests\App\AppKernel; use Sonata\UserBundle\Tests\App\Entity\User; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use Symfony\Component\HttpKernel\KernelInterface; final class RequestActionTest extends WebTestCase { @@ -89,7 +90,7 @@ public function itSubmitsResetPasswordRequest(): void } /** - * @return class-string<\Symfony\Component\HttpKernel\KernelInterface> + * @return class-string */ protected static function getKernelClass(): string { diff --git a/tests/Functional/Action/ResetActionTest.php b/tests/Functional/Action/ResetActionTest.php index d4eb429bc..c5657bf65 100644 --- a/tests/Functional/Action/ResetActionTest.php +++ b/tests/Functional/Action/ResetActionTest.php @@ -18,6 +18,7 @@ use Sonata\UserBundle\Tests\App\AppKernel; use Sonata\UserBundle\Tests\App\Entity\User; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use Symfony\Component\HttpKernel\KernelInterface; final class ResetActionTest extends WebTestCase { @@ -84,7 +85,7 @@ public function testItResetsPassword(): void } /** - * @return class-string<\Symfony\Component\HttpKernel\KernelInterface> + * @return class-string */ protected static function getKernelClass(): string { diff --git a/tests/Functional/Admin/UserAdminTest.php b/tests/Functional/Admin/UserAdminTest.php index de974b081..47407675d 100644 --- a/tests/Functional/Admin/UserAdminTest.php +++ b/tests/Functional/Admin/UserAdminTest.php @@ -18,6 +18,7 @@ use Sonata\UserBundle\Tests\App\AppKernel; use Sonata\UserBundle\Tests\App\Entity\User; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use Symfony\Component\HttpKernel\KernelInterface; final class UserAdminTest extends WebTestCase { @@ -113,7 +114,7 @@ public function testUpdatePassword(): void } /** - * @return class-string<\Symfony\Component\HttpKernel\KernelInterface> + * @return class-string */ protected static function getKernelClass(): string { diff --git a/tests/Functional/Command/ActivateUserCommandTest.php b/tests/Functional/Command/ActivateUserCommandTest.php index e992cba1b..6934f8839 100644 --- a/tests/Functional/Command/ActivateUserCommandTest.php +++ b/tests/Functional/Command/ActivateUserCommandTest.php @@ -20,6 +20,7 @@ use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Console\Tester\CommandTester; +use Symfony\Component\HttpKernel\KernelInterface; class ActivateUserCommandTest extends KernelTestCase { @@ -65,7 +66,7 @@ public function testActivatesUser(): void } /** - * @return class-string<\Symfony\Component\HttpKernel\KernelInterface> + * @return class-string */ protected static function getKernelClass(): string { diff --git a/tests/Functional/Command/ChangePasswordCommandTest.php b/tests/Functional/Command/ChangePasswordCommandTest.php index 17837c013..a8ef48e17 100644 --- a/tests/Functional/Command/ChangePasswordCommandTest.php +++ b/tests/Functional/Command/ChangePasswordCommandTest.php @@ -20,6 +20,7 @@ use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Console\Tester\CommandTester; +use Symfony\Component\HttpKernel\KernelInterface; class ChangePasswordCommandTest extends KernelTestCase { @@ -62,7 +63,7 @@ public function testChangesUserPassword(): void } /** - * @return class-string<\Symfony\Component\HttpKernel\KernelInterface> + * @return class-string */ protected static function getKernelClass(): string { diff --git a/tests/Functional/Command/CreateUserCommandTest.php b/tests/Functional/Command/CreateUserCommandTest.php index 899a58023..651a396e1 100644 --- a/tests/Functional/Command/CreateUserCommandTest.php +++ b/tests/Functional/Command/CreateUserCommandTest.php @@ -19,6 +19,7 @@ use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Console\Tester\CommandTester; +use Symfony\Component\HttpKernel\KernelInterface; class CreateUserCommandTest extends KernelTestCase { @@ -79,7 +80,7 @@ public function testCreatesAnSuperAdminUser(): void } /** - * @return class-string<\Symfony\Component\HttpKernel\KernelInterface> + * @return class-string */ protected static function getKernelClass(): string { diff --git a/tests/Functional/Command/DeactivateUserCommandTest.php b/tests/Functional/Command/DeactivateUserCommandTest.php index b33af2a8c..35bed64f8 100644 --- a/tests/Functional/Command/DeactivateUserCommandTest.php +++ b/tests/Functional/Command/DeactivateUserCommandTest.php @@ -20,6 +20,7 @@ use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Console\Tester\CommandTester; +use Symfony\Component\HttpKernel\KernelInterface; class DeactivateUserCommandTest extends KernelTestCase { @@ -65,7 +66,7 @@ public function testDeactivatesUser(): void } /** - * @return class-string<\Symfony\Component\HttpKernel\KernelInterface> + * @return class-string */ protected static function getKernelClass(): string { diff --git a/tests/Functional/Command/DemoteUserCommandTest.php b/tests/Functional/Command/DemoteUserCommandTest.php index 13a13c00d..40544fa87 100644 --- a/tests/Functional/Command/DemoteUserCommandTest.php +++ b/tests/Functional/Command/DemoteUserCommandTest.php @@ -20,6 +20,7 @@ use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Console\Tester\CommandTester; +use Symfony\Component\HttpKernel\KernelInterface; class DemoteUserCommandTest extends KernelTestCase { @@ -114,7 +115,7 @@ public function testBecomeNormalUser(): void } /** - * @return class-string<\Symfony\Component\HttpKernel\KernelInterface> + * @return class-string */ protected static function getKernelClass(): string { diff --git a/tests/Functional/Command/PromoteUserCommandTest.php b/tests/Functional/Command/PromoteUserCommandTest.php index 684983645..be4622fa9 100644 --- a/tests/Functional/Command/PromoteUserCommandTest.php +++ b/tests/Functional/Command/PromoteUserCommandTest.php @@ -20,6 +20,7 @@ use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Console\Tester\CommandTester; +use Symfony\Component\HttpKernel\KernelInterface; class PromoteUserCommandTest extends KernelTestCase { @@ -114,7 +115,7 @@ public function testBecomeSuperAdmin(): void } /** - * @return class-string<\Symfony\Component\HttpKernel\KernelInterface> + * @return class-string */ protected static function getKernelClass(): string {