minor #15018 Upgrade PHPStan to level 4 (lruozzi9)

This PR was merged into the 1.12 branch.

Discussion
----------

| Q               | A                                                            |
|-----------------|--------------------------------------------------------------|
| Branch?         | 1.12                  |
| Bug fix?        | no                                                      |
| New feature?    | no                                                      |
| BC breaks?      | no                                                      |
| Deprecations?   | no |
| Related tickets | partially #14019                      |
| License         | MIT                                                          |


Commits
-------

4bc2aa7c01 [PHPStan] Bump to level 4 (#14019)
ac1b7f69f2 [PHPStan] Ignore properties not used to avoid BC (#14019)
b26c4ba3d1 [PHPStan] Fix static errors (#14019)
d1f4aa6fa1 [PHPStan] Maybe we can not trust the Symfony docblock in method (#14019)

We chose to maintain this condition to avoid potential errors
720fb4e1ba [PHPStan] Maybe the priority is not given in the configuration parameter (#14019)

We chose to maintain this condition to avoid potential errors
e97d93bb0b Improve solutions fixing errors reported by PHPStan level 4
This commit is contained in:
Rafał Jaskulski 2023-05-11 16:26:40 +02:00 committed by GitHub
commit 7c3f05265f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 22 additions and 47 deletions

View file

@ -6,7 +6,7 @@ includes:
- vendor/phpstan/phpstan-symfony/rules.neon
parameters:
level: 3
level: 4
reportUnmatchedIgnoredErrors: false

View file

@ -31,7 +31,7 @@ final class DashboardController
private ChannelRepositoryInterface $channelRepository,
private Environment $templatingEngine,
private RouterInterface $router,
private ?SalesDataProviderInterface $salesDataProvider = null,
private ?SalesDataProviderInterface $salesDataProvider = null, /** @phpstan-ignore-line */
private ?StatisticsDataProviderInterface $statisticsDataProvider = null,
) {
}

View file

@ -31,7 +31,7 @@ final class CommandArgumentsDenormalizer implements ContextAwareDenormalizerInte
public function supportsDenormalization($data, $type, $format = null, array $context = []): bool
{
/** @psalm-var class-string $inputClassName|null */
/** @psalm-var class-string|null $inputClassName */
$inputClassName = $this->getInputClassName($context);
if ($inputClassName === null) {

View file

@ -25,13 +25,7 @@ final class ShowAvailablePluginsCommand extends Command
{
protected static $defaultName = 'sylius:show-available-plugins';
/**
* @var iterable<PluginInfo>
*
* @phpstan-var ArrayCollection<PluginInfo>
*
* @psalm-var ArrayCollection<array-key, PluginInfo>
*/
/** @var ArrayCollection<array-key, PluginInfo> */
private Collection $plugins;
protected function configure(): void
@ -58,7 +52,6 @@ final class ShowAvailablePluginsCommand extends Command
private function configurePlugins(): void
{
/** @var ArrayCollection<array-key, PluginInfo> $this->plugins */
$this->plugins = new ArrayCollection();
$this->plugins->add(new PluginInfo('<info>Admin Order Creation</info>', 'Creating (and copying) orders in the administration panel.', 'https://github.com/Sylius/AdminOrderCreationPlugin'));

View file

@ -13,6 +13,7 @@ declare(strict_types=1);
namespace Sylius\Bundle\CoreBundle\DependencyInjection;
use InvalidArgumentException;
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
use Sylius\Component\Core\Filesystem\Adapter\FilesystemAdapterInterface;
use Sylius\Component\Core\Filesystem\Adapter\FlysystemFilesystemAdapter;
@ -80,6 +81,10 @@ final class SyliusCoreExtension extends AbstractResourceExtension implements Pre
match ($config['filesystem']['adapter']) {
'default', 'flysystem' => FlysystemFilesystemAdapter::class,
'gaufrette' => 'Sylius\Component\Core\Filesystem\Adapter\GaufretteFilesystemAdapter',
default => throw new InvalidArgumentException(sprintf(
'Invalid filesystem adapter "%s" provided.',
$config['filesystem']['adapter']
)),
},
);
}

View file

@ -41,10 +41,6 @@ final class LazyOption
return function (Options $options) use ($repository, $criteria): object {
$objects = $repository->findBy($criteria);
if ($objects instanceof Collection) {
$objects = $objects->toArray();
}
Assert::notEmpty($objects, 'No entities found of type ' . $repository->getClassName());
return $objects[array_rand($objects)];
@ -63,10 +59,6 @@ final class LazyOption
$objects = $repository->findBy($criteria);
if ($objects instanceof Collection) {
$objects = $objects->toArray();
}
return 0 === count($objects) ? null : $objects[array_rand($objects)];
};
}
@ -76,10 +68,6 @@ final class LazyOption
return function (Options $options) use ($repository, $amount, $criteria): iterable {
$objects = $repository->findBy($criteria);
if ($objects instanceof Collection) {
$objects = $objects->toArray();
}
$selectedObjects = [];
for (; $amount > 0 && count($objects) > 0; --$amount) {
$randomKey = array_rand($objects);

View file

@ -61,7 +61,7 @@ final class LocaleTypeExtension extends AbstractTypeExtension
return [LocaleType::class];
}
private function getLocaleName(string $code): ?string
private function getLocaleName(string $code): string
{
return Locales::getName($code);
}

View file

@ -47,8 +47,10 @@ final class PaymentMethodTypeExtension extends AbstractTypeExtension
}
$gatewayConfig = $paymentMethod->getGatewayConfig();
/** @psalm-suppress DocblockTypeContradiction */
if (null === $gatewayConfig->getGatewayName() && null !== $paymentMethod->getCode()) {
/** @var string|null $gatewayName */
$gatewayName = $gatewayConfig->getGatewayName();
if (null === $gatewayName && null !== $paymentMethod->getCode()) {
$gatewayConfig->setGatewayName(StringInflector::nameToLowercaseCode($paymentMethod->getCode()));
}
})

View file

@ -43,7 +43,7 @@ final class PayumController
private OrderRepositoryInterface $orderRepository,
private MetadataInterface $orderMetadata,
private RequestConfigurationFactoryInterface $requestConfigurationFactory,
private ViewHandlerInterface $viewHandler,
private ViewHandlerInterface $viewHandler, /** @phpstan-ignore-line */
private RouterInterface $router,
private GetStatusFactoryInterface $getStatusRequestFactory,
private ResolveNextRouteFactoryInterface $resolveNextRouteRequestFactory,

View file

@ -57,8 +57,7 @@ final class NonChannelLocaleListener
}
$request = $event->getRequest();
/** @psalm-suppress RedundantConditionGivenDocblockType Symfony docblock is not always true */
if ($request->attributes && in_array($request->attributes->get('_route'), ['_wdt', '_profiler', '_profiler_search', '_profiler_search_results'])) {
if (in_array($request->attributes->get('_route'), ['_wdt', '_profiler', '_profiler_search', '_profiler_search_results'])) {
return;
}

View file

@ -32,24 +32,12 @@ final class UserCartRecalculationListener
) {
}
/**
* @param InteractiveLoginEvent|UserEvent $event
*/
public function recalculateCartWhileLogin(object $event): void
public function recalculateCartWhileLogin(InteractiveLoginEvent|UserEvent $event): void
{
if (!$this->uriBasedSectionContext->getSection() instanceof ShopSection) {
return;
}
/** @psalm-suppress DocblockTypeContradiction */
if (!$event instanceof InteractiveLoginEvent && !$event instanceof UserEvent) {
throw new \TypeError(sprintf(
'$event needs to be an instance of "%s" or "%s"',
InteractiveLoginEvent::class,
UserEvent::class,
));
}
try {
$cart = $this->cartContext->getCart();
} catch (CartNotFoundException) {

View file

@ -40,7 +40,7 @@ final class SyliusUiExtension extends Extension implements PrependExtensionInter
}
/**
* @psalm-param array<string, array{blocks: array<string, array{template: string, context: array, priority: int, enabled: bool}>}> $eventsConfig
* @psalm-param array<string, array{blocks: array<string, array{template: string, context: array, priority?: int, enabled: bool}>}> $eventsConfig
*/
private function loadEvents(array $eventsConfig, ContainerBuilder $container): void
{

View file

@ -49,11 +49,11 @@ class ExchangeRate implements ExchangeRateInterface
{
/**
* It looks like Doctrine is hydrating decimal field as string, force casting to float.
*
* @psalm-suppress DocblockTypeContradiction
* @psalm-suppress RedundantConditionGivenDocblockType
* @var float|string|null $ratio
*/
return is_string($this->ratio) ? (float) $this->ratio : $this->ratio;
$ratio = $this->ratio;
return is_string($ratio) ? (float) $ratio : $ratio;
}
/**