Skip to content

Commit 3ea7dc1

Browse files
authored
Merge pull request #107 from Setono/phpstan
Fix some PHPStan errors
2 parents 309e63f + 684cb42 commit 3ea7dc1

31 files changed

+148
-41
lines changed

phpstan-baseline.neon

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: '#^Interface IteratorAggregate specifies template type TKey of interface Traversable as mixed but it''s already specified as \(int\|string\)\.$#'
5+
identifier: generics.interfaceConflict
6+
count: 1
7+
path: src/FeedContext/ContextList.php
8+
9+
-
10+
message: '#^Parameter \#1 \$context of method Setono\\SyliusFeedPlugin\\FeedContext\\ContextList\:\:add\(\) expects array\|object, mixed given\.$#'
11+
identifier: argument.type
12+
count: 1
13+
path: src/FeedContext/ContextList.php
14+
15+
-
16+
message: '#^PHPDoc tag @var with type Sylius\\Component\\Core\\Model\\ProductTranslationInterface\|null is not subtype of native type Sylius\\Component\\Resource\\Model\\TranslationInterface\|null\.$#'
17+
identifier: varTag.nativeType
18+
count: 1
19+
path: src/FeedContext/Google/Shopping/ProductItemContext.php
20+
21+
-
22+
message: '#^PHPDoc tag @var with type Sylius\\Component\\Taxonomy\\Model\\TaxonTranslationInterface\|null is not subtype of native type Sylius\\Component\\Resource\\Model\\TranslationInterface\|null\.$#'
23+
identifier: varTag.nativeType
24+
count: 1
25+
path: src/FeedContext/Google/Shopping/ProductItemContext.php
26+
27+
-
28+
message: '#^Parameter \#1 \$callback of function array_map expects \(callable\(Sylius\\Component\\Taxonomy\\Model\\TaxonInterface\)\: mixed\)\|null, Closure\(Sylius\\Component\\Core\\Model\\TaxonInterface\)\: string given\.$#'
29+
identifier: argument.type
30+
count: 1
31+
path: src/FeedContext/Google/Shopping/ProductItemContext.php
32+
33+
-
34+
message: '#^Parameter \#1 \$price of method Setono\\SyliusFeedPlugin\\Feed\\Model\\Google\\Shopping\\Product\:\:setPrice\(\) expects Setono\\SyliusFeedPlugin\\Feed\\Model\\Google\\Shopping\\Price\|null, mixed given\.$#'
35+
identifier: argument.type
36+
count: 1
37+
path: src/FeedContext/Google/Shopping/ProductItemContext.php
38+
39+
-
40+
message: '#^Parameter \#1 \$salePrice of method Setono\\SyliusFeedPlugin\\Feed\\Model\\Google\\Shopping\\Product\:\:setSalePrice\(\) expects Setono\\SyliusFeedPlugin\\Feed\\Model\\Google\\Shopping\\Price\|null, mixed given\.$#'
41+
identifier: argument.type
42+
count: 1
43+
path: src/FeedContext/Google/Shopping/ProductItemContext.php
44+
45+
-
46+
message: '#^Parameter \#1 \$translatable of method Setono\\SyliusFeedPlugin\\FeedContext\\Google\\Shopping\\ProductItemContext\:\:getTranslation\(\) expects Sylius\\Component\\Resource\\Model\\TranslatableInterface, Sylius\\Component\\Core\\Model\\ProductInterface given\.$#'
47+
identifier: argument.type
48+
count: 1
49+
path: src/FeedContext/Google/Shopping/ProductItemContext.php
50+
51+
-
52+
message: '#^Parameter \#1 \$translatable of method Setono\\SyliusFeedPlugin\\FeedContext\\Google\\Shopping\\ProductItemContext\:\:getTranslation\(\) expects Sylius\\Component\\Resource\\Model\\TranslatableInterface, Sylius\\Component\\Core\\Model\\TaxonInterface given\.$#'
53+
identifier: argument.type
54+
count: 1
55+
path: src/FeedContext/Google/Shopping/ProductItemContext.php
56+
57+
-
58+
message: '#^Parameter \#2 \$currency of class Setono\\SyliusFeedPlugin\\Feed\\Model\\Google\\Shopping\\Price constructor expects string\|Stringable, Sylius\\Component\\Currency\\Model\\CurrencyInterface given\.$#'
59+
identifier: argument.type
60+
count: 1
61+
path: src/FeedContext/Google/Shopping/ProductItemContext.php
62+
63+
-
64+
message: '#^PHPDoc tag @var with type array\<array\{basename\: string, path\: string\}\>\|League\\Flysystem\\DirectoryListing\<League\\Flysystem\\StorageAttributes\> is not subtype of type League\\Flysystem\\DirectoryListing\<League\\Flysystem\\StorageAttributes\>\.$#'
65+
identifier: varTag.type
66+
count: 1
67+
path: src/Message/Handler/FinishGenerationHandler.php

phpstan.neon

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
includes:
2+
- phpstan-baseline.neon
3+
14
parameters:
25
level: max
36

@@ -22,7 +25,7 @@ parameters:
2225
objectManagerLoader: tests/PHPStan/object_manager.php
2326

2427
reportUnmatchedIgnoredErrors: false
25-
treatPhpDocTypesAsCertain: false
28+
treatPhpDocTypesAsCertain: true
2629

2730
ignoreErrors:
2831
-
@@ -31,6 +34,7 @@ parameters:
3134
- doctrine.associationType
3235
- doctrine.columnType
3336
- missingType.generics
37+
- missingType.parameter
3438
-
3539
identifier: class.notFound
3640
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;

0 commit comments

Comments
 (0)