Skip to content

Commit 8125862

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

File tree

10 files changed

+39
-16
lines changed

10 files changed

+39
-16
lines changed

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: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@
1717
use Setono\SyliusFeedPlugin\Event\QueryBuilderEvent;
1818
use Sylius\Component\Core\Model\ChannelInterface;
1919
use Sylius\Component\Locale\Model\LocaleInterface;
20+
use Sylius\Component\Resource\Model\ResourceInterface;
2021

2122
class DataProvider implements DataProviderInterface
2223
{
2324
/** @var CollectionBatcherInterface[] */
2425
private array $batchers = [];
2526

27+
/**
28+
* @param class-string $class
29+
*/
2630
public function __construct(
2731
private readonly BatcherFactoryInterface $batcherFactory,
2832
private readonly QueryRebuilderInterface $queryRebuilder,
@@ -53,7 +57,10 @@ public function getBatchCount(ChannelInterface $channel, LocaleInterface $locale
5357

5458
public function getItems(BatchInterface $batch): iterable
5559
{
56-
return $this->queryRebuilder->rebuild($batch)->getResult();
60+
/** @var list<ResourceInterface> $result */
61+
$result = $this->queryRebuilder->rebuild($batch)->getResult();
62+
63+
return $result;
5764
}
5865

5966
private function getQueryBuilder(ChannelInterface $channel, LocaleInterface $locale): QueryBuilder

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use InvalidArgumentException;
88
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
99
use Symfony\Component\DependencyInjection\ContainerBuilder;
10+
use Webmozart\Assert\Assert;
1011

1112
final class ValidateDataProvidersPass implements CompilerPassInterface
1213
{
@@ -23,12 +24,14 @@ public function process(ContainerBuilder $container): void
2324
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));
2425
}
2526

27+
/** @var array{code?: string} $attributes */
2628
foreach ($tagged as $attributes) {
2729
if (!isset($attributes['code'])) {
2830
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));
2931
}
3032

3133
$code = $attributes['code'];
34+
Assert::string($code);
3235

3336
if (isset($seen[$code])) {
3437
throw new InvalidArgumentException(sprintf('There is already a data provider with the given code, "%s"', $code));

src/DependencyInjection/SetonoSyliusFeedExtension.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,24 @@
1313
use Symfony\Component\DependencyInjection\ContainerBuilder;
1414
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
1515
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
16+
use Webmozart\Assert\Assert;
1617

1718
final class SetonoSyliusFeedExtension extends AbstractResourceExtension implements PrependExtensionInterface
1819
{
1920
public function load(array $configs, ContainerBuilder $container): void
2021
{
22+
/**
23+
* @var array{
24+
* driver: string,
25+
* storage: array{feed: string, feed_tmp: string},
26+
* resources: array
27+
* } $config
28+
*/
2129
$config = $this->processConfiguration($this->getConfiguration([], $container), $configs);
2230
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
2331

32+
Assert::isArray($config['storage']);
33+
2434
$container->setParameter('setono_sylius_feed.storage.feed', $config['storage']['feed']);
2535
$container->setParameter('setono_sylius_feed.storage.feed_tmp', $config['storage']['feed_tmp']);
2636

src/Doctrine/ORM/FeedRepository.php

Lines changed: 5 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

src/EventListener/MoveGeneratedFeedSubscriber.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,8 @@ public function move(TransitionEvent $event): void
8787
);
8888
$temporaryFilesystem = $this->temporaryFilesystem;
8989
$temporaryPath = TemporaryFeedPathGenerator::getBaseFile($temporaryDir);
90-
/** @var resource|false $tempFile */
9190
$tempFile = $temporaryFilesystem->readStream((string) $temporaryPath);
92-
if (false === $tempFile) {
91+
if (!\is_resource($tempFile)) {
9392
throw new \RuntimeException(sprintf(
9493
'The file with path "%s" could not be found',
9594
$temporaryPath,

src/Exception/GenerateBatchException.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ final class GenerateBatchException extends RuntimeException implements Exception
1414

1515
private ?int $feedId = null;
1616

17-
/** @var mixed */
18-
private $resourceId;
17+
private mixed $resourceId;
1918

2019
private ?string $channelCode = null;
2120

@@ -40,18 +39,12 @@ public function setFeedId(int $feedId): void
4039
$this->updateMessage();
4140
}
4241

43-
/**
44-
* @return mixed
45-
*/
46-
public function getResourceId()
42+
public function getResourceId(): mixed
4743
{
4844
return $this->resourceId;
4945
}
5046

51-
/**
52-
* @param mixed $resourceId
53-
*/
54-
public function setResourceId($resourceId): void
47+
public function setResourceId(mixed $resourceId): void
5548
{
5649
Assert::scalar($resourceId);
5750

src/FeedType/FeedType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111

1212
final class FeedType implements FeedTypeInterface
1313
{
14+
/** @var list<string> */
1415
private readonly array $validationGroups;
1516

17+
/**
18+
* @param list<string> $validationGroups
19+
*/
1620
public function __construct(
1721
private readonly string $code,
1822
private readonly string $template,

src/FeedType/FeedTypeInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public function getItemContext(): ItemContextInterface;
2424

2525
/**
2626
* The validation groups used when validating each item
27+
*
28+
* @return list<string>
2729
*/
2830
public function getValidationGroups(): array;
2931
}

0 commit comments

Comments
 (0)