Skip to content

Commit

Permalink
Fix issues detected by psalm
Browse files Browse the repository at this point in the history
  • Loading branch information
discordier committed Apr 29, 2024
1 parent ef43e7d commit f3a8cd5
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/ContaoDictionaryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function __construct(
$this->extractorFactory = $extractorFactory;
$this->mapBuilder = $mapBuilder;

if (empty($dictionaryMeta)) {
if ([] === $dictionaryMeta || null === $dictionaryMeta) {
$dictionaryMeta = [
'tl_page',
'tl_article',
Expand Down
8 changes: 6 additions & 2 deletions src/Extractor/AbstractSerializingCompoundExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ abstract class AbstractSerializingCompoundExtractor implements MultiStringExtrac
*
* @var array<string, ExtractorInterface>
*/
private $extractors = [];
private array $extractors = [];

/**
* @param string $colName The column name.
Expand Down Expand Up @@ -144,7 +144,11 @@ public function set(string $path, array &$row, ?string $value): void

switch (true) {
case $extractor instanceof MultiStringExtractorInterface:
$extractor->set($chunks[1], $content, $value);
$subKey = ($chunks[1] ?? '');
if ('' === $subKey) {
throw new InvalidArgumentException('Invalid path value');
}
$extractor->set($subKey, $content, $value);
break;
case $extractor instanceof StringExtractorInterface:
if (1 < count($chunks)) {
Expand Down
17 changes: 14 additions & 3 deletions src/Extractor/ArrayExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

use function array_key_exists;
use function array_slice;
use function assert;
use function explode;
use function get_class;
use function implode;
use function is_array;
use function is_string;

/**
* This extracts numerical indexed arrays of values.
Expand Down Expand Up @@ -100,12 +102,17 @@ public function get(string $path, array $row): ?string
/** @var mixed $content */
$content = $arrayContent[$chunks[0]];
$this->ensureArray($this->colName . '.' . $chunks[0], $content);

$extractor = $this->getExtractor($chunks[1]);
$extractorName = $chunks[1] ?? null;
assert(is_string($extractorName));
$extractor = $this->getExtractor($extractorName);

switch (true) {
case $extractor instanceof MultiStringExtractorInterface:
return $extractor->get($chunks[2], $content);
$subKey = ($chunks[2] ?? '');
if ('' === $subKey) {
throw new InvalidArgumentException('Invalid path value');
}
return $extractor->get($subKey, $content);
case $extractor instanceof StringExtractorInterface:
return $extractor->get($content);
default:
Expand All @@ -114,6 +121,10 @@ public function get(string $path, array $row): ?string
throw new InvalidArgumentException('Unknown extractor type ' . get_class($extractor));
}

/**
* @psalm-suppress UnsupportedPropertyReferenceUsage
* @psalm-suppress UnsupportedReferenceUsage
*/
public function set(string $path, array &$row, ?string $value): void
{
if (!$this->supports($row)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Extractor/TableExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function get(string $path, array $row): ?string
}
[$rowIndex, $colIndex] = $this->extractPath($path);

if ($value = ($content[$rowIndex][$colIndex] ?? null)) {
if ((bool) ($value = ($content[$rowIndex][$colIndex] ?? null))) {
return $value;
}

Expand Down
3 changes: 2 additions & 1 deletion src/Mapping/Terminal42ChangeLanguage/ContaoDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace CyberSpectrum\I18N\Contao\Mapping\Terminal42ChangeLanguage;

use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Query\QueryBuilder;
use Doctrine\DBAL\Result;
Expand Down Expand Up @@ -67,7 +68,7 @@ public function getPagesByPidList(array $pidList): array
->select('id', 'pid', 'languageMain', 'type')
->from('tl_page')
->where('pid IN (:lookupQueue)')
->setParameter('lookupQueue', $pidList, Connection::PARAM_INT_ARRAY)
->setParameter('lookupQueue', $pidList, ArrayParameterType::INTEGER)

Check failure on line 71 in src/Mapping/Terminal42ChangeLanguage/ContaoDatabase.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

UndefinedClass: Class, interface or enum named Doctrine\DBAL\ArrayParameterType does not exist (reported by psalm)

Check failure on line 71 in src/Mapping/Terminal42ChangeLanguage/ContaoDatabase.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

MixedArgument: Argument 3 of Doctrine\DBAL\Query\QueryBuilder::setParameter cannot be mixed, expecting Doctrine\DBAL\Types\Type|int|null|string (reported by psalm)

Check failure on line 71 in src/Mapping/Terminal42ChangeLanguage/ContaoDatabase.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

UndefinedClass: Class, interface or enum named Doctrine\DBAL\ArrayParameterType does not exist (reported by psalm)

Check failure on line 71 in src/Mapping/Terminal42ChangeLanguage/ContaoDatabase.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

MixedArgument: Argument 3 of Doctrine\DBAL\Query\QueryBuilder::setParameter cannot be mixed, expecting Doctrine\DBAL\Types\Type|int|null|string (reported by psalm)
->orderBy('sorting'));
$result = [];
while ($row = $rows->fetchAssociative()) {
Expand Down
4 changes: 2 additions & 2 deletions src/TranslationValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ public function getTarget(): ?string

public function isSourceEmpty(): bool
{
return empty($this->getSource());
return !(bool) $this->getSource();
}

public function isTargetEmpty(): bool
{
return empty($this->getTarget());
return !(bool) $this->getTarget();
}

/**
Expand Down

0 comments on commit f3a8cd5

Please sign in to comment.