diff --git a/contao/templates/nav_dropdown.html5 b/contao/templates/nav_dropdown.html5 index e3bac0b..5a12680 100755 --- a/contao/templates/nav_dropdown.html5 +++ b/contao/templates/nav_dropdown.html5 @@ -10,7 +10,7 @@ if (1 == $intLevel): $arrLanguages = \Contao\System::getLanguages(); foreach ($this->items as $item) { - if ($item['isActive'] || false !== strpos($item['subitems'], 'class="active')) { + if ($item['isActive'] || str_contains($item['subitems'], 'class="active')) { $blnHasActive = true; break; } diff --git a/src/ContaoManager/Plugin.php b/src/ContaoManager/Plugin.php index 7e9de14..2f7a31b 100644 --- a/src/ContaoManager/Plugin.php +++ b/src/ContaoManager/Plugin.php @@ -11,7 +11,6 @@ use Contao\ManagerPlugin\Bundle\Config\BundleConfig; use Contao\ManagerPlugin\Bundle\Parser\ParserInterface; use Contao\NewsBundle\ContaoNewsBundle; -use MenAtWork\MultiColumnWizardBundle\MultiColumnWizardBundle; use Terminal42\ChangeLanguage\Terminal42ChangeLanguageBundle; class Plugin implements BundlePluginInterface @@ -26,7 +25,6 @@ public function getBundles(ParserInterface $parser) ContaoNewsBundle::class, ContaoCalendarBundle::class, ContaoFaqBundle::class, - MultiColumnWizardBundle::class, ]), ]; } diff --git a/src/DependencyInjection/Terminal42ChangeLanguageExtension.php b/src/DependencyInjection/Terminal42ChangeLanguageExtension.php index 201692c..9d1b923 100644 --- a/src/DependencyInjection/Terminal42ChangeLanguageExtension.php +++ b/src/DependencyInjection/Terminal42ChangeLanguageExtension.php @@ -18,7 +18,7 @@ public function load(array $config, ContainerBuilder $container): void { $loader = new YamlFileLoader( $container, - new FileLocator(__DIR__.'/../../config') + new FileLocator(__DIR__.'/../../config'), ); $loader->load('services.yaml'); diff --git a/src/Event/ChangelanguageNavigationEvent.php b/src/Event/ChangelanguageNavigationEvent.php index 0ff676e..4db6537 100644 --- a/src/Event/ChangelanguageNavigationEvent.php +++ b/src/Event/ChangelanguageNavigationEvent.php @@ -4,15 +4,17 @@ namespace Terminal42\ChangeLanguage\Event; +use Symfony\Contracts\EventDispatcher\Event; use Terminal42\ChangeLanguage\Navigation\NavigationItem; use Terminal42\ChangeLanguage\Navigation\UrlParameterBag; -class ChangelanguageNavigationEvent +class ChangelanguageNavigationEvent extends Event { private NavigationItem $navigationItem; + private UrlParameterBag $urlParameterBag; + private bool $skipped = false; - private bool $stopPropagation = false; public function __construct(NavigationItem $navigationItem, UrlParameterBag $urlParameters) { @@ -46,18 +48,8 @@ public function skipInNavigation(): void $this->stopPropagation(); } - public function isSkipped() + public function isSkipped(): bool { return $this->skipped; } - - public function isPropagationStopped() - { - return $this->stopPropagation; - } - - public function stopPropagation(): void - { - $this->stopPropagation = true; - } } diff --git a/src/EventListener/AbstractTableListener.php b/src/EventListener/AbstractTableListener.php index e9bed5b..d58e964 100644 --- a/src/EventListener/AbstractTableListener.php +++ b/src/EventListener/AbstractTableListener.php @@ -15,6 +15,8 @@ public function __construct(string $table) /** * Register necessary callbacks for this listener. + * + * @return void */ abstract public function register(); diff --git a/src/EventListener/BackendView/AbstractViewListener.php b/src/EventListener/BackendView/AbstractViewListener.php index 44e4ac4..eea2b0e 100644 --- a/src/EventListener/BackendView/AbstractViewListener.php +++ b/src/EventListener/BackendView/AbstractViewListener.php @@ -15,9 +15,10 @@ abstract class AbstractViewListener extends AbstractTableListener { protected DataContainer $dataContainer; + protected PageFinder $pageFinder; - public function __construct($table) + public function __construct(string $table) { parent::__construct($table); @@ -93,7 +94,7 @@ abstract protected function getAvailableLanguages(PageModel $page); * * @param string $id */ - abstract protected function doSwitchView($id); + abstract protected function doSwitchView($id): void; /** * @param string $languageCode @@ -152,7 +153,7 @@ private function getSwitchButton(PageModel $page, array $languages): string '
  • %s
  • ', Backend::addToUrl('&switchLanguage='.$id), sprintf($GLOBALS['TL_LANG']['MSC']['switchLanguageTo'][1], $language), - $language + $language, ); } @@ -161,7 +162,7 @@ private function getSwitchButton(PageModel $page, array $languages): string $GLOBALS['TL_LANG']['MSC']['switchLanguage'], $this->getLanguageLabel($page->language), $GLOBALS['TL_LANG']['MSC']['switchLanguageTo'][0], - $list + $list, ); } } diff --git a/src/EventListener/BackendView/ArticleViewListener.php b/src/EventListener/BackendView/ArticleViewListener.php index 258dfe5..40405a5 100644 --- a/src/EventListener/BackendView/ArticleViewListener.php +++ b/src/EventListener/BackendView/ArticleViewListener.php @@ -77,7 +77,7 @@ protected function getAvailableLanguages(PageModel $page): array $articles = array_values(array_filter( $articles, - fn (ArticleModel $article) => $article->inColumn === $this->currentArticle->inColumn + fn (ArticleModel $article) => $article->inColumn === $this->currentArticle->inColumn, )); if (1 === \count($articles)) { @@ -100,7 +100,7 @@ protected function doSwitchView($id): void $uri = UriModifier::removeParams($uri, 'switchLanguage', 'act', 'mode'); $uri = UriModifier::mergeQuery($uri, 'id='.$id); - throw new RedirectResponseException($uri->toString()); + throw new RedirectResponseException((string) $uri); } /** @@ -123,7 +123,7 @@ private function findArticlesForPage(PageModel $page, int $articleId): array $articleId, $articleId, ], - ['order' => 'tl_article.id=? DESC, tl_article.languageMain=? DESC'] + ['order' => 'tl_article.id=? DESC, tl_article.languageMain=? DESC'], ); if (!$articles instanceof Collection) { diff --git a/src/EventListener/BackendView/PageViewListener.php b/src/EventListener/BackendView/PageViewListener.php index 3065f0a..a6b96ed 100644 --- a/src/EventListener/BackendView/PageViewListener.php +++ b/src/EventListener/BackendView/PageViewListener.php @@ -49,6 +49,6 @@ protected function doSwitchView($id): void $uri = Uri::createFromString($requestStack->getCurrentRequest()->getUri()); $uri = UriModifier::removePairs($uri, 'switchLanguage'); - throw new RedirectResponseException($uri->toString()); + throw new RedirectResponseException((string) $uri); } } diff --git a/src/EventListener/BackendView/ParentChildViewListener.php b/src/EventListener/BackendView/ParentChildViewListener.php index 02e14ad..3f52547 100644 --- a/src/EventListener/BackendView/ParentChildViewListener.php +++ b/src/EventListener/BackendView/ParentChildViewListener.php @@ -20,9 +20,6 @@ class ParentChildViewListener extends AbstractViewListener */ private $current = false; - /** - * {@inheritdoc} - */ protected function isSupported() { return $this->getTable() === Input::get('table') @@ -91,7 +88,7 @@ protected function doSwitchView($id): void $uri = UriModifier::mergeQuery($uri, 'id='.$id); - throw new RedirectResponseException($uri->toString()); + throw new RedirectResponseException((string) $uri); } /** @@ -122,18 +119,15 @@ private function findRelatedForPageAndId(PageModel $page, $id) ]; } - return $class::findOneBy( - $columns, - [ - $page->id, - $this->current->id, - $id, - $id, - ] - ); + return $class::findOneBy($columns, [ + $page->id, + $this->current->id, + $id, + $id, + ]); } - private function getModelClass() + private function getModelClass(): string { Controller::loadDataContainer($this->getTable()); diff --git a/src/EventListener/DataContainer/AbstractChildTableListener.php b/src/EventListener/DataContainer/AbstractChildTableListener.php index 60bc48f..26d636a 100644 --- a/src/EventListener/DataContainer/AbstractChildTableListener.php +++ b/src/EventListener/DataContainer/AbstractChildTableListener.php @@ -33,6 +33,9 @@ public function onLoad(DataContainer $dc): void } } + /** + * @return array + */ public function onLanguageMainOptions(DataContainer $dc) { if ( @@ -49,7 +52,7 @@ public function onLanguageMainOptions(DataContainer $dc) $this->table.'.pid=?', sprintf('%s.id NOT IN (SELECT languageMain FROM %s WHERE pid=? AND id!=?)', $this->table, $this->table), ], - [$master->id, $current->pid, $current->id] + [$master->id, $current->pid, $current->id], ); return $models instanceof Collection ? $this->formatOptions($current, $models) : []; @@ -65,7 +68,7 @@ protected function addFieldsToPalettes(): void $palettes = array_diff( array_keys($GLOBALS['TL_DCA'][$this->table]['palettes']), - ['__selector__'] + ['__selector__'], ); foreach ($palettes as $palette) { @@ -73,6 +76,11 @@ protected function addFieldsToPalettes(): void } } + /** + * @param int|string $id + * + * @return Model + */ protected function getModel($id) { /** @var Model $class */ @@ -92,6 +100,8 @@ abstract protected function getTitleField(); abstract protected function getSorting(); /** + * @param Collection $models + * * @return array */ abstract protected function formatOptions(Model $current, Collection $models); diff --git a/src/EventListener/DataContainer/CalendarEventsListener.php b/src/EventListener/DataContainer/CalendarEventsListener.php index f95eeb9..fc617f9 100644 --- a/src/EventListener/DataContainer/CalendarEventsListener.php +++ b/src/EventListener/DataContainer/CalendarEventsListener.php @@ -28,7 +28,7 @@ protected function formatOptions(Model $current, Collection $models): array $options[$model->id] = sprintf( '%s [%s]', $model->title, - Date::parse($GLOBALS['TL_CONFIG']['datimFormat'], $model->startTime) + Date::parse($GLOBALS['TL_CONFIG']['datimFormat'], $model->startTime), ); } diff --git a/src/EventListener/DataContainer/FaqListener.php b/src/EventListener/DataContainer/FaqListener.php index 7fe8309..2e11bfc 100644 --- a/src/EventListener/DataContainer/FaqListener.php +++ b/src/EventListener/DataContainer/FaqListener.php @@ -4,6 +4,7 @@ namespace Terminal42\ChangeLanguage\EventListener\DataContainer; +use Contao\FaqModel; use Contao\Model; use Contao\Model\Collection; @@ -19,6 +20,9 @@ protected function getSorting(): string return 'sorting'; } + /** + * @param Collection $models + */ protected function formatOptions(Model $current, Collection $models): array { $options = []; diff --git a/src/EventListener/DataContainer/MissingLanguageIconListener.php b/src/EventListener/DataContainer/MissingLanguageIconListener.php index a429fa9..5bb7a46 100644 --- a/src/EventListener/DataContainer/MissingLanguageIconListener.php +++ b/src/EventListener/DataContainer/MissingLanguageIconListener.php @@ -50,15 +50,13 @@ public function __invoke(string $table): void if (\array_key_exists($table, self::$callbacks)) { LabelCallback::createAndRegister( $table, - fn (array $args, $previousResult) => $this->{self::$callbacks[$table]}($args, $previousResult) + fn (array $args, $previousResult) => $this->{self::$callbacks[$table]}($args, $previousResult), ); } } /** * Adds missing translation warning to page tree. - * - * @param mixed $previousResult */ private function onPageLabel(array $args, $previousResult = null): string { @@ -95,7 +93,7 @@ private function onPageLabel(array $args, $previousResult = null): string $label, Backend::addToUrl('pn='.$mainPage->id), StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['selectNode']), - $mainPage->title + $mainPage->title, ); } @@ -104,8 +102,6 @@ private function onPageLabel(array $args, $previousResult = null): string /** * Adds missing translation warning to article tree. - * - * @param mixed $previousResult */ private function onArticleLabel(array $args, $previousResult = null): string { @@ -131,8 +127,6 @@ private function onArticleLabel(array $args, $previousResult = null): string /** * Generate missing translation warning for news child records. - * - * @param mixed $previousResult */ private function onNewsChildRecords(array $args, $previousResult = null): string { @@ -158,8 +152,6 @@ private function onNewsChildRecords(array $args, $previousResult = null): string /** * Generate missing translation warning for calendar events child records. - * - * @param mixed $previousResult */ private function onCalendarEventChildRecords(array $args, $previousResult = null): string { @@ -181,8 +173,6 @@ private function onCalendarEventChildRecords(array $args, $previousResult = null /** * Generate missing translation warning for faq child records. - * - * @param mixed $previousResult */ private function onFaqChildRecords(array $args, $previousResult = null): string { @@ -200,7 +190,7 @@ private function onFaqChildRecords(array $args, $previousResult = null): string '##', $this->generateLabelWithWarning('', 'position:absolute;top:6px').'', $label, - 1 + 1, ); } @@ -220,7 +210,7 @@ private function generateLabelWithWarning($label, $imgStyle = '') 'bundles/terminal42changelanguage/language-warning.png', $GLOBALS['TL_LANG']['MSC']['noMainLanguage'], $GLOBALS['TL_LANG']['MSC']['noMainLanguage'], - $imgStyle + $imgStyle, ); } } diff --git a/src/EventListener/DataContainer/NewsListener.php b/src/EventListener/DataContainer/NewsListener.php index 1292eea..46e2897 100644 --- a/src/EventListener/DataContainer/NewsListener.php +++ b/src/EventListener/DataContainer/NewsListener.php @@ -7,6 +7,7 @@ use Contao\Date; use Contao\Model; use Contao\Model\Collection; +use Contao\NewsModel; class NewsListener extends AbstractChildTableListener { @@ -20,6 +21,9 @@ protected function getSorting(): string return 'date DESC, time DESC'; } + /** + * @param Collection $models + */ protected function formatOptions(Model $current, Collection $models): array { $sameDay = $GLOBALS['TL_LANG']['tl_news']['sameDay']; @@ -33,7 +37,7 @@ protected function formatOptions(Model $current, Collection $models): array $options[$group][$model->id] = sprintf( '%s [%s]', $model->headline, - Date::parse($GLOBALS['TL_CONFIG']['datimFormat'], $model->time) + Date::parse($GLOBALS['TL_CONFIG']['datimFormat'], $model->time), ); } diff --git a/src/EventListener/DataContainer/PageFieldsListener.php b/src/EventListener/DataContainer/PageFieldsListener.php index e527fca..35e58d8 100644 --- a/src/EventListener/DataContainer/PageFieldsListener.php +++ b/src/EventListener/DataContainer/PageFieldsListener.php @@ -74,7 +74,7 @@ public function onSaveLanguageMain($value, DataContainer $dc) 'tl_page.languageMain=?', 'tl_page.id!=?', ], - [$value, $dc->id] + [$value, $dc->id], ); if (null !== $duplicates) { @@ -106,7 +106,7 @@ public function onLanguageRootOptions(DataContainer $dc): array 'tl_page.languageRoot=0', 'tl_page.id!=?', ], - [$dc->id] + [$dc->id], ); if (null === $pages) { @@ -120,7 +120,7 @@ public function onLanguageRootOptions(DataContainer $dc): array '%s%s [%s]', $page->title, \strlen($page->dns) ? (' ('.$page->dns.')') : '', - $page->language + $page->language, ); } diff --git a/src/EventListener/DataContainer/PageInitializationListener.php b/src/EventListener/DataContainer/PageInitializationListener.php index 3d4e589..01b58f2 100644 --- a/src/EventListener/DataContainer/PageInitializationListener.php +++ b/src/EventListener/DataContainer/PageInitializationListener.php @@ -84,8 +84,8 @@ private function handleEditAllMode(): void $this->addRegularLanguageFields( array_diff( array_keys($GLOBALS['TL_DCA']['tl_page']['palettes']), - ['__selector__', 'root', 'rootfallback', 'folder'] - ) + ['__selector__', 'root', 'rootfallback', 'folder'], + ), ); } diff --git a/src/EventListener/DataContainer/PageOperationListener.php b/src/EventListener/DataContainer/PageOperationListener.php index 2fcfddb..b6a85fd 100644 --- a/src/EventListener/DataContainer/PageOperationListener.php +++ b/src/EventListener/DataContainer/PageOperationListener.php @@ -99,7 +99,7 @@ private function validateLanguageMainForPage(int $pageId): void 'languageMain=?', 'id!=?', ], - [$page->languageMain, $page->id] + [$page->languageMain, $page->id], ); // Reset languageMain if another page in the new page tree has the same languageMain @@ -133,7 +133,7 @@ private function resetPageAndChildren(int $pageId): void $this->connection->executeStatement( 'UPDATE tl_page SET languageMain = 0 WHERE id IN (?)', [$resetIds], - [Connection::PARAM_INT_ARRAY] + [Connection::PARAM_INT_ARRAY], ); } } diff --git a/src/EventListener/DataContainer/ParentTableListener.php b/src/EventListener/DataContainer/ParentTableListener.php index 3edfe57..6f3088f 100644 --- a/src/EventListener/DataContainer/ParentTableListener.php +++ b/src/EventListener/DataContainer/ParentTableListener.php @@ -51,6 +51,9 @@ public function register(): void ; } + /** + * @return array + */ public function onMasterOptions(DataContainer $dc) { if (null === ($jumpTo = PageModel::findByPk($dc->activeRecord->jumpTo))) { diff --git a/src/EventListener/InsertTagsListener.php b/src/EventListener/InsertTagsListener.php index acb207e..e0ce29a 100644 --- a/src/EventListener/InsertTagsListener.php +++ b/src/EventListener/InsertTagsListener.php @@ -31,7 +31,7 @@ public function __invoke(string $insertTag) { $parts = StringUtil::trimsplit('::', $insertTag); - if (0 !== strpos($parts[0], 'changelanguage')) { + if (!str_starts_with($parts[0], 'changelanguage')) { return false; } @@ -53,8 +53,8 @@ public function __invoke(string $insertTag) sprintf( '{{%s::%s}}', substr($parts[0], 15), - $targetPage->id - ) + $targetPage->id, + ), ); } } diff --git a/src/EventListener/Navigation/AbstractNavigationListener.php b/src/EventListener/Navigation/AbstractNavigationListener.php index 47f3414..468f05f 100644 --- a/src/EventListener/Navigation/AbstractNavigationListener.php +++ b/src/EventListener/Navigation/AbstractNavigationListener.php @@ -76,7 +76,7 @@ public function onChangelanguageNavigation(ChangelanguageNavigationEvent $event) "($t.id=? OR $t.languageMain=?)", sprintf('%s.pid=(SELECT id FROM %s WHERE (id=? OR master=?) AND jumpTo=?)', $t, $parent::getTable()), ], - [$mainId, $mainId, $masterId, $masterId, $targetPage->id] + [$mainId, $mainId, $masterId, $masterId, $targetPage->id], ); if (null === $translated) { diff --git a/src/EventListener/Navigation/ArticleNavigationListener.php b/src/EventListener/Navigation/ArticleNavigationListener.php index 464e837..a9d7302 100644 --- a/src/EventListener/Navigation/ArticleNavigationListener.php +++ b/src/EventListener/Navigation/ArticleNavigationListener.php @@ -44,7 +44,7 @@ public function __invoke(ChangelanguageNavigationEvent $event): void $parameterBag = $event->getUrlParameterBag(); $currentArticle = ArticleModel::findByIdOrAliasAndPid( $parameterBag->getUrlAttribute('articles'), - $objPage->id + $objPage->id, ); if (null === $currentArticle) { @@ -59,7 +59,7 @@ public function __invoke(ChangelanguageNavigationEvent $event): void $currentArticle, $targetRoot->id, $objPage->rootId === $masterRoot->id, - null !== $masterRoot && $targetRoot->id === $masterRoot->id + null !== $masterRoot && $targetRoot->id === $masterRoot->id, ); if (null === $targetArticle) { @@ -96,7 +96,7 @@ private function findTargetArticle(ArticleModel $currentArticle, $targetRootId, ], [ $currentIsFallback ? $currentArticle->id : $currentArticle->languageMain, - ] + ], ); } diff --git a/src/EventListener/Navigation/CalendarNavigationListener.php b/src/EventListener/Navigation/CalendarNavigationListener.php index fcae2b5..ea5a379 100644 --- a/src/EventListener/Navigation/CalendarNavigationListener.php +++ b/src/EventListener/Navigation/CalendarNavigationListener.php @@ -56,7 +56,7 @@ protected function findPublishedBy(array $columns, array $values = [], array $op return CalendarEventsModel::findOneBy( $this->addPublishedConditions($columns, CalendarEventsModel::getTable()), $values, - $options + $options, ); } } diff --git a/src/EventListener/Navigation/FaqNavigationListener.php b/src/EventListener/Navigation/FaqNavigationListener.php index 6f3da94..1c56847 100644 --- a/src/EventListener/Navigation/FaqNavigationListener.php +++ b/src/EventListener/Navigation/FaqNavigationListener.php @@ -56,7 +56,7 @@ protected function findPublishedBy(array $columns, array $values = [], array $op return FaqModel::findOneBy( $this->addPublishedConditions($columns, FaqModel::getTable(), false), $values, - $options + $options, ); } } diff --git a/src/EventListener/Navigation/NewsNavigationListener.php b/src/EventListener/Navigation/NewsNavigationListener.php index db8dbbd..bf8ac32 100644 --- a/src/EventListener/Navigation/NewsNavigationListener.php +++ b/src/EventListener/Navigation/NewsNavigationListener.php @@ -59,7 +59,7 @@ protected function findPublishedBy(array $columns, array $values = [], array $op return NewsModel::findOneBy( $this->addPublishedConditions($columns, NewsModel::getTable()), $values, - $options + $options, ); } } diff --git a/src/FrontendModule/ChangeLanguageModule.php b/src/FrontendModule/ChangeLanguageModule.php index 238512a..ee995ec 100755 --- a/src/FrontendModule/ChangeLanguageModule.php +++ b/src/FrontendModule/ChangeLanguageModule.php @@ -58,7 +58,7 @@ public function generate(): string $template->link = $this->name; $template->href = System::getContainer()->get('router')->generate( 'contao_backend', - ['do' => 'themes', 'table' => 'tl_module', 'act' => 'edit', 'id' => $this->id] + ['do' => 'themes', 'table' => 'tl_module', 'act' => 'edit', 'id' => $this->id], ); return $template->parse(); diff --git a/src/Helper/AlternateLinks.php b/src/Helper/AlternateLinks.php index 3c54862..82988b9 100644 --- a/src/Helper/AlternateLinks.php +++ b/src/Helper/AlternateLinks.php @@ -78,7 +78,7 @@ public function generate(string $templateName = 'block_alternate_links'): string private function store(string $language, string $href, string $title): void { // URLs must always be absolute - if (0 !== strpos($href, 'http://') && 0 !== strpos($href, 'https://')) { + if (!str_starts_with($href, 'http://') && !str_starts_with($href, 'https://')) { $href = Environment::get('base').$href; } diff --git a/src/Helper/LabelCallback.php b/src/Helper/LabelCallback.php index 8bf9507..dfa46b6 100644 --- a/src/Helper/LabelCallback.php +++ b/src/Helper/LabelCallback.php @@ -61,7 +61,7 @@ public static function createAndRegister($table, callable $callback) /** * @param callable $callback * - * @return mixed + * @return string|int */ private function executeCallback($callback, array $args) { @@ -69,7 +69,7 @@ private function executeCallback($callback, array $args) if (\is_array($callback)) { return \call_user_func_array( [System::importStatic($callback[0]), $callback[1]], - $args + $args, ); } diff --git a/src/Helper/LanguageText.php b/src/Helper/LanguageText.php index 7be0fc0..3b60381 100644 --- a/src/Helper/LanguageText.php +++ b/src/Helper/LanguageText.php @@ -78,14 +78,12 @@ static function (NavigationItem $a, NavigationItem $b) use ($languages) { $key2 = array_search(strtolower($b->getLanguageTag()), $languages, true); return $key1 <=> $key2; - } + }, ); } /** * Create instance from serialized data of optionsWizard widget. - * - * @param mixed $config */ public static function createFromOptionWizard($config): self { diff --git a/src/Migration/CustomLanguageTextMigration.php b/src/Migration/CustomLanguageTextMigration.php index 11e7e79..bfc1dc0 100644 --- a/src/Migration/CustomLanguageTextMigration.php +++ b/src/Migration/CustomLanguageTextMigration.php @@ -13,6 +13,7 @@ class CustomLanguageTextMigration extends AbstractMigration { private Connection $connection; + private ContaoFramework $framework; public function __construct(Connection $connection, ContaoFramework $framework) diff --git a/src/Navigation/NavigationFactory.php b/src/Navigation/NavigationFactory.php index 98169f1..032bb5e 100644 --- a/src/Navigation/NavigationFactory.php +++ b/src/Navigation/NavigationFactory.php @@ -12,8 +12,11 @@ class NavigationFactory { private PageFinder $pageFinder; + private LanguageText $languageText; + private PageModel $currentPage; + private array $locales = []; public function __construct(PageFinder $pageFinder, LanguageText $languageText, PageModel $currentPage, array $locales = []) @@ -37,7 +40,7 @@ public function findNavigationItems(PageModel $currentPage): array $this->setTargetPageForNavigationItems( $navigationItems, $rootPages, - $this->pageFinder->findAssociatedForPage($currentPage, false, $rootPages) + $this->pageFinder->findAssociatedForPage($currentPage, false, $rootPages), ); foreach ($navigationItems as $item) { @@ -45,7 +48,7 @@ public function findNavigationItems(PageModel $currentPage): array $item->setAriaLabel( $item->isDirectFallback() ? sprintf($GLOBALS['TL_LANG']['MSC']['gotoLanguage'], $this->locales[$item->getLocaleId()]) - : sprintf($GLOBALS['TL_LANG']['MSC']['switchLanguageTo'][1], $this->locales[$item->getLocaleId()]) + : sprintf($GLOBALS['TL_LANG']['MSC']['switchLanguageTo'][1], $this->locales[$item->getLocaleId()]), ); } @@ -55,7 +58,7 @@ public function findNavigationItems(PageModel $currentPage): array $this ->pageFinder ->findAssociatedParentForLanguage($currentPage, $item->getLanguageTag()), - false + false, ); } catch (\RuntimeException $e) { // parent page of current page not found or not published diff --git a/src/Navigation/NavigationItem.php b/src/Navigation/NavigationItem.php index cad19ee..5770cf2 100644 --- a/src/Navigation/NavigationItem.php +++ b/src/Navigation/NavigationItem.php @@ -11,13 +11,21 @@ class NavigationItem { private PageModel $rootPage; + private ?PageModel $targetPage = null; + private ?string $title = null; + private ?string $pageTitle = null; + private string $linkLabel; + private ?string $ariaLabel = null; + private ?bool $newWindow = null; + private bool $isDirectFallback = false; + private bool $isCurrentPage = false; public function __construct(PageModel $rootPage, ?string $label = null) @@ -45,6 +53,9 @@ public function isDirectFallback(): bool return $this->isDirectFallback; } + /** + * @param bool|string $isDirectFallback + */ public function setIsDirectFallback($isDirectFallback): void { $this->isDirectFallback = (bool) $isDirectFallback; diff --git a/src/Navigation/UrlParameterBag.php b/src/Navigation/UrlParameterBag.php index 2d08b9e..73867c2 100644 --- a/src/Navigation/UrlParameterBag.php +++ b/src/Navigation/UrlParameterBag.php @@ -7,6 +7,7 @@ class UrlParameterBag { private array $attributes; + private array $query; /** @@ -39,11 +40,17 @@ public function hasUrlAttribute(string $name): bool return \array_key_exists($name, $this->attributes); } + /** + * @return int|float|string|bool|null + */ public function getUrlAttribute(string $name) { return $this->hasUrlAttribute($name) ? $this->attributes[$name] : null; } + /** + * @param int|float|string|bool $value + */ public function setUrlAttribute(string $name, $value): void { $this->validateScalar($value); @@ -73,11 +80,17 @@ public function hasQueryParameter(string $name): bool return \array_key_exists($name, $this->query); } + /** + * @return int|float|string|bool|null + */ public function getQueryParameter(string $name) { return $this->hasQueryParameter($name) ? $this->query[$name] : null; } + /** + * @param int|float|string|bool $value + */ public function setQueryParameter(string $name, $value): void { $this->validateScalar($value); @@ -128,7 +141,7 @@ public function generateParameters(): ?string $attributes, static function (&$v, $k): void { $v = $k.'/'.$v; - } + }, ); $params = '/'.implode('/', $attributes); diff --git a/src/PageFinder.php b/src/PageFinder.php index cab286e..5126f63 100644 --- a/src/PageFinder.php +++ b/src/PageFinder.php @@ -82,7 +82,7 @@ public function findMasterRootForPage(PageModel $page): ?PageModel return PageModel::findOneBy( $columns, - [$page->domain, $page->domain, $page->domain] + [$page->domain, $page->domain, $page->domain], ); } @@ -127,7 +127,7 @@ static function (PageModel $page) use ($rootPages) { $page->loadDetails(); return \array_key_exists($page->rootId, $rootPages); - } + }, ); } @@ -215,7 +215,6 @@ private function addPublishingConditions(array &$columns, string $table): void */ private function findPages(array $columns, array $values, array $options = []): array { - /** @var Collection $collection */ $collection = PageModel::findBy($columns, $values, $options); if (!$collection instanceof Collection) { diff --git a/tests/ContaoTestCase.php b/tests/ContaoTestCase.php index afe6f61..793728b 100644 --- a/tests/ContaoTestCase.php +++ b/tests/ContaoTestCase.php @@ -31,7 +31,7 @@ protected function tearDown(): void Registry::getInstance()->reset(); } - protected function query($statement) + protected function query(string $statement): int { $connection = static::getConnection(); @@ -40,7 +40,7 @@ protected function query($statement) return (int) $connection->lastInsertId(); } - protected function createRootPage(string $dns = '', string $language = '', bool $fallback = true, $languageRoot = 0, bool $published = true): PageModel + protected function createRootPage(string $dns = '', string $language = '', bool $fallback = true, int $languageRoot = 0, bool $published = true): PageModel { $pageModel = new PageModel(); $pageModel->type = 'root'; @@ -56,7 +56,7 @@ protected function createRootPage(string $dns = '', string $language = '', bool return $pageModel; } - protected function createPage($pid = 0, $languageMain = 0, bool $published = true): PageModel + protected function createPage(int $pid = 0, int $languageMain = 0, bool $published = true): PageModel { $pageModel = new PageModel(); $pageModel->pid = $pid; diff --git a/tests/Helper/LanguageTextTest.php b/tests/Helper/LanguageTextTest.php index c6fe6ea..c283967 100644 --- a/tests/Helper/LanguageTextTest.php +++ b/tests/Helper/LanguageTextTest.php @@ -8,6 +8,7 @@ use Contao\PageModel; use Contao\System; use Contao\TestCase\ContaoTestCase; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\DependencyInjection\ContainerInterface; use Terminal42\ChangeLanguage\Helper\LanguageText; use Terminal42\ChangeLanguage\Navigation\NavigationItem; @@ -151,7 +152,10 @@ public function testIgnoresEmptyOptionWizardRows(): void $this->assertFalse($languageText->has('fr')); } - private function createRootPage($dns, $language) + /** + * @return PageModel&MockObject + */ + private function createRootPage(string $dns, string $language): PageModel { $pageModel = $this->mockClassWithProperties(PageModel::class, [ 'type' => 'root', diff --git a/tests/LanguageTest.php b/tests/LanguageTest.php index c77fc6c..c99f59b 100644 --- a/tests/LanguageTest.php +++ b/tests/LanguageTest.php @@ -10,59 +10,47 @@ class LanguageTest extends TestCase { /** - * @param mixed $localeId - * @param mixed $languageTag - * * @dataProvider languagesProvider */ - public function testConvertLocaleIdToLanguageTag($localeId, $languageTag): void + public function testConvertLocaleIdToLanguageTag(string $localeId, string $languageTag): void { $this->assertSame($languageTag, Language::toLanguageTag($localeId)); } /** - * @param mixed $localeId - * @param mixed $languageTag - * * @dataProvider languagesProvider */ - public function testConvertLanguageTagToLocaleId($localeId, $languageTag): void + public function testConvertLanguageTagToLocaleId(string $localeId, string $languageTag): void { $this->assertSame($localeId, Language::toLocaleID($languageTag)); } /** - * @param mixed $language - * * @dataProvider invalidLanguagesProvider */ - public function testInvalidLanguage($language): void + public function testInvalidLanguage(string $language): void { $this->expectException('InvalidArgumentException'); Language::normalize($language, '-'); } - public function languagesProvider() + public function languagesProvider(): \Generator { - return [ - ['en', 'en'], - ['de', 'de'], - ['en_US', 'en-US'], - ['de_DE', 'de-DE'], - ['de_CH', 'de-CH'], - ]; + yield ['en', 'en']; + yield ['de', 'de']; + yield ['en_US', 'en-US']; + yield ['de_DE', 'de-DE']; + yield ['de_CH', 'de-CH']; } - public function invalidLanguagesProvider() + public function invalidLanguagesProvider(): \Generator { - return [ - [''], - ['-'], - ['en-'], - ['en_'], - ['cn-Hant'], - ['cn-Hant-TW'], - ]; + yield ['']; + yield ['-']; + yield ['en-']; + yield ['en_']; + yield ['cn-Hant']; + yield ['cn-Hant-TW']; } } diff --git a/tests/Navigation/UrlParameterBagTest.php b/tests/Navigation/UrlParameterBagTest.php index ae75d24..4956a75 100644 --- a/tests/Navigation/UrlParameterBagTest.php +++ b/tests/Navigation/UrlParameterBagTest.php @@ -9,9 +9,6 @@ class UrlParameterBagTest extends TestCase { - /** - * {@inheritdoc} - */ protected function setUp(): void { $GLOBALS['TL_CONFIG']['useAutoItem'] = true; diff --git a/tests/PageFinder/AssociatedForPageTest.php b/tests/PageFinder/AssociatedForPageTest.php index 0fa7cff..1d61b70 100644 --- a/tests/PageFinder/AssociatedForPageTest.php +++ b/tests/PageFinder/AssociatedForPageTest.php @@ -130,7 +130,7 @@ public function testIgnoresPagesInWrongRoot(): void $this->assertPageCount($pages, 2); } - private function assertPageCount($pages, $count): void + private function assertPageCount(array $pages, int $count): void { $this->assertCount($count, $pages); diff --git a/tests/PageFinder/RootPagesTest.php b/tests/PageFinder/RootPagesTest.php index ae8c643..68a8be7 100644 --- a/tests/PageFinder/RootPagesTest.php +++ b/tests/PageFinder/RootPagesTest.php @@ -156,7 +156,7 @@ public function testKeyEqualsPageId(): void } } - private function assertPageCount($roots, $count): void + private function assertPageCount(array $roots, int $count): void { $this->assertCount($count, $roots);