Skip to content

Commit

Permalink
Fix issues found by the PhpStorm code inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Dec 4, 2020
1 parent 80b6469 commit d6b22e4
Show file tree
Hide file tree
Showing 32 changed files with 73 additions and 109 deletions.
Expand Up @@ -19,7 +19,7 @@

class ContaoCalendarExtension extends Extension
{
public function load(array $mergedConfig, ContainerBuilder $container): void
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new YamlFileLoader(
$container,
Expand Down
Expand Up @@ -109,7 +109,6 @@ protected function compile()
}

throw new InternalServerErrorException('Invalid "jumpTo" value or target page not public');
break;

case 'article':
if (($article = ArticleModel::findByPk($objEvent->articleId)) && ($page = PageModel::findPublishedById($article->pid)))
Expand All @@ -118,7 +117,6 @@ protected function compile()
}

throw new InternalServerErrorException('Invalid "articleId" value or target page not public');
break;

case 'external':
if ($objEvent->url)
Expand All @@ -127,7 +125,6 @@ protected function compile()
}

throw new InternalServerErrorException('Empty target URL');
break;
}

// Overwrite the page title (see #2853, #4955 and #87)
Expand Down
4 changes: 2 additions & 2 deletions core-bundle/src/Command/MigrateCommand.php
Expand Up @@ -288,8 +288,8 @@ private function getCommandHashes(array $commands, bool $withDrops): array
if (!$withDrops) {
foreach ($commands as $hash => $command) {
if (
(0 === strncmp($command, 'DROP ', 5) && 0 !== strncmp($command, 'DROP INDEX', 10))
|| preg_match('/^ALTER TABLE [^ ]+ DROP /', $command, $matches)
preg_match('/^ALTER TABLE [^ ]+ DROP /', $command, $matches)
|| (0 === strncmp($command, 'DROP ', 5) && 0 !== strncmp($command, 'DROP INDEX', 10))
) {
unset($commands[$hash]);
}
Expand Down
4 changes: 2 additions & 2 deletions core-bundle/src/Config/Loader/PhpFileLoader.php
Expand Up @@ -19,9 +19,9 @@
*/
class PhpFileLoader extends Loader
{
public function load($file, $type = null): string
public function load($resource, $type = null): string
{
[$code, $namespace] = $this->parseFile((string) $file);
[$code, $namespace] = $this->parseFile((string) $resource);

$code = $this->stripLegacyCheck($code);

Expand Down
4 changes: 2 additions & 2 deletions core-bundle/src/Config/Loader/XliffFileLoader.php
Expand Up @@ -35,9 +35,9 @@ public function __construct(string $projectDir, bool $addToGlobals = false)
$this->addToGlobals = $addToGlobals;
}

public function load($file, $type = null): string
public function load($resource, $type = null): string
{
return $this->convertXlfToPhp((string) $file, $type ?: 'en');
return $this->convertXlfToPhp((string) $resource, $type ?: 'en');
}

public function supports($resource, $type = null): bool
Expand Down
8 changes: 4 additions & 4 deletions core-bundle/src/Crawl/Monolog/CrawlCsvLogHandler.php
Expand Up @@ -36,7 +36,7 @@ public function setFilterSource(string $filterSource): self
return $this;
}

protected function streamWrite($resource, array $record): void
protected function streamWrite($stream, array $record): void
{
if (!isset($record['context']['source'])) {
return;
Expand All @@ -49,11 +49,11 @@ protected function streamWrite($resource, array $record): void
/** @var CrawlUri $crawlUri */
$crawlUri = $record['context']['crawlUri'] ?? null;

$stat = fstat($resource);
$stat = fstat($stream);
$size = $stat['size'];

if (0 === $size) {
fputcsv($resource, [
fputcsv($stream, [
'Time',
'Source',
'URI',
Expand All @@ -74,6 +74,6 @@ protected function streamWrite($resource, array $record): void
preg_replace('/\r\n|\n|\r/', ' ', $record['message']),
];

fputcsv($resource, $columns);
fputcsv($stream, $columns);
}
}
3 changes: 1 addition & 2 deletions core-bundle/src/DataContainer/PaletteManipulator.php
Expand Up @@ -315,7 +315,6 @@ private function applyFieldToField(array &$config, array $action, bool $skipLege
$legend = $this->findLegendForField($config, $parent);

if (false !== $legend) {
$legend = (string) $legend;
$offset += array_search($parent, $config[$legend]['fields'], true);
array_splice($config[$legend]['fields'], $offset, 0, $action['fields']);

Expand Down Expand Up @@ -380,7 +379,7 @@ private function applyRemove(array &$config, array $remove): void
*
* @return string|false
*/
private function findLegendForField(array &$config, string $field)
private function findLegendForField(array $config, string $field)
{
foreach ($config as $legend => $group) {
if (\in_array($field, $group['fields'], true)) {
Expand Down
Expand Up @@ -76,7 +76,7 @@ protected function getListenerId(): string
return 'contao.security.authentication_listener';
}

protected function createEntryPoint($container, $id, $config, $defaultEntryPoint): string
protected function createEntryPoint($container, $id, $config, $defaultEntryPointId): string
{
return 'contao.security.entry_point';
}
Expand Down
8 changes: 4 additions & 4 deletions core-bundle/src/Doctrine/DBAL/Types/BinaryStringType.php
Expand Up @@ -22,13 +22,13 @@ class BinaryStringType extends Type
{
public const NAME = 'binary_string';

public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
if (!empty($fieldDeclaration['fixed'])) {
return $platform->getBinaryTypeDeclarationSQL($fieldDeclaration);
if (!empty($column['fixed'])) {
return $platform->getBinaryTypeDeclarationSQL($column);
}

return $platform->getBlobTypeDeclarationSQL($fieldDeclaration);
return $platform->getBlobTypeDeclarationSQL($column);
}

public function getName(): string
Expand Down
16 changes: 8 additions & 8 deletions core-bundle/src/Monolog/ContaoTableProcessor.php
Expand Up @@ -51,25 +51,25 @@ public function __construct(RequestStack $requestStack, TokenStorageInterface $t
*
* @return array<string,array<string,mixed>>
*/
public function __invoke(array $record): array
public function __invoke(array $records): array
{
if (!isset($record['context']['contao']) || !$record['context']['contao'] instanceof ContaoContext) {
return $record;
if (!isset($records['context']['contao']) || !$records['context']['contao'] instanceof ContaoContext) {
return $records;
}

$context = $record['context']['contao'];
$context = $records['context']['contao'];
$request = $this->requestStack->getCurrentRequest();
$level = $record['level'] ?? 0;
$level = $records['level'] ?? 0;

$this->updateAction($context, $level);
$this->updateBrowser($context, $request);
$this->updateUsername($context);
$this->updateSource($context, $request);

$record['extra']['contao'] = $context;
unset($record['context']['contao']);
$records['extra']['contao'] = $context;
unset($records['context']['contao']);

return $record;
return $records;
}

private function updateAction(ContaoContext $context, int $level): void
Expand Down
12 changes: 1 addition & 11 deletions core-bundle/src/Resources/contao/classes/BackendModule.php
Expand Up @@ -68,17 +68,7 @@ public function __set($strKey, $varValue)
*/
public function __get($strKey)
{
if (isset($this->arrData[$strKey]))
{
return $this->arrData[$strKey];
}

if ($this->objDc->$strKey !== null)
{
return $this->objDc->$strKey;
}

return parent::__get($strKey);
return $this->arrData[$strKey] ?? $this->objDc->$strKey ?? parent::__get($strKey);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion core-bundle/src/Resources/contao/dca/tl_page.php
Expand Up @@ -1174,7 +1174,7 @@ static function ($alias) use ($objPage, $aliasExists)
);

// Generate folder URL aliases (see #4933)
if (Contao\Config::get('folderUrl') && $objPage->folderUrl)
if ($objPage->folderUrl && Contao\Config::get('folderUrl'))
{
$varValue = $objPage->folderUrl . $varValue;
}
Expand Down
2 changes: 1 addition & 1 deletion core-bundle/src/Resources/contao/drivers/DC_Table.php
Expand Up @@ -3584,7 +3584,7 @@ protected function treeView()
}
elseif ($blnHasSorting)
{
$objRoot = $this->Database->prepare("SELECT pid, (SELECT sorting FROM " . $table . " WHERE " . $this->strTable . ".pid=" . $table . ".id) AS psort FROM " . $this->strTable . " WHERE " . implode(' AND ', $this->procedure) . " GROUP BY pid" . ($blnHasSorting ? " ORDER BY psort" : ""))
$objRoot = $this->Database->prepare("SELECT pid, (SELECT sorting FROM " . $table . " WHERE " . $this->strTable . ".pid=" . $table . ".id) AS psort FROM " . $this->strTable . " WHERE " . implode(' AND ', $this->procedure) . " GROUP BY pid ORDER BY psort")
->execute($this->values);
}
else
Expand Down
2 changes: 0 additions & 2 deletions core-bundle/src/Resources/contao/forms/FormTextArea.php
Expand Up @@ -143,11 +143,9 @@ public function __get($strKey)

case 'value':
return StringUtil::specialchars(str_replace('\n', "\n", $this->varValue));
break;

case 'rawValue':
return $this->varValue;
break;

default:
return parent::__get($strKey);
Expand Down
10 changes: 4 additions & 6 deletions core-bundle/src/Resources/contao/forms/FormTextField.php
Expand Up @@ -156,15 +156,13 @@ public function __get($strKey)
return $this->varValue;
}
}
elseif ($this->rgxp == 'email' || $this->rgxp == 'friendly')

if ($this->rgxp == 'email' || $this->rgxp == 'friendly')
{
return Idna::decodeEmail($this->varValue);
}
else
{
return $this->varValue;
}
break;

return $this->varValue;

case 'type':
if ($this->hideInput)
Expand Down
Expand Up @@ -1531,7 +1531,7 @@ public static function addImageToTemplate($objTemplate, $arrItem, $intMaxWidth=n
$objFile = null;
}

$imgSize = $objFile ? $objFile->imageSize : false;
$imgSize = $objFile->imageSize ?? false;
$size = StringUtil::deserialize($arrItem['size']);

if (is_numeric($size))
Expand Down
33 changes: 15 additions & 18 deletions core-bundle/src/Resources/contao/library/Contao/DcaExtractor.php
Expand Up @@ -551,28 +551,25 @@ protected function createExtract()
);

// Fields
if (!empty($fields))
{
$this->arrFields = array();
$this->arrOrderFields = array();
$this->arrFields = array();
$this->arrOrderFields = array();

foreach ($fields as $field=>$config)
foreach ($fields as $field=>$config)
{
if (isset($config['sql']))
{
if (isset($config['sql']))
{
$this->arrFields[$field] = $config['sql'];
}
$this->arrFields[$field] = $config['sql'];
}

// Only add order fields of binary fields (see #7785)
if (isset($config['inputType'], $config['eval']['orderField']) && $config['inputType'] == 'fileTree')
{
$this->arrOrderFields[] = $config['eval']['orderField'];
}
// Only add order fields of binary fields (see #7785)
if (isset($config['inputType'], $config['eval']['orderField']) && $config['inputType'] == 'fileTree')
{
$this->arrOrderFields[] = $config['eval']['orderField'];
}

if (isset($config['eval']['unique']) && $config['eval']['unique'])
{
$this->arrUniqueFields[] = $field;
}
if (isset($config['eval']['unique']) && $config['eval']['unique'])
{
$this->arrUniqueFields[] = $field;
}
}

Expand Down
1 change: 0 additions & 1 deletion core-bundle/src/Resources/contao/library/Contao/Email.php
Expand Up @@ -209,7 +209,6 @@ public function __set($strKey, $varValue)

default:
throw new \Exception(sprintf('Invalid argument "%s"', $strKey));
break;
}
}

Expand Down
Expand Up @@ -204,7 +204,6 @@ public function saveToFile($path)

default:
throw new \InvalidArgumentException('Image type "' . $extension . '" cannot be generated');
break;
}

return $this;
Expand Down
10 changes: 5 additions & 5 deletions core-bundle/src/Resources/contao/library/Contao/Input.php
Expand Up @@ -128,7 +128,7 @@ public static function post($strKey, $blnDecodeEntities=false)

if ($varValue === null)
{
return $varValue;
return null;
}

$varValue = static::decodeEntities($varValue);
Expand Down Expand Up @@ -169,7 +169,7 @@ public static function postHtml($strKey, $blnDecodeEntities=false)

if ($varValue === null)
{
return $varValue;
return null;
}

$varValue = static::decodeEntities($varValue);
Expand Down Expand Up @@ -209,7 +209,7 @@ public static function postRaw($strKey)

if ($varValue === null)
{
return $varValue;
return null;
}

$varValue = static::preserveBasicEntities($varValue);
Expand Down Expand Up @@ -243,7 +243,7 @@ public static function postUnsafeRaw($strKey)

if ($varValue === null)
{
return $varValue;
return null;
}

static::$arrCache[$strCacheKey][$strKey] = $varValue;
Expand Down Expand Up @@ -547,7 +547,7 @@ public static function xssClean($varValue, $blnStrictMode=false)
}

// Return if the value is not a string
if (\is_bool($varValue) || $varValue === null || is_numeric($varValue))
if (\is_bool($varValue) || is_numeric($varValue))
{
return $varValue;
}
Expand Down
Expand Up @@ -165,7 +165,6 @@ public function __set($strKey, $varValue)

default:
throw new \Exception(sprintf('Invalid argument "%s"', $strKey));
break;
}
}

Expand Down
Expand Up @@ -33,14 +33,14 @@ public function __construct(\Iterator $iterator)
/**
* Sort items ascending
*
* @param mixed $a The first SplFileInfo object
* @param mixed $b The second SplFileInfo object
* @param mixed $value1 The first SplFileInfo object
* @param mixed $value2 The second SplFileInfo object
*
* @return integer Negative value if $b is less than $a, positive value if $b is greater than $a or 0 if they are equal
*/
public function compare($a, $b)
public function compare($value1, $value2)
{
return strcmp($b->getRealpath(), $a->getRealpath());
return strcmp($value2->getRealpath(), $value1->getRealpath());
}
}

Expand Down

0 comments on commit d6b22e4

Please sign in to comment.