Skip to content

Commit

Permalink
Clean up before the release
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Dec 10, 2020
1 parent 137d410 commit 7db3c54
Show file tree
Hide file tree
Showing 20 changed files with 36 additions and 72 deletions.
2 changes: 0 additions & 2 deletions core-bundle/src/Command/CrawlCommand.php
Expand Up @@ -13,7 +13,6 @@
namespace Contao\CoreBundle\Command;

use Contao\CoreBundle\Crawl\Escargot\Factory;
use Contao\CoreBundle\Crawl\Escargot\Subscriber\SubscriberResult;
use Contao\CoreBundle\Crawl\Monolog\CrawlCsvLogHandler;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\GroupHandler;
Expand Down Expand Up @@ -143,7 +142,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
foreach ($this->escargotFactory->getSubscribers($subscribers) as $subscriber) {
$io->section($subscriber->getName());

/** @var SubscriberResult $result */
$result = $subscriber->getResult();

if ($result->wasSuccessful()) {
Expand Down
22 changes: 11 additions & 11 deletions core-bundle/src/Controller/FrontendModule/TwoFactorController.php
Expand Up @@ -38,22 +38,22 @@ class TwoFactorController extends AbstractFrontendModuleController
/**
* @var PageModel
*/
protected $page;
protected $pageModel;

public function __invoke(Request $request, ModuleModel $model, string $section, array $classes = null, PageModel $page = null): Response
public function __invoke(Request $request, ModuleModel $model, string $section, array $classes = null, PageModel $pageModel = null): Response
{
if (!$this->get('security.helper')->isGranted('IS_AUTHENTICATED_FULLY')) {
// TODO: front end users should be able to re-authenticate after REMEMBERME
return new Response('', Response::HTTP_NO_CONTENT);
}

$this->page = $page;
$this->pageModel = $pageModel;

if (
$this->page instanceof PageModel
$this->pageModel instanceof PageModel
&& $this->get('contao.routing.scope_matcher')->isFrontendRequest($request)
) {
$this->page->loadDetails();
$this->pageModel->loadDetails();
}

return parent::__invoke($request, $model, $section, $classes);
Expand Down Expand Up @@ -87,19 +87,19 @@ protected function getResponse(Template $template, ModuleModel $model, Request $
$adapter = $this->get('contao.framework')->getAdapter(PageModel::class);

$redirectPage = $model->jumpTo > 0 ? $adapter->findByPk($model->jumpTo) : null;
$return = $redirectPage instanceof PageModel ? $redirectPage->getAbsoluteUrl() : $this->page->getAbsoluteUrl();
$return = $redirectPage instanceof PageModel ? $redirectPage->getAbsoluteUrl() : $this->pageModel->getAbsoluteUrl();

$template->enforceTwoFactor = $this->page->enforceTwoFactor;
$template->enforceTwoFactor = $this->pageModel->enforceTwoFactor;
$template->targetPath = $return;

$translator = $this->get('translator');

// Inform the user if 2FA is enforced
if ($this->page->enforceTwoFactor) {
if ($this->pageModel->enforceTwoFactor) {
$template->message = $translator->trans('MSC.twoFactorEnforced', [], 'contao_default');
}

if ((!$user->useTwoFactor && $this->page->enforceTwoFactor) || 'enable' === $request->get('2fa')) {
if ((!$user->useTwoFactor && $this->pageModel->enforceTwoFactor) || 'enable' === $request->get('2fa')) {
$response = $this->enableTwoFactor($template, $request, $user, $return);

if (null !== $response) {
Expand Down Expand Up @@ -134,7 +134,7 @@ protected function getResponse(Template $template, ModuleModel $model, Request $
}

$template->isEnabled = (bool) $user->useTwoFactor;
$template->href = $this->page->getAbsoluteUrl().'?2fa=enable';
$template->href = $this->pageModel->getAbsoluteUrl().'?2fa=enable';
$template->backupCodes = json_decode((string) $user->backupCodes, true) ?? [];
$template->trustedDevices = $this->get('contao.security.two_factor.trusted_device_manager')->getTrustedDevices($user);

Expand Down Expand Up @@ -197,7 +197,7 @@ private function disableTwoFactor(FrontendUser $user): ?Response
// Clear all trusted devices
$this->get('contao.security.two_factor.trusted_device_manager')->clearTrustedDevices($user);

return new RedirectResponse($this->page->getAbsoluteUrl());
return new RedirectResponse($this->pageModel->getAbsoluteUrl());
}

private function generateBackupCodes(FrontendUser $user): void
Expand Down
6 changes: 2 additions & 4 deletions core-bundle/src/Controller/InitializeController.php
Expand Up @@ -127,7 +127,7 @@ static function () use ($self, $realRequest, $response): void {
*
* @see HttpKernel::handleException()
*/
private function handleException(\Throwable $e, Request $request, $type): void
private function handleException(\Throwable $e, Request $request, int $type): void
{
$event = new ExceptionEvent($this->get('http_kernel'), $request, $type, $e);
$this->get('event_dispatcher')->dispatch($event, KernelEvents::EXCEPTION);
Expand Down Expand Up @@ -184,10 +184,8 @@ private function handleException(\Throwable $e, Request $request, $type): void

/**
* Execute kernel.response and kernel.finish_request events.
*
* @param int $type
*/
private function handleResponse(Request $request, Response $response, $type): void
private function handleResponse(Request $request, Response $response, int $type): void
{
$event = new ResponseEvent($this->get('http_kernel'), $request, $type, $response);

Expand Down
5 changes: 1 addition & 4 deletions core-bundle/src/DataContainer/PaletteManipulator.php
Expand Up @@ -105,10 +105,7 @@ public function removeField($name, string $legend = null): self
return $this;
}

/**
* @param string $name
*/
public function applyToPalette($name, string $table): self
public function applyToPalette(string $name, string $table): self
{
$palettes = &$GLOBALS['TL_DCA'][$table]['palettes'];

Expand Down
1 change: 0 additions & 1 deletion core-bundle/src/Image/ImageFactory.php
Expand Up @@ -149,7 +149,6 @@ public function create($path, $size = null, $options = null): ImageInterface
$targetPath = $options instanceof ResizeOptions ? $options->getTargetPath() : $options;

if ($size instanceof ResizeConfiguration) {
/** @var ResizeConfiguration $resizeConfig */
$resizeConfig = $size;
$importantPart = null;
} else {
Expand Down
1 change: 0 additions & 1 deletion core-bundle/src/Image/PictureFactory.php
Expand Up @@ -208,7 +208,6 @@ static function ($formatsString) {
if (null !== $imageSizeItems) {
$configItems = [];

/** @var ImageSizeItemModel $imageSizeItem */
foreach ($imageSizeItems as $imageSizeItem) {
$configItems[] = $this->createConfigItem($imageSizeItem->row());
}
Expand Down
1 change: 0 additions & 1 deletion core-bundle/src/Resources/contao/classes/StyleSheets.php
Expand Up @@ -1069,7 +1069,6 @@ public function importStyleSheet()
return '';
}

/** @var FileUpload $objUploader */
$objUploader = new FileUpload();

// Import CSS
Expand Down
1 change: 0 additions & 1 deletion core-bundle/src/Resources/contao/classes/Theme.php
Expand Up @@ -42,7 +42,6 @@ public function __construct()
*/
public function importTheme()
{
/** @var FileUpload $objUploader */
$objUploader = new FileUpload();

if (Input::post('FORM_SUBMIT') == 'tl_theme_import')
Expand Down
Expand Up @@ -1067,7 +1067,6 @@ public static function generateMargin($arrValues, $strType='margin')
*/
public static function addToUrl($strRequest, $blnAddRef=true, $arrUnset=array())
{
/** @var Query $query */
$query = new Query(Environment::get('queryString'));

// Remove the request token and referer ID
Expand Down
1 change: 0 additions & 1 deletion core-bundle/src/Resources/contao/library/Contao/Image.php
Expand Up @@ -759,7 +759,6 @@ public static function create($image, $size=null)
$image = new File(rawurldecode($image));
}

/** @var Image $imageObj */
$imageObj = new static($image);

if (\is_array($size) && !empty($size[2]))
Expand Down
1 change: 0 additions & 1 deletion core-bundle/src/Resources/contao/library/Contao/System.php
Expand Up @@ -395,7 +395,6 @@ public static function getReferer($blnEncodeAmpersands=false, $strTable=null)

list($path, $query) = explode('?', $url, 2);

/** @var Query $queryObj */
$queryObj = new Query($query);
$queryObj = $queryObj->withoutPairs($params);

Expand Down
17 changes: 12 additions & 5 deletions core-bundle/src/Translation/DataCollectorTranslator.php
Expand Up @@ -14,24 +14,27 @@

use Symfony\Component\Translation\DataCollectorTranslator as SymfonyDataCollectorTranslator;
use Symfony\Component\Translation\MessageCatalogueInterface;
use Symfony\Component\Translation\TranslatorBagInterface;
use Symfony\Contracts\Service\ResetInterface;
use Symfony\Contracts\Translation\LocaleAwareInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* @internal
*/
class DataCollectorTranslator extends SymfonyDataCollectorTranslator implements ResetInterface
{
/**
* @var SymfonyDataCollectorTranslator
* @var TranslatorInterface|TranslatorBagInterface|LocaleAwareInterface
*/
private $translator;

private $messages = [];

/**
* @param SymfonyDataCollectorTranslator $translator
* @var array
*/
public function __construct($translator)
private $messages = [];

public function __construct(TranslatorInterface $translator)
{
parent::__construct($translator);

Expand Down Expand Up @@ -60,6 +63,10 @@ public function trans($id, array $parameters = [], $domain = null, $locale = nul

public function transChoice($id, $number, array $parameters = [], $domain = null, $locale = null): string
{
if (!method_exists($this->translator, 'transChoice')) {
return $this->trans($id, $parameters, $domain, $locale);
}

return $this->translator->transChoice($id, $number, $parameters, $domain, $locale);
}

Expand Down
25 changes: 10 additions & 15 deletions core-bundle/tests/Contao/SearchTest.php
Expand Up @@ -25,12 +25,9 @@
class SearchTest extends TestCase
{
/**
* @param string $moreCanonicalUrl
* @param string $lessCanonicalUrl
*
* @dataProvider compareUrlsProvider
*/
public function testCompareUrls($moreCanonicalUrl, $lessCanonicalUrl): void
public function testCompareUrls(string $moreCanonicalUrl, string $lessCanonicalUrl): void
{
$search = new \ReflectionClass(Search::class);
$compareUrls = $search->getMethod('compareUrls');
Expand All @@ -42,17 +39,15 @@ public function testCompareUrls($moreCanonicalUrl, $lessCanonicalUrl): void
$this->assertSame(0, $compareUrls->invokeArgs(null, [$lessCanonicalUrl, $lessCanonicalUrl]));
}

public function compareUrlsProvider(): array
public function compareUrlsProvider(): \Generator
{
return [
['foo/bar.html', 'foo/bar.html?query'],
['foo/bar.html', 'foo/bar/baz.html'],
['foo/bar.html', 'foo/bar-baz.html'],
['foo/bar.html', 'foo/barr.html'],
['foo/bar.html', 'foo/baz.html'],
['foo/bar-longer-url-but-no-query.html', 'foo/bar.html?query'],
['foo/bar-longer-url-but-less-slashes.html', 'foo/bar/baz.html'],
['foo.html?query/with/many/slashes/', 'foo/bar.html?query-without-slashes'],
];
yield ['foo/bar.html', 'foo/bar.html?query'];
yield ['foo/bar.html', 'foo/bar/baz.html'];
yield ['foo/bar.html', 'foo/bar-baz.html'];
yield ['foo/bar.html', 'foo/barr.html'];
yield ['foo/bar.html', 'foo/baz.html'];
yield ['foo/bar-longer-url-but-no-query.html', 'foo/bar.html?query'];
yield ['foo/bar-longer-url-but-less-slashes.html', 'foo/bar/baz.html'];
yield ['foo.html?query/with/many/slashes/', 'foo/bar.html?query-without-slashes'];
}
}
3 changes: 0 additions & 3 deletions core-bundle/tests/Framework/ContaoFrameworkTest.php
Expand Up @@ -496,7 +496,6 @@ public function testRegistersTheLazySessionAccessObject(): void

public function testCreatesAnObjectInstance(): void
{
/** @var ContaoFramework $framework */
$framework = $this->mockFramework();

$class = LegacyClass::class;
Expand All @@ -508,7 +507,6 @@ public function testCreatesAnObjectInstance(): void

public function testCreateASingeltonObjectInstance(): void
{
/** @var ContaoFramework $framework */
$framework = $this->mockFramework();

$class = LegacySingletonClass::class;
Expand All @@ -520,7 +518,6 @@ public function testCreateASingeltonObjectInstance(): void

public function testCreatesAdaptersForLegacyClasses(): void
{
/** @var ContaoFramework $framework */
$framework = $this->mockFramework();
$adapter = $framework->getAdapter(LegacyClass::class);

Expand Down
15 changes: 0 additions & 15 deletions core-bundle/tests/Functional/RoutingTest.php
Expand Up @@ -19,7 +19,6 @@
use Contao\System;
use Contao\TestCase\ContaoDatabaseTrait;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Response;

class RoutingTest extends WebTestCase
{
Expand Down Expand Up @@ -65,8 +64,6 @@ public function testResolvesAliases(string $request, int $statusCode, string $pa

$crawler = $client->request('GET', $request);
$title = trim($crawler->filterXPath('//head/title')->text());

/** @var Response $response */
$response = $client->getResponse();

$this->assertSame($statusCode, $response->getStatusCode());
Expand Down Expand Up @@ -325,8 +322,6 @@ public function testResolvesAliasesWithLocale(string $request, int $statusCode,

$crawler = $client->request('GET', $request);
$title = trim($crawler->filterXPath('//head/title')->text());

/** @var Response $response */
$response = $client->getResponse();

$this->assertSame($statusCode, $response->getStatusCode());
Expand Down Expand Up @@ -574,8 +569,6 @@ public function testResolvesAliasesWithoutUrlSuffix(string $request, int $status

$crawler = $client->request('GET', $request);
$title = trim($crawler->filterXPath('//head/title')->text());

/** @var Response $response */
$response = $client->getResponse();

$this->assertSame($statusCode, $response->getStatusCode());
Expand Down Expand Up @@ -790,8 +783,6 @@ public function testResolvesTheRootPage(string $request, int $statusCode, string

$crawler = $client->request('GET', $request);
$title = trim($crawler->filterXPath('//head/title')->text());

/** @var Response $response */
$response = $client->getResponse();

$this->assertSame($statusCode, $response->getStatusCode());
Expand Down Expand Up @@ -881,8 +872,6 @@ public function testResolvesTheRootPageWithLocale(string $request, int $statusCo

$crawler = $client->request('GET', $request);
$title = trim($crawler->filterXPath('//head/title')->text());

/** @var Response $response */
$response = $client->getResponse();

$this->assertSame($statusCode, $response->getStatusCode());
Expand Down Expand Up @@ -1009,8 +998,6 @@ public function testOrdersThePageModelsByCandidates(): void

$crawler = $client->request('GET', '/main/sub-zh.html');
$title = trim($crawler->filterXPath('//head/title')->text());

/** @var Response $response */
$response = $client->getResponse();

$this->assertSame(200, $response->getStatusCode());
Expand All @@ -1035,8 +1022,6 @@ public function testCorrectPageForUnknownLanguage(): void

$crawler = $client->request('GET', $request);
$title = trim($crawler->filterXPath('//head/title')->text());

/** @var Response $response */
$response = $client->getResponse();

$this->assertSame(200, $response->getStatusCode());
Expand Down
1 change: 0 additions & 1 deletion manager-bundle/src/HttpKernel/JwtManager.php
Expand Up @@ -141,7 +141,6 @@ public function parseCookie(string $data): ?array
*/
private function hasCookie(Response $response): bool
{
/** @var array<Cookie> $cookies */
$cookies = $response->headers->getCookies();

foreach ($cookies as $cookie) {
Expand Down
2 changes: 0 additions & 2 deletions manager-bundle/tests/ContaoManager/PluginTest.php
Expand Up @@ -271,8 +271,6 @@ static function (string $file): RouteCollection {

$plugin = new Plugin();
$collection = $plugin->getRouteCollection($resolver, $kernel);

/** @var array<Route> $routes */
$routes = array_values($collection->all());

$this->assertCount(3, $routes);
Expand Down
Expand Up @@ -427,7 +427,6 @@ public function importRecipients()
return '';
}

/** @var FileUpload $objUploader */
$objUploader = new FileUpload();

// Import recipients
Expand Down
Expand Up @@ -100,7 +100,6 @@ protected function compile()
'eval' => array('mandatory'=>true)
);

/** @var Widget $objWidget */
$objWidget = new FormCaptcha(FormCaptcha::getAttributesFromDca($arrField, $arrField['name']));
}

Expand Down
Expand Up @@ -90,7 +90,6 @@ protected function compile()
'eval' => array('mandatory'=>true)
);

/** @var Widget $objWidget */
$objWidget = new FormCaptcha(FormCaptcha::getAttributesFromDca($arrField, $arrField['name']));
}

Expand Down

0 comments on commit 7db3c54

Please sign in to comment.