diff --git a/Tests/Application/config/bootstrap.php b/Tests/Application/config/bootstrap.php index 7314acf..36801a1 100644 --- a/Tests/Application/config/bootstrap.php +++ b/Tests/Application/config/bootstrap.php @@ -35,5 +35,5 @@ } $_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev'; -$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV']; +$_SERVER['APP_DEBUG'] ??= $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV']; $_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || \filter_var($_SERVER['APP_DEBUG'], \FILTER_VALIDATE_BOOLEAN) ? '1' : '0'; diff --git a/composer.json b/composer.json index 2e7a829..d7ed68e 100644 --- a/composer.json +++ b/composer.json @@ -44,6 +44,7 @@ "phpstan/phpstan-webmozart-assert": "^1.2", "phpunit/phpunit": "^10.0", "qossmic/deptrac": "^1.0", + "rector/rector": "^1.0", "symfony/dotenv": "^6.0 || ^7.0", "thecodingmachine/phpstan-strict-rules": "^1.0" }, @@ -51,6 +52,7 @@ "lint": [ "@phpstan", "@php-cs", + "@lint-rector", "@lint-composer", "@deptrac" ], @@ -61,8 +63,18 @@ "phpstan": [ "@php vendor/bin/phpstan analyze" ], + "fix": [ + "@rector", + "@php-cs-fix" + ], "php-cs": "@php vendor/bin/php-cs-fixer fix --verbose --diff --dry-run", "php-cs-fix": "@php vendor/bin/php-cs-fixer fix", + "rector": [ + "@php vendor/bin/rector process" + ], + "lint-rector": [ + "@php vendor/bin/rector process --dry-run" + ], "lint-composer": "@composer validate --strict", "deptrac": "@php vendor/qossmic/deptrac/deptrac.php" }, diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..4225388 --- /dev/null +++ b/rector.php @@ -0,0 +1,33 @@ +paths([__DIR__ . '/src', __DIR__ . '/tests']); + + $rectorConfig->phpstanConfigs([ + __DIR__ . '/phpstan.neon', + ]); + + // basic rules + $rectorConfig->importNames(); + $rectorConfig->importShortClasses(false); + + $rectorConfig->sets([ + SetList::CODE_QUALITY, + LevelSetList::UP_TO_PHP_81, + ]); +}; diff --git a/src/Application/Session/SessionManager.php b/src/Application/Session/SessionManager.php index 3cfff12..7ee6a1a 100644 --- a/src/Application/Session/SessionManager.php +++ b/src/Application/Session/SessionManager.php @@ -19,8 +19,8 @@ class SessionManager { - private string $workspace; - private string $workspaceLive; + private readonly string $workspace; + private readonly string $workspaceLive; /** * @param array{ @@ -39,7 +39,7 @@ class SessionManager */ public function __construct( private array $configuration, - private ?Connection $connection = null, + private readonly ?Connection $connection = null, ) { $this->workspace = $configuration['workspace']['default']; $this->workspaceLive = $configuration['workspace']['live']; @@ -57,7 +57,7 @@ public function getLiveSession(): SessionInterface private function getSession(string $workspace): SessionInterface { - $factory = $this->connection ? new RepositoryFactoryDoctrineDBAL() : new RepositoryFactoryJackrabbit(); + $factory = $this->connection instanceof Connection ? new RepositoryFactoryDoctrineDBAL() : new RepositoryFactoryJackrabbit(); $repository = $factory->getRepository(\array_filter([ 'jackalope.doctrine_dbal_connection' => $this->connection, 'jackalope.jackrabbit_uri' => $this->configuration['connection']['url'] ?? null, diff --git a/src/UserInterface/Command/MigratePhpcrCommand.php b/src/UserInterface/Command/MigratePhpcrCommand.php index 3485690..174355a 100644 --- a/src/UserInterface/Command/MigratePhpcrCommand.php +++ b/src/UserInterface/Command/MigratePhpcrCommand.php @@ -20,7 +20,7 @@ #[AsCommand(name: 'sulu:phpcr-migration:migrate', description: 'Migrate the PHPCR content repository to the SuluContentBundle.')] class MigratePhpcrCommand extends Command { - public function __construct(private SessionManager $sessionManager) + public function __construct(private readonly SessionManager $sessionManager) { parent::__construct(); }