Skip to content

Commit

Permalink
Add and run rector
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Nov 29, 2022
1 parent 63ecac4 commit 53099c7
Show file tree
Hide file tree
Showing 18 changed files with 245 additions and 125 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
23 changes: 4 additions & 19 deletions src/Event/ChangelanguageNavigationEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 1 addition & 3 deletions src/EventListener/BackendView/ArticleViewListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
51 changes: 29 additions & 22 deletions src/EventListener/CallbackSetupListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions src/EventListener/DataContainer/LanguageMainTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

class MissingLanguageIconListener
{
private static $callbacks = [
private static array $callbacks = [
'tl_page' => 'onPageLabel',
'tl_article' => 'onArticleLabel',
'tl_news' => 'onNewsChildRecords',
Expand All @@ -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)
);
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/EventListener/DataContainer/PageOperationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
}
9 changes: 2 additions & 7 deletions src/EventListener/DataContainer/ParentTableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@

class ParentTableListener
{
/**
* @var string
*/
private $table;
private string $table;

/**
* Constructor.
Expand All @@ -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'],
Expand Down
5 changes: 1 addition & 4 deletions src/EventListener/DataContainer/UserLabelsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
*/
class UserLabelsListener
{
/**
* @var Connection
*/
private $connection;
private Connection $connection;

public function __construct(Connection $connection)
{
Expand Down
5 changes: 1 addition & 4 deletions src/FrontendModule/ChangeLanguageModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ class ChangeLanguageModule extends Module
*/
protected $strTemplate = 'mod_changelanguage';

/**
* @var AlternateLinks
*/
private static $alternateLinks;
private static ?AlternateLinks $alternateLinks = null;

/**
* @return AlternateLinks
Expand Down
5 changes: 1 addition & 4 deletions src/Helper/AlternateLinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
*/
class AlternateLinks
{
/**
* @var array
*/
private $links = [];
private array $links = [];

/**
* Returns whether a link already exists for a language.
Expand Down
5 changes: 1 addition & 4 deletions src/Helper/LanguageText.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
*/
class LanguageText
{
/**
* @var array
*/
private $map = [];
private array $map = [];

/**
* Constructor.
Expand Down
15 changes: 3 additions & 12 deletions src/Navigation/NavigationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
30 changes: 6 additions & 24 deletions src/Navigation/NavigationItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 2 additions & 8 deletions src/Navigation/UrlParameterBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@

class UrlParameterBag
{
/**
* @var array
*/
private $attributes;
private array $attributes;

/**
* @var array
*/
private $query;
private array $query;

/**
* Constructor.
Expand Down
5 changes: 5 additions & 0 deletions tools/rector/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require": {
"rector/rector": "^0.12"
}
}
Loading

0 comments on commit 53099c7

Please sign in to comment.