Skip to content

Commit

Permalink
Fix the coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Jul 16, 2020
1 parent 2fa6eee commit bfab096
Show file tree
Hide file tree
Showing 46 changed files with 256 additions and 198 deletions.
5 changes: 1 addition & 4 deletions core-bundle/src/ContaoCoreBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ public function build(ContainerBuilder $container): void
$container->addCompilerPass(new SearchIndexerPass()); // Must be before the CrawlerPass
$container->addCompilerPass(new CrawlerPass());
$container->addCompilerPass(new AddCronJobsPass());

$container->addCompilerPass(
new RegisterRouteEnhancersPass('contao.routing.page_router', 'contao.page_router_enhancer')
);
$container->addCompilerPass(new RegisterRouteEnhancersPass('contao.routing.page_router', 'contao.page_router_enhancer'));
}
}
8 changes: 6 additions & 2 deletions core-bundle/src/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ protected function tagResponse(array $tags): void

/**
* Uses the Symfony router to generate a URL for the given content.
* _Content_ in this case should be any supported model/entity of Contao, e.g. a PageModel, NewsModel or similar.
*
* "Content" in this case should be any supported model/entity of Contao,
* e.g. a PageModel, NewsModel or similar.
*/
protected function generateContentUrl($content, array $parameters = [], int $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH): string
{
Expand All @@ -59,7 +61,9 @@ protected function generateContentUrl($content, array $parameters = [], int $ref

/**
* Uses the Symfony router to generate redirect response to the URL of the given content.
* _Content_ in this case should be any supported model/entity of Contao, e.g. a PageModel, NewsModel or similar.
*
* "Content" in this case should be any supported model/entity of Contao,
* e.g. a PageModel, NewsModel or similar.
*/
protected function redirectToContent($content, array $parameters = [], int $status = 302): RedirectResponse
{
Expand Down
3 changes: 1 addition & 2 deletions core-bundle/src/Controller/Page/RootPageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ private function getNextPage(int $rootPageId): PageModel

/** @var PageModel $pageAdapter */
$pageAdapter = $this->get('contao.framework')->getAdapter(PageModel::class);

$nextPage = $pageAdapter->findFirstPublishedByPid($rootPageId);

if (null !== $nextPage) {
Expand All @@ -79,7 +78,7 @@ private function getNextPage(int $rootPageId): PageModel
if (null !== ($logger = $this->get('logger'))) {
$logger->error(
'No active page found under root page "'.$rootPageId.'"',
['contao' => new ContaoContext(__METHOD__, ContaoContext::ERROR)]
['contao' => new ContaoContext(__METHOD__, ContaoContext::ERROR)]
);
}

Expand Down
10 changes: 7 additions & 3 deletions core-bundle/src/DataCollector/ContaoDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,15 @@ private function addLegacyRoutingData(): void

foreach ($GLOBALS['TL_HOOKS'][$name] as $callback) {
$class = $systemAdapter->importStatic($callback[0]);
$r = new \ReflectionClass($class);
$file = $r->getFileName();
$file = (new \ReflectionClass($class))->getFileName();
$vendorDir = $this->parameterBag->get('kernel.project_dir').'/vendor/';

$hook = ['name' => $name, 'class' => \get_class($class), 'method' => $callback[1], 'package' => ''];
$hook = [
'name' => $name,
'class' => \get_class($class),
'method' => $callback[1],
'package' => '',
];

if (Path::isBasePath($vendorDir, $file)) {
[$vendor, $package] = explode('/', Path::makeRelative($file, $vendorDir), 3);
Expand Down
1 change: 1 addition & 0 deletions core-bundle/src/Event/FilterPageTypeEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class FilterPageTypeEvent
* @var array
*/
private $options;

/**
* @var DataContainer
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function renderPageArticlesOperation(array $row, string $href, string $la
}

/**
* Automatically create an article in the main column of a new page.
* Automatically creates an article in the main column of a new page.
*
* @Callback(table="tl_page", target="config.onsubmit", priority=-16)
*/
Expand All @@ -122,7 +122,7 @@ public function generateArticleForPage(DataContainer $dc): void
$user = $this->security->getUser();

// Return if there is no active record (override all)
if (!$dc->activeRecord || null === $request || !$request->hasSession() || !$user instanceof BackendUser) {
if (!$dc->activeRecord || null === $request || !$user instanceof BackendUser || !$request->hasSession()) {
return;
}

Expand Down Expand Up @@ -152,10 +152,13 @@ public function generateArticleForPage(DataContainer $dc): void
}

// Check whether there are articles (e.g. on copied pages)
$total = $this->connection->executeQuery(
'SELECT COUNT(*) FROM tl_article WHERE pid=:pid',
['pid' => $dc->id]
)->fetchColumn();
$total = $this->connection
->executeQuery(
'SELECT COUNT(*) FROM tl_article WHERE pid=:pid',
['pid' => $dc->id]
)
->fetchColumn()
;

if ($total > 0) {
return;
Expand Down Expand Up @@ -207,18 +210,14 @@ private function renderArticlePasteIntoButton(DataContainer $dc, array $row, boo
'<a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a> ',
$this->backend->addToUrl('act='.$clipboard['mode'].'&amp;mode=2&amp;pid='.$row['id'].(!\is_array($clipboard['id'] ?? null) ? '&amp;id='.$clipboard['id'] : '')),
StringUtil::specialchars($this->translator->trans($dc->table.'.pasteinto.1', [$row['id']], 'contao_'.$dc->table)),
$this->image->getHtml(
'pasteinto.svg',
$this->translator->trans($dc->table.'.pasteinto.1', [$row['id']], 'contao_'.$dc->table)
)
$this->image->getHtml('pasteinto.svg', $this->translator->trans($dc->table.'.pasteinto.1', [$row['id']], 'contao_'.$dc->table))
);
}

private function renderArticlePasteAfterButton(DataContainer $dc, array $row, bool $cr, array $clipboard = null)
{
/** @var PageModel $pageAdapter */
$pageAdapter = $this->framework->getAdapter(PageModel::class);

$pageModel = $pageAdapter->findByPk($row['pid']);

// Do not show paste button for pages without content composition or articles in layout
Expand All @@ -243,10 +242,7 @@ private function renderArticlePasteAfterButton(DataContainer $dc, array $row, bo
'<a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a> ',
$this->backend->addToUrl('act='.$clipboard['mode'].'&amp;mode=1&amp;pid='.$row['id'].(!\is_array($clipboard['id']) ? '&amp;id='.$clipboard['id'] : '')),
StringUtil::specialchars($this->translator->trans($dc->table.'.pasteafter.1', [$row['id']], 'contao_'.$dc->table)),
$this->image->getHtml(
'pasteafter.svg',
$this->translator->trans($dc->table.'.pasteafter.1', [$row['id']], 'contao_'.$dc->table)
)
$this->image->getHtml('pasteafter.svg', $this->translator->trans($dc->table.'.pasteafter.1', [$row['id']], 'contao_'.$dc->table))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function overrideUrlPrefix($value, DataContainer $dc)
/**
* @Callback(table="tl_page", target="fields.urlSuffix.load")
*/
public function overrideUrlSuffix()
public function overrideUrlSuffix(): string
{
return $this->urlSuffix;
}
Expand Down
38 changes: 20 additions & 18 deletions core-bundle/src/EventListener/DataContainer/PageUrlListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,22 +149,24 @@ public function validateUrlPrefix(string $value, DataContainer $dc): string
}

// First check if another root page uses the same url prefix and domain
$count = $this->connection->executeQuery(
'SELECT COUNT(*) FROM tl_page WHERE urlPrefix=:urlPrefix AND dns=:dns AND id!=:rootId',
[
'urlPrefix' => $value,
'dns' => $dc->activeRecord->dns,
'rootId' => $dc->id,
]
)->fetchColumn();
$count = $this->connection
->executeQuery(
'SELECT COUNT(*) FROM tl_page WHERE urlPrefix=:urlPrefix AND dns=:dns AND id!=:rootId',
[
'urlPrefix' => $value,
'dns' => $dc->activeRecord->dns,
'rootId' => $dc->id,
]
)
->fetchColumn()
;

if ($count > 0) {
throw new \RuntimeException($this->translator->trans('ERR.urlPrefixExists', [$value], 'contao_default'));
}

/** @var PageModel|Adapter $pageAdapter */
$pageAdapter = $this->framework->getAdapter(PageModel::class);

$rootPage = $pageAdapter->findByPk($dc->id);

if (null === $rootPage) {
Expand All @@ -191,7 +193,6 @@ public function validateUrlSuffix($value, DataContainer $dc)

/** @var PageModel|Adapter $pageAdapter */
$pageAdapter = $this->framework->getAdapter(PageModel::class);

$rootPage = $pageAdapter->findByPk($dc->id);

if (null === $rootPage) {
Expand All @@ -215,10 +216,13 @@ public function reset(): void

private function purgeSearchIndex(int $pageId): void
{
$urls = $this->connection->executeQuery(
'SELECT url FROM tl_search WHERE pid=:pageId',
['pageId' => $pageId]
)->fetchAll(FetchMode::COLUMN);
$urls = $this->connection
->executeQuery(
'SELECT url FROM tl_search WHERE pid=:pageId',
['pageId' => $pageId]
)
->fetchAll(FetchMode::COLUMN)
;

foreach ($urls as $url) {
$this->searchIndexer->delete(new Document(new Uri($url), 200));
Expand All @@ -232,7 +236,6 @@ private function recursiveValidatePages(int $pid, PageModel $rootPage): void
{
/** @var PageModel|Adapter $pageAdapter */
$pageAdapter = $this->framework->getAdapter(PageModel::class);

$pages = $pageAdapter->findByPid($pid);

if (null === $pages) {
Expand All @@ -242,7 +245,6 @@ private function recursiveValidatePages(int $pid, PageModel $rootPage): void
/** @var PageModel $page */
foreach ($pages as $page) {
$this->aliasExists($page->alias, (int) $page->id, $rootPage, true);

$this->recursiveValidatePages((int) $page->id, $rootPage);
}
}
Expand Down Expand Up @@ -275,7 +277,8 @@ private function aliasExists(string $currentAlias, int $currentId, PageModel $cu
'alias' => '%'.$this->stripPrefixesAndSuffixes($currentAlias, $currentPrefix, $currentSuffix).'%',
'id' => $currentId,
]
)->fetchAll(FetchMode::COLUMN)
)
->fetchAll(FetchMode::COLUMN)
;

if (0 === \count($aliasIds)) {
Expand All @@ -284,7 +287,6 @@ private function aliasExists(string $currentAlias, int $currentId, PageModel $cu

/** @var PageModel|Adapter $pageAdapter */
$pageAdapter = $this->framework->getAdapter(PageModel::class);

$currentUrl = $this->buildUrl($currentAlias, $currentPrefix, $currentSuffix);

foreach ($aliasIds as $aliasId) {
Expand Down
7 changes: 2 additions & 5 deletions core-bundle/src/Framework/ContaoFramework.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,13 +456,10 @@ private function registerHookListeners(): void

private function throwOnLegacyRoutingHooks(): void
{
if (
empty($GLOBALS['TL_HOOKS']['getPageIdFromUrl'])
&& empty($GLOBALS['TL_HOOKS']['getRootPageFromUrl'])
) {
if (empty($GLOBALS['TL_HOOKS']['getPageIdFromUrl']) && empty($GLOBALS['TL_HOOKS']['getRootPageFromUrl'])) {
return;
}

throw new LegacyRoutingException('Legacy routing is required to support the getPageIdFromUrl and getRootPageFromUrl hooks. Check the Symfony inspector for more information.');
throw new LegacyRoutingException('Legacy routing is required to support the "getPageIdFromUrl" and "getRootPageFromUrl" hooks. Check the Symfony inspector for more information.');
}
}
1 change: 0 additions & 1 deletion core-bundle/src/Resources/contao/classes/Frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,6 @@ public static function getRootPageFromUrl()
*/
public static function addToUrl($strRequest, $blnIgnoreParams=false, $arrUnset=array())
{
/** @var PageModel $objPage */
global $objPage;

$arrGet = $blnIgnoreParams ? array() : $_GET;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,8 @@ protected static function replaceOldBePaths($strContext)
*
* @return string An URL that can be used in the front end
*
* @deprecated Deprecated since Contao 4.2, to be removed in Contao 5.0. Use the Symfony router instead.
* @deprecated Deprecated since Contao 4.2, to be removed in Contao 5.0.
* Use the Symfony router instead.
*/
public static function generateFrontendUrl(array $arrRow, $strParams=null, $strForceLang=null, $blnFixDomain=false)
{
Expand Down
15 changes: 15 additions & 0 deletions core-bundle/src/Resources/contao/models/PageModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,12 @@
* @method static PageModel|null findOneByTstamp($val, array $opt=array())
* @method static PageModel|null findOneByTitle($val, array $opt=array())
* @method static PageModel|null findOneByAlias($val, array $opt=array())
* @method static PageModel|null findOneByParameters($val, array $opt=array())
* @method static PageModel|null findOneByType($val, array $opt=array())
* @method static PageModel|null findOneByPageTitle($val, array $opt=array())
* @method static PageModel|null findOneByLanguage($val, array $opt=array())
* @method static PageModel|null findOneByUseFolderUrl($val, array $opt=array())
* @method static PageModel|null findOneByUseAutoItem($val, array $opt=array())
* @method static PageModel|null findOneByRobots($val, array $opt=array())
* @method static PageModel|null findOneByDescription($val, array $opt=array())
* @method static PageModel|null findOneByRedirect($val, array $opt=array())
Expand All @@ -138,6 +140,9 @@
* @method static PageModel|null findOneByDateFormat($val, array $opt=array())
* @method static PageModel|null findOneByTimeFormat($val, array $opt=array())
* @method static PageModel|null findOneByDatimFormat($val, array $opt=array())
* @method static PageModel|null findOneByValidAliasCharacters($val, array $opt=array())
* @method static PageModel|null findOneByUrlPrefix($val, array $opt=array())
* @method static PageModel|null findOneByUrlSuffix($val, array $opt=array())
* @method static PageModel|null findOneByCreateSitemap($val, array $opt=array())
* @method static PageModel|null findOneBySitemapName($val, array $opt=array())
* @method static PageModel|null findOneByUseSSL($val, array $opt=array())
Expand Down Expand Up @@ -170,10 +175,12 @@
* @method static Collection|PageModel[]|PageModel|null findByTstamp($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByTitle($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByAlias($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByParameters($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByType($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByPageTitle($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByLanguage($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByUseFolderUrl($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByUseAutoItem($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByRobots($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByDescription($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByRedirect($val, array $opt=array())
Expand All @@ -191,6 +198,9 @@
* @method static Collection|PageModel[]|PageModel|null findByDateFormat($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByTimeFormat($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByDatimFormat($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByValidAliasCharacters($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByUrlPrefix($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByUrlSuffix($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByCreateSitemap($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findBySitemapName($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByUseSSL($val, array $opt=array())
Expand Down Expand Up @@ -227,10 +237,12 @@
* @method static integer countByTstamp($val, array $opt=array())
* @method static integer countByTitle($val, array $opt=array())
* @method static integer countByAlias($val, array $opt=array())
* @method static integer countByParameters($val, array $opt=array())
* @method static integer countByType($val, array $opt=array())
* @method static integer countByPageTitle($val, array $opt=array())
* @method static integer countByLanguage($val, array $opt=array())
* @method static integer countByUseFolderUrl($val, array $opt=array())
* @method static integer countByUseAutoItem($val, array $opt=array())
* @method static integer countByRobots($val, array $opt=array())
* @method static integer countByDescription($val, array $opt=array())
* @method static integer countByRedirect($val, array $opt=array())
Expand All @@ -248,6 +260,9 @@
* @method static integer countByDateFormat($val, array $opt=array())
* @method static integer countByTimeFormat($val, array $opt=array())
* @method static integer countByDatimFormat($val, array $opt=array())
* @method static integer countByValidAliasCharacters($val, array $opt=array())
* @method static integer countByUrlPrefix($val, array $opt=array())
* @method static integer countByUrlSuffix($val, array $opt=array())
* @method static integer countByCreateSitemap($val, array $opt=array())
* @method static integer countBySitemapName($val, array $opt=array())
* @method static integer countByUseSSL($val, array $opt=array())
Expand Down
2 changes: 1 addition & 1 deletion core-bundle/src/Resources/contao/pages/PageError404.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function prepare()
// Find the matching root page
$objRootPage = $this->getRootPageFromUrl();

// Forward if the language should be but is not set (see #4028).
// Forward if the language should be but is not set (see #4028)
if ($objRootPage->urlPrefix)
{
// Get the request string without the script name
Expand Down
Loading

0 comments on commit bfab096

Please sign in to comment.