diff --git a/composer.json b/composer.json index c658a96..170f9ef 100644 --- a/composer.json +++ b/composer.json @@ -59,6 +59,7 @@ "contao-manager-plugin": "Terminal42\\ChangeLanguage\\ContaoManager\\Plugin" }, "scripts": { - "cs-fixer": "@php tools/ecs/vendor/bin/ecs check src/ --config tools/ecs/config.php --fix --ansi" + "cs-fixer": "@php tools/ecs/vendor/bin/ecs check src/ --config tools/ecs/config.php --fix --ansi", + "rector": "@php tools/rector/vendor/bin/rector --config tools/rector/config.php --ansi" } } diff --git a/src/Event/ChangelanguageNavigationEvent.php b/src/Event/ChangelanguageNavigationEvent.php index 8ccb9ee..0ff676e 100644 --- a/src/Event/ChangelanguageNavigationEvent.php +++ b/src/Event/ChangelanguageNavigationEvent.php @@ -9,25 +9,10 @@ class ChangelanguageNavigationEvent { - /** - * @var NavigationItem - */ - private $navigationItem; - - /** - * @var UrlParameterBag - */ - private $urlParameterBag; - - /** - * @var bool - */ - private $skipped = false; - - /** - * @var bool - */ - private $stopPropagation = false; + private NavigationItem $navigationItem; + private UrlParameterBag $urlParameterBag; + private bool $skipped = false; + private bool $stopPropagation = false; public function __construct(NavigationItem $navigationItem, UrlParameterBag $urlParameters) { diff --git a/src/EventListener/BackendView/ArticleViewListener.php b/src/EventListener/BackendView/ArticleViewListener.php index 23b8f1f..f40f0b8 100644 --- a/src/EventListener/BackendView/ArticleViewListener.php +++ b/src/EventListener/BackendView/ArticleViewListener.php @@ -86,9 +86,7 @@ protected function getAvailableLanguages(PageModel $page) $articles = array_values(array_filter( $articles, - function (ArticleModel $article) { - return $article->inColumn === $this->currentArticle->inColumn; - } + fn (ArticleModel $article) => $article->inColumn === $this->currentArticle->inColumn )); if (1 === \count($articles)) { diff --git a/src/EventListener/CallbackSetupListener.php b/src/EventListener/CallbackSetupListener.php index 432ae70..1715754 100644 --- a/src/EventListener/CallbackSetupListener.php +++ b/src/EventListener/CallbackSetupListener.php @@ -4,46 +4,53 @@ namespace Terminal42\ChangeLanguage\EventListener; +use Terminal42\ChangeLanguage\EventListener\BackendView\ArticleViewListener; +use Terminal42\ChangeLanguage\EventListener\BackendView\PageViewListener; +use Terminal42\ChangeLanguage\EventListener\BackendView\ParentChildViewListener; +use Terminal42\ChangeLanguage\EventListener\DataContainer\ArticleListener; +use Terminal42\ChangeLanguage\EventListener\DataContainer\CalendarEventsListener; +use Terminal42\ChangeLanguage\EventListener\DataContainer\FaqListener; use Terminal42\ChangeLanguage\EventListener\DataContainer\MissingLanguageIconListener; +use Terminal42\ChangeLanguage\EventListener\DataContainer\NewsListener; +use Terminal42\ChangeLanguage\EventListener\DataContainer\PageInitializationListener; +use Terminal42\ChangeLanguage\EventListener\DataContainer\PageOperationListener; +use Terminal42\ChangeLanguage\EventListener\DataContainer\ParentTableListener; class CallbackSetupListener { - private static $listeners = [ + private static array $listeners = [ 'tl_page' => [ - 'Terminal42\ChangeLanguage\EventListener\DataContainer\PageInitializationListener', - 'Terminal42\ChangeLanguage\EventListener\DataContainer\PageOperationListener', - 'Terminal42\ChangeLanguage\EventListener\BackendView\PageViewListener', + PageInitializationListener::class, + PageOperationListener::class, + PageViewListener::class, ], 'tl_article' => [ - 'Terminal42\ChangeLanguage\EventListener\DataContainer\ArticleListener', - 'Terminal42\ChangeLanguage\EventListener\BackendView\PageViewListener', - 'Terminal42\ChangeLanguage\EventListener\BackendView\ArticleViewListener', + ArticleListener::class, + PageViewListener::class, + ArticleViewListener::class, ], 'tl_content' => [ - 'Terminal42\ChangeLanguage\EventListener\BackendView\ArticleViewListener', - 'Terminal42\ChangeLanguage\EventListener\BackendView\ParentChildViewListener', + ArticleViewListener::class, + ParentChildViewListener::class, ], - 'tl_news_archive' => ['Terminal42\ChangeLanguage\EventListener\DataContainer\ParentTableListener'], - 'tl_calendar' => ['Terminal42\ChangeLanguage\EventListener\DataContainer\ParentTableListener'], - 'tl_faq_category' => ['Terminal42\ChangeLanguage\EventListener\DataContainer\ParentTableListener'], + 'tl_news_archive' => [ParentTableListener::class], + 'tl_calendar' => [ParentTableListener::class], + 'tl_faq_category' => [ParentTableListener::class], 'tl_news' => [ - 'Terminal42\ChangeLanguage\EventListener\DataContainer\NewsListener', - 'Terminal42\ChangeLanguage\EventListener\BackendView\ParentChildViewListener', + NewsListener::class, + ParentChildViewListener::class, ], 'tl_calendar_events' => [ - 'Terminal42\ChangeLanguage\EventListener\DataContainer\CalendarEventsListener', - 'Terminal42\ChangeLanguage\EventListener\BackendView\ParentChildViewListener', + CalendarEventsListener::class, + ParentChildViewListener::class, ], 'tl_faq' => [ - 'Terminal42\ChangeLanguage\EventListener\DataContainer\FaqListener', - 'Terminal42\ChangeLanguage\EventListener\BackendView\ParentChildViewListener', + FaqListener::class, + ParentChildViewListener::class, ], ]; - /** - * @var MissingLanguageIconListener - */ - private $labelListener; + private MissingLanguageIconListener $labelListener; /** * Constructor. diff --git a/src/EventListener/DataContainer/LanguageMainTrait.php b/src/EventListener/DataContainer/LanguageMainTrait.php index deddc32..a715c3f 100644 --- a/src/EventListener/DataContainer/LanguageMainTrait.php +++ b/src/EventListener/DataContainer/LanguageMainTrait.php @@ -14,9 +14,7 @@ protected function addLanguageMainField(): void 'label' => &$GLOBALS['TL_LANG'][$this->getTable()]['languageMain'], 'exclude' => true, 'inputType' => 'select', - 'options_callback' => function (DataContainer $dc) { - return $this->onLanguageMainOptions($dc); - }, + 'options_callback' => fn (DataContainer $dc) => $this->onLanguageMainOptions($dc), 'eval' => [ 'includeBlankOption' => true, 'blankOptionLabel' => &$GLOBALS['TL_LANG'][$this->getTable()]['languageMain'][2], diff --git a/src/EventListener/DataContainer/MissingLanguageIconListener.php b/src/EventListener/DataContainer/MissingLanguageIconListener.php index 8d36dff..f38866d 100644 --- a/src/EventListener/DataContainer/MissingLanguageIconListener.php +++ b/src/EventListener/DataContainer/MissingLanguageIconListener.php @@ -22,7 +22,7 @@ class MissingLanguageIconListener { - private static $callbacks = [ + private static array $callbacks = [ 'tl_page' => 'onPageLabel', 'tl_article' => 'onArticleLabel', 'tl_news' => 'onNewsChildRecords', @@ -40,9 +40,7 @@ public function register($table): void if (\array_key_exists($table, self::$callbacks)) { LabelCallback::createAndRegister( $table, - function (array $args, $previousResult) use ($table) { - return $this->{self::$callbacks[$table]}($args, $previousResult); - } + fn (array $args, $previousResult) => $this->{self::$callbacks[$table]}($args, $previousResult) ); } } diff --git a/src/EventListener/DataContainer/PageOperationListener.php b/src/EventListener/DataContainer/PageOperationListener.php index 3830106..c218cd4 100644 --- a/src/EventListener/DataContainer/PageOperationListener.php +++ b/src/EventListener/DataContainer/PageOperationListener.php @@ -134,11 +134,9 @@ private function resetPageAndChildren($pageId): void */ private function selfCallback($method) { - return function () use ($method) { - return \call_user_func_array( - [$this, $method], - \func_get_args() - ); - }; + return fn () => \call_user_func_array( + [$this, $method], + \func_get_args() + ); } } diff --git a/src/EventListener/DataContainer/ParentTableListener.php b/src/EventListener/DataContainer/ParentTableListener.php index 0cdd910..fb1b774 100644 --- a/src/EventListener/DataContainer/ParentTableListener.php +++ b/src/EventListener/DataContainer/ParentTableListener.php @@ -12,10 +12,7 @@ class ParentTableListener { - /** - * @var string - */ - private $table; + private string $table; /** * Constructor. @@ -37,9 +34,7 @@ public function register(): void 'label' => &$GLOBALS['TL_LANG'][$this->table]['master'], 'exclude' => true, 'inputType' => 'select', - 'options_callback' => function (DataContainer $dc) { - return $this->onMasterOptions($dc); - }, + 'options_callback' => fn (DataContainer $dc) => $this->onMasterOptions($dc), 'eval' => [ 'includeBlankOption' => true, 'blankOptionLabel' => &$GLOBALS['TL_LANG'][$this->table]['isMaster'], diff --git a/src/EventListener/DataContainer/UserLabelsListener.php b/src/EventListener/DataContainer/UserLabelsListener.php index 6a553cf..be6cd14 100644 --- a/src/EventListener/DataContainer/UserLabelsListener.php +++ b/src/EventListener/DataContainer/UserLabelsListener.php @@ -12,10 +12,7 @@ */ class UserLabelsListener { - /** - * @var Connection - */ - private $connection; + private Connection $connection; public function __construct(Connection $connection) { diff --git a/src/FrontendModule/ChangeLanguageModule.php b/src/FrontendModule/ChangeLanguageModule.php index 41004b1..448d29f 100755 --- a/src/FrontendModule/ChangeLanguageModule.php +++ b/src/FrontendModule/ChangeLanguageModule.php @@ -33,10 +33,7 @@ class ChangeLanguageModule extends Module */ protected $strTemplate = 'mod_changelanguage'; - /** - * @var AlternateLinks - */ - private static $alternateLinks; + private static ?AlternateLinks $alternateLinks = null; /** * @return AlternateLinks diff --git a/src/Helper/AlternateLinks.php b/src/Helper/AlternateLinks.php index 98016a7..3c54862 100644 --- a/src/Helper/AlternateLinks.php +++ b/src/Helper/AlternateLinks.php @@ -15,10 +15,7 @@ */ class AlternateLinks { - /** - * @var array - */ - private $links = []; + private array $links = []; /** * Returns whether a link already exists for a language. diff --git a/src/Helper/LanguageText.php b/src/Helper/LanguageText.php index b429eac..8b3c0db 100644 --- a/src/Helper/LanguageText.php +++ b/src/Helper/LanguageText.php @@ -13,10 +13,7 @@ */ class LanguageText { - /** - * @var array - */ - private $map = []; + private array $map = []; /** * Constructor. diff --git a/src/Navigation/NavigationFactory.php b/src/Navigation/NavigationFactory.php index e005c6d..a5514e9 100644 --- a/src/Navigation/NavigationFactory.php +++ b/src/Navigation/NavigationFactory.php @@ -10,20 +10,11 @@ class NavigationFactory { - /** - * @var PageFinder - */ - private $pageFinder; + private PageFinder $pageFinder; - /** - * @var LanguageText - */ - private $languageText; + private LanguageText $languageText; - /** - * @var PageModel - */ - private $currentPage; + private PageModel $currentPage; /** * Constructor. diff --git a/src/Navigation/NavigationItem.php b/src/Navigation/NavigationItem.php index c282bba..e212ff4 100644 --- a/src/Navigation/NavigationItem.php +++ b/src/Navigation/NavigationItem.php @@ -10,35 +10,17 @@ class NavigationItem { - /** - * @var PageModel - */ - private $rootPage; + private PageModel $rootPage; - /** - * @var PageModel|null - */ - private $targetPage; + private ?PageModel $targetPage = null; - /** - * @var string - */ - private $linkLabel; + private string $linkLabel; - /** - * @var bool - */ - private $newWindow; + private ?bool $newWindow = null; - /** - * @var bool - */ - private $isDirectFallback = false; + private bool $isDirectFallback = false; - /** - * @var bool - */ - private $isCurrentPage = false; + private bool $isCurrentPage = false; /** * Constructor. diff --git a/src/Navigation/UrlParameterBag.php b/src/Navigation/UrlParameterBag.php index 53b19ef..edc4852 100644 --- a/src/Navigation/UrlParameterBag.php +++ b/src/Navigation/UrlParameterBag.php @@ -6,15 +6,9 @@ class UrlParameterBag { - /** - * @var array - */ - private $attributes; + private array $attributes; - /** - * @var array - */ - private $query; + private array $query; /** * Constructor. diff --git a/tools/rector/composer.json b/tools/rector/composer.json new file mode 100644 index 0000000..aabf487 --- /dev/null +++ b/tools/rector/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "rector/rector": "^0.12" + } +} diff --git a/tools/rector/composer.lock b/tools/rector/composer.lock new file mode 100644 index 0000000..afde269 --- /dev/null +++ b/tools/rector/composer.lock @@ -0,0 +1,138 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "1b172c779330acfc362f492ece0e0604", + "packages": [ + { + "name": "phpstan/phpstan", + "version": "1.9.2", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "d6fdf01c53978b6429f1393ba4afeca39cc68afa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/d6fdf01c53978b6429f1393ba4afeca39cc68afa", + "reference": "d6fdf01c53978b6429f1393ba4afeca39cc68afa", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "issues": "https://github.com/phpstan/phpstan/issues", + "source": "https://github.com/phpstan/phpstan/tree/1.9.2" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", + "type": "tidelift" + } + ], + "time": "2022-11-10T09:56:11+00:00" + }, + { + "name": "rector/rector", + "version": "0.12.23", + "source": { + "type": "git", + "url": "https://github.com/rectorphp/rector.git", + "reference": "690b31768b322db886b35845f8452025eba2cacb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/690b31768b322db886b35845f8452025eba2cacb", + "reference": "690b31768b322db886b35845f8452025eba2cacb", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0", + "phpstan/phpstan": "^1.6" + }, + "conflict": { + "phpstan/phpdoc-parser": "<1.2", + "rector/rector-cakephp": "*", + "rector/rector-doctrine": "*", + "rector/rector-laravel": "*", + "rector/rector-nette": "*", + "rector/rector-phpoffice": "*", + "rector/rector-phpunit": "*", + "rector/rector-prefixed": "*", + "rector/rector-symfony": "*" + }, + "bin": [ + "bin/rector" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "0.12-dev" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Instant Upgrade and Automated Refactoring of any PHP code", + "support": { + "issues": "https://github.com/rectorphp/rector/issues", + "source": "https://github.com/rectorphp/rector/tree/0.12.23" + }, + "funding": [ + { + "url": "https://github.com/tomasvotruba", + "type": "github" + } + ], + "time": "2022-05-01T15:50:16+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.3.0" +} diff --git a/tools/rector/config.php b/tools/rector/config.php new file mode 100644 index 0000000..f8cbf39 --- /dev/null +++ b/tools/rector/config.php @@ -0,0 +1,42 @@ +paths([ + __DIR__ . '/../../src', + ]); + + $rectorConfig->skip([ + ClassPropertyAssignToConstructorPromotionRector::class => [ + '/src/Entity/*', + ], + ChangeSwitchToMatchRector::class, + ]); + + $services = $rectorConfig->services(); + $services->set(ArraySpreadInsteadOfArrayMergeRector::class); + $services->set(CompactToVariablesRector::class); + $services->set(RemoveUnusedPrivateMethodParameterRector::class); + $services->set(RestoreDefaultNullToNullableTypePropertyRector::class); + $services->set(TypedPropertyRector::class); + + $rectorConfig->sets([ + LevelSetList::UP_TO_PHP_74, + DoctrineSetList::DOCTRINE_DBAL_30, + DoctrineSetList::DOCTRINE_ORM_29, + SymfonyLevelSetList::UP_TO_SYMFONY_54, + ]); +};