Skip to content

Commit

Permalink
Add rector
Browse files Browse the repository at this point in the history
  • Loading branch information
Prokyonn committed Apr 30, 2024
1 parent 38deb6c commit 7782f23
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Tests/Application/config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
12 changes: 12 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@
"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"
},
"scripts": {
"lint": [
"@phpstan",
"@php-cs",
"@lint-rector",
"@lint-composer",
"@deptrac"
],
Expand All @@ -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"
},
Expand Down
33 changes: 33 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* 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\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;

return static function(RectorConfig $rectorConfig): void {
$rectorConfig->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,
]);
};
8 changes: 4 additions & 4 deletions src/Application/Session/SessionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

class SessionManager
{
private string $workspace;
private string $workspaceLive;
private readonly string $workspace;
private readonly string $workspaceLive;

/**
* @param array{
Expand All @@ -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'];
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/UserInterface/Command/MigratePhpcrCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 7782f23

Please sign in to comment.