Skip to content

Commit fb7960e

Browse files
committed
Fix PHPStan errors
1 parent 309e63f commit fb7960e

30 files changed

+78
-41
lines changed

phpstan.neon

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ parameters:
2222
objectManagerLoader: tests/PHPStan/object_manager.php
2323

2424
reportUnmatchedIgnoredErrors: false
25-
treatPhpDocTypesAsCertain: false
25+
treatPhpDocTypesAsCertain: true
2626

2727
ignoreErrors:
2828
-
@@ -31,6 +31,7 @@ parameters:
3131
- doctrine.associationType
3232
- doctrine.columnType
3333
- missingType.generics
34+
- missingType.parameter
3435
-
3536
identifier: class.notFound
3637
message: '#League\\Flysystem\\#'

src/Controller/Action/Shop/ShowFeedAction.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@ public function __invoke(string $code): StreamedResponse
6868
}
6969
}
7070

71-
/** @var resource|false $stream */
7271
$stream = $filesystem->readStream((string) $feedPath);
73-
if (false === $stream) {
72+
if (!\is_resource($stream)) {
7473
throw new RuntimeException(sprintf('An error occurred trying to read the feed file %s', $feedPath));
7574
}
7675

src/DataProvider/DataProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class DataProvider implements DataProviderInterface
2323
/** @var CollectionBatcherInterface[] */
2424
private array $batchers = [];
2525

26+
/**
27+
* @param class-string $class
28+
*/
2629
public function __construct(
2730
private readonly BatcherFactoryInterface $batcherFactory,
2831
private readonly QueryRebuilderInterface $queryRebuilder,
@@ -53,6 +56,7 @@ public function getBatchCount(ChannelInterface $channel, LocaleInterface $locale
5356

5457
public function getItems(BatchInterface $batch): iterable
5558
{
59+
/** @phpstan-ignore return.type */
5660
return $this->queryRebuilder->rebuild($batch)->getResult();
5761
}
5862

src/DataProvider/DataProviderInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ interface DataProviderInterface
1414
{
1515
/**
1616
* This will be the root class of the data provided by this data provider
17+
*
18+
* @return class-string
1719
*/
1820
public function getClass(): string;
1921

src/DependencyInjection/Compiler/RegisterFilesystemPass.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public function process(ContainerBuilder $container): void
3333

3434
foreach (self::PARAMETERS as $parameter) {
3535
$parameterValue = $container->getParameter($parameter);
36+
Assert::string($parameterValue);
37+
3638
if (!$container->hasDefinition($parameterValue)) {
3739
throw new InvalidArgumentException(sprintf('No service definition exists with id "%s"', $parameterValue));
3840
}

src/DependencyInjection/Compiler/ValidateDataProvidersPass.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function process(ContainerBuilder $container): void
2323
throw new InvalidArgumentException(sprintf('The service %s needs the code attribute. Something like this: <tag name="setono_sylius_feed.data_provider" code="insert code here"/>', $id));
2424
}
2525

26+
/** @var array{code?: string} $attributes */
2627
foreach ($tagged as $attributes) {
2728
if (!isset($attributes['code'])) {
2829
throw new InvalidArgumentException(sprintf('The service %s needs the code attribute. Something like this: <tag name="setono_sylius_feed.data_provider" code="insert code here"/>', $id));

src/DependencyInjection/SetonoSyliusFeedExtension.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ final class SetonoSyliusFeedExtension extends AbstractResourceExtension implemen
1818
{
1919
public function load(array $configs, ContainerBuilder $container): void
2020
{
21+
/**
22+
* @var array{
23+
* driver: string,
24+
* storage: array{feed: string, feed_tmp: string},
25+
* resources: array
26+
* } $config
27+
*/
2128
$config = $this->processConfiguration($this->getConfiguration([], $container), $configs);
2229
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
2330

src/Doctrine/ORM/FeedRepository.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ class FeedRepository extends EntityRepository implements FeedRepositoryInterface
1313
{
1414
public function findOneByCode(string $code): ?FeedInterface
1515
{
16-
return $this->createQueryBuilder('o')
16+
$result = $this->createQueryBuilder('o')
1717
->where('o.code = :code')
1818
->setParameter('code', $code)
1919
->getQuery()
2020
->getOneOrNullResult()
2121
;
22+
23+
Assert::nullOrIsInstanceOf($result, FeedInterface::class);
24+
25+
return $result;
2226
}
2327

2428
public function findEnabled(): array
@@ -29,6 +33,7 @@ public function findEnabled(): array
2933
->getResult()
3034
;
3135

36+
Assert::isArray($res);
3237
Assert::allIsInstanceOf($res, FeedInterface::class);
3338

3439
return $res;

src/Doctrine/ORM/ViolationRepository.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ public function findCountsGroupedBySeverity($feed = null): array
1919
$feed = (int) $feed->getId();
2020
}
2121

22-
Assert::nullOrInteger($feed);
23-
2422
$qb = $this->createQueryBuilder('o')
2523
->select('NEW Setono\SyliusFeedPlugin\DTO\SeverityCount(o.severity, count(o))')
2624
->groupBy('o.severity')
@@ -32,6 +30,7 @@ public function findCountsGroupedBySeverity($feed = null): array
3230
}
3331

3432
$res = $qb->getQuery()->getResult();
33+
Assert::isArray($res);
3534
Assert::allIsInstanceOf($res, SeverityCount::class);
3635

3736
return $res;

src/EventListener/Filter/AbstractFilterListener.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ public function __construct(private readonly string $class)
1515
{
1616
}
1717

18+
/**
19+
* @param list<class-string> $additionalInstanceChecks
20+
*/
1821
protected function isEligible(QueryBuilderEvent $event, array $additionalInstanceChecks = []): bool
1922
{
2023
$class = $event->getDataProvider()->getClass();
@@ -39,7 +42,7 @@ protected function getAlias(QueryBuilder $queryBuilder): string
3942
throw new InvalidArgumentException('This filter only works with one root alias');
4043
}
4144

42-
return reset($aliases);
45+
return $aliases[0];
4346
}
4447

4548
protected function getClassMetadata(QueryBuilderEvent $event): ClassMetadata

0 commit comments

Comments
 (0)