Skip to content

Commit

Permalink
CS & argument and return types
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Nov 30, 2022
1 parent 53099c7 commit 87f5c1f
Show file tree
Hide file tree
Showing 23 changed files with 104 additions and 419 deletions.
13 changes: 3 additions & 10 deletions src/EventListener/AbstractTableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@

abstract class AbstractTableListener
{
/**
* @var string
*/
protected $table;
protected string $table;

/**
* Constructor.
*
* @param string $table
*/
public function __construct($table)
public function __construct(string $table)
{
$this->table = $table;
}
Expand All @@ -28,10 +23,8 @@ abstract public function register();

/**
* Gets the table name for this listener.
*
* @return string
*/
protected function getTable()
protected function getTable(): string
{
return $this->table;
}
Expand Down
14 changes: 2 additions & 12 deletions src/EventListener/BackendView/AbstractViewListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,9 @@

abstract class AbstractViewListener extends AbstractTableListener
{
/**
* @var DataContainer
*/
protected $dataContainer;
protected DataContainer $dataContainer;
protected PageFinder $pageFinder;

/**
* @var PageFinder
*/
protected $pageFinder;

/**
* {@inheritdoc}
*/
public function __construct($table)
{
parent::__construct($table);
Expand Down
26 changes: 5 additions & 21 deletions src/EventListener/BackendView/ArticleViewListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@
class ArticleViewListener extends AbstractViewListener
{
/**
* @var ArticleModel
* @var ArticleModel|false|null
*/
private $currentArticle = false;

/**
* {@inheritdoc}
*/
protected function isSupported()
protected function isSupported(): bool
{
return 'article' === (string) Input::get('do')
&& (
Expand All @@ -32,10 +29,7 @@ protected function isSupported()
);
}

/**
* {@inheritdoc}
*/
protected function getCurrentPage()
protected function getCurrentPage(): ?PageModel
{
if (false === $this->currentArticle) {
if (Input::get('table') === $this->getTable() && !empty(Input::get('act'))) {
Expand All @@ -56,10 +50,7 @@ protected function getCurrentPage()
return PageModel::findWithDetails($this->currentArticle->pid);
}

/**
* {@inheritdoc}
*/
protected function getAvailableLanguages(PageModel $page)
protected function getAvailableLanguages(PageModel $page): array
{
$options = [];
$masterRoot = $this->pageFinder->findMasterRootForPage($page);
Expand Down Expand Up @@ -103,11 +94,6 @@ protected function getAvailableLanguages(PageModel $page)
return $options;
}

/**
* {@inheritdoc}
*
* @throws \InvalidArgumentException
*/
protected function doSwitchView($id): void
{
$uri = Uri::createFromString(System::getContainer()->get('request_stack')->getCurrentRequest()->getUri());
Expand All @@ -118,11 +104,9 @@ protected function doSwitchView($id): void
}

/**
* @param int $articleId
*
* @return array<ArticleModel>
*/
private function findArticlesForPage(PageModel $page, $articleId): array
private function findArticlesForPage(PageModel $page, int $articleId): array
{
$articles = ArticleModel::findBy(
[
Expand Down
18 changes: 3 additions & 15 deletions src/EventListener/BackendView/PageViewListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,12 @@

class PageViewListener extends AbstractViewListener
{
/**
* {@inheritdoc}
*/
protected function isSupported()
protected function isSupported(): bool
{
return 'page' === Input::get('do') || ('article' === Input::get('do') && 'edit' !== Input::get('act'));
}

/**
* {@inheritdoc}
*/
protected function getCurrentPage()
protected function getCurrentPage(): ?PageModel
{
$node = System::getContainer()->get('request_stack')->getSession()->getBag('contao_backend')->get('tl_page_node');

Expand All @@ -35,10 +29,7 @@ protected function getCurrentPage()
return PageModel::findByPk($node);
}

/**
* {@inheritdoc}
*/
protected function getAvailableLanguages(PageModel $page)
protected function getAvailableLanguages(PageModel $page): array
{
$options = [];

Expand All @@ -50,9 +41,6 @@ protected function getAvailableLanguages(PageModel $page)
return $options;
}

/**
* {@inheritdoc}
*/
protected function doSwitchView($id): void
{
$requestStack = System::getContainer()->get('request_stack');
Expand Down
19 changes: 3 additions & 16 deletions src/EventListener/DataContainer/CalendarEventsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,23 @@

namespace Terminal42\ChangeLanguage\EventListener\DataContainer;

use Contao\CalendarEventsModel;
use Contao\Date;
use Contao\Model;
use Contao\Model\Collection;

class CalendarEventsListener extends AbstractChildTableListener
{
/**
* {@inheritdoc}
*/
protected function getTitleField()
protected function getTitleField(): string
{
return 'title';
}

/**
* {@inheritdoc}
*/
protected function getSorting()
protected function getSorting(): string
{
return 'startTime DESC';
}

/**
* {@inheritdoc}
*
* @param CalendarEventsModel $current
* @param Collection<CalendarEventsModel> $models
*/
protected function formatOptions(Model $current, Collection $models)
protected function formatOptions(Model $current, Collection $models): array
{
$options = [];

Expand Down
19 changes: 3 additions & 16 deletions src/EventListener/DataContainer/FaqListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,22 @@

namespace Terminal42\ChangeLanguage\EventListener\DataContainer;

use Contao\FaqModel;
use Contao\Model;
use Contao\Model\Collection;

class FaqListener extends AbstractChildTableListener
{
/**
* {@inheritdoc}
*/
protected function getTitleField()
protected function getTitleField(): string
{
return 'question';
}

/**
* {@inheritdoc}
*/
protected function getSorting()
protected function getSorting(): string
{
return 'sorting';
}

/**
* {@inheritdoc}
*
* @param FaqModel $current
* @param Collection<FaqModel> $models
*/
protected function formatOptions(Model $current, Collection $models)
protected function formatOptions(Model $current, Collection $models): array
{
$options = [];

Expand Down
20 changes: 5 additions & 15 deletions src/EventListener/DataContainer/MissingLanguageIconListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ public function register($table): void
* Adds missing translation warning to page tree.
*
* @param mixed $previousResult
*
* @return string
*/
public function onPageLabel(array $args, $previousResult = null)
private function onPageLabel(array $args, $previousResult = null): string
{
[$row, $label] = $args;

Expand Down Expand Up @@ -95,10 +93,8 @@ public function onPageLabel(array $args, $previousResult = null)
* Adds missing translation warning to article tree.
*
* @param mixed $previousResult
*
* @return string
*/
public function onArticleLabel(array $args, $previousResult = null)
private function onArticleLabel(array $args, $previousResult = null): string
{
[$row, $label] = $args;

Expand All @@ -124,10 +120,8 @@ public function onArticleLabel(array $args, $previousResult = null)
* Generate missing translation warning for news child records.
*
* @param mixed $previousResult
*
* @return string
*/
public function onNewsChildRecords(array $args, $previousResult = null)
private function onNewsChildRecords(array $args, $previousResult = null): string
{
$row = $args[0];
$label = (string) $previousResult;
Expand All @@ -153,10 +147,8 @@ public function onNewsChildRecords(array $args, $previousResult = null)
* Generate missing translation warning for calendar events child records.
*
* @param mixed $previousResult
*
* @return string
*/
public function onCalendarEventChildRecords(array $args, $previousResult = null)
private function onCalendarEventChildRecords(array $args, $previousResult = null): string
{
$row = $args[0];
$label = (string) $previousResult;
Expand All @@ -178,10 +170,8 @@ public function onCalendarEventChildRecords(array $args, $previousResult = null)
* Generate missing translation warning for faq child records.
*
* @param mixed $previousResult
*
* @return string
*/
public function onFaqChildRecords(array $args, $previousResult = null)
private function onFaqChildRecords(array $args, $previousResult = null): string
{
$row = $args[0];
$label = (string) $previousResult;
Expand Down
19 changes: 3 additions & 16 deletions src/EventListener/DataContainer/NewsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,20 @@
use Contao\Date;
use Contao\Model;
use Contao\Model\Collection;
use Contao\NewsModel;

class NewsListener extends AbstractChildTableListener
{
/**
* {@inheritdoc}
*/
protected function getTitleField()
protected function getTitleField(): string
{
return 'headline';
}

/**
* {@inheritdoc}
*/
protected function getSorting()
protected function getSorting(): string
{
return 'date DESC, time DESC';
}

/**
* {@inheritdoc}
*
* @param NewsModel $current
* @param Collection<NewsModel> $models
*/
protected function formatOptions(Model $current, Collection $models)
protected function formatOptions(Model $current, Collection $models): array
{
$sameDay = $GLOBALS['TL_LANG']['tl_news']['sameDay'];
$otherDay = $GLOBALS['TL_LANG']['tl_news']['otherDay'];
Expand Down
2 changes: 1 addition & 1 deletion src/EventListener/DataContainer/PageFieldsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function onSaveLanguageMain($value, DataContainer $dc)
*
* @return array
*/
public function onLanguageRootOptions(DataContainer $dc)
public function onLanguageRootOptions(DataContainer $dc): array
{
/** @var array<PageModel> $pages */
$pages = PageModel::findBy(
Expand Down
7 changes: 1 addition & 6 deletions src/EventListener/DataContainer/ParentTableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ class ParentTableListener
{
private string $table;

/**
* Constructor.
*
* @param string $table
*/
public function __construct($table)
public function __construct(string $table)
{
$this->table = $table;
}
Expand Down
2 changes: 1 addition & 1 deletion src/EventListener/DataContainer/UserLabelsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(Connection $connection)
$this->connection = $connection;
}

public function __invoke()
public function __invoke(): array
{
$pages = $this->connection->fetchAllAssociative("SELECT id, title FROM tl_page WHERE type='root' AND (fallback='' OR languageRoot!=0) ORDER BY pid, sorting");

Expand Down
7 changes: 1 addition & 6 deletions src/EventListener/Navigation/AbstractNavigationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,8 @@ public function onChangelanguageNavigation(ChangelanguageNavigationEvent $event)

/**
* Adds publishing conditions to Model query columns if backend user is not logged in.
*
* @param string $table
* @param bool $addStartStop
*
* @return array
*/
protected function addPublishedConditions(array $columns, $table, $addStartStop = true)
protected function addPublishedConditions(array $columns, string $table, bool $addStartStop = true): array
{
if (true !== BE_USER_LOGGED_IN) {
$columns[] = "$table.published='1'";
Expand Down
Loading

0 comments on commit 87f5c1f

Please sign in to comment.