mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
minor #14491 Upgrade PHPStan to level 3 (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<!-- don't forget to update the UPGRADE-*.md file --> |
| Related tickets | partially #14019 |
| License | MIT |
Written during the journey to the SyliusCon, so lit 🔥 😆
Commits
-------
67004338e1 [PHPStan] Bump to level 3 (#14019)
This commit is contained in:
commit
cf8a0ecd26
36 changed files with 137 additions and 37 deletions
|
|
@ -6,7 +6,7 @@ includes:
|
||||||
- vendor/phpstan/phpstan-symfony/rules.neon
|
- vendor/phpstan/phpstan-symfony/rules.neon
|
||||||
|
|
||||||
parameters:
|
parameters:
|
||||||
level: 2
|
level: 3
|
||||||
|
|
||||||
reportUnmatchedIgnoredErrors: false
|
reportUnmatchedIgnoredErrors: false
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\RouterInterface;
|
use Symfony\Component\Routing\RouterInterface;
|
||||||
use Twig\Environment;
|
use Twig\Environment;
|
||||||
|
use Webmozart\Assert\Assert;
|
||||||
|
|
||||||
final class DashboardController
|
final class DashboardController
|
||||||
{
|
{
|
||||||
|
|
@ -71,9 +72,15 @@ final class DashboardController
|
||||||
private function findChannelByCodeOrFindFirst(?string $channelCode): ?ChannelInterface
|
private function findChannelByCodeOrFindFirst(?string $channelCode): ?ChannelInterface
|
||||||
{
|
{
|
||||||
if (null !== $channelCode) {
|
if (null !== $channelCode) {
|
||||||
return $this->channelRepository->findOneByCode($channelCode);
|
$channel = $this->channelRepository->findOneByCode($channelCode);
|
||||||
|
Assert::nullOrIsInstanceOf($channel, ChannelInterface::class);
|
||||||
|
|
||||||
|
return $channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->channelRepository->findOneBy([]);
|
$channel = $this->channelRepository->findOneBy([]);
|
||||||
|
Assert::nullOrIsInstanceOf($channel, ChannelInterface::class);
|
||||||
|
|
||||||
|
return $channel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,10 @@ final class LoggedInCustomerEmailAwareCommandDataTransformer implements CommandD
|
||||||
/** @var UserInterface|null $user */
|
/** @var UserInterface|null $user */
|
||||||
$user = $this->userContext->getUser();
|
$user = $this->userContext->getUser();
|
||||||
if ($user instanceof ShopUserInterface) {
|
if ($user instanceof ShopUserInterface) {
|
||||||
return $user->getCustomer();
|
$customer = $user->getCustomer();
|
||||||
|
Assert::nullOrIsInstanceOf($customer, CustomerInterface::class);
|
||||||
|
|
||||||
|
return $customer;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,10 @@ final class LoggedInCustomerEmailIfNotSetAwareCommandDataTransformer implements
|
||||||
/** @var UserInterface|null $user */
|
/** @var UserInterface|null $user */
|
||||||
$user = $this->userContext->getUser();
|
$user = $this->userContext->getUser();
|
||||||
if ($user instanceof ShopUserInterface) {
|
if ($user instanceof ShopUserInterface) {
|
||||||
return $user->getCustomer();
|
$customer = $user->getCustomer();
|
||||||
|
Assert::nullOrIsInstanceOf($customer, CustomerInterface::class);
|
||||||
|
|
||||||
|
return $customer;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ final class ShippingMethodNormalizer implements ContextAwareNormalizerInterface,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($filters['tokenValue']) || !isset($filters['shipmentId'])) {
|
if (!isset($filters['tokenValue']) || !isset($filters['shipmentId'])) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var ChannelInterface $channel */
|
/** @var ChannelInterface $channel */
|
||||||
|
|
|
||||||
|
|
@ -80,9 +80,7 @@ final class CountryTypeExtension extends AbstractTypeExtension
|
||||||
return Countries::getName($code);
|
return Countries::getName($code);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @return string[] */
|
||||||
* @return array|CountryInterface[]
|
|
||||||
*/
|
|
||||||
private function getAvailableCountries(): array
|
private function getAvailableCountries(): array
|
||||||
{
|
{
|
||||||
$availableCountries = Countries::getNames();
|
$availableCountries = Countries::getNames();
|
||||||
|
|
|
||||||
|
|
@ -66,9 +66,7 @@ final class LocaleTypeExtension extends AbstractTypeExtension
|
||||||
return Locales::getName($code);
|
return Locales::getName($code);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @return string[] */
|
||||||
* @return array|LocaleInterface[]
|
|
||||||
*/
|
|
||||||
private function getAvailableLocales(): array
|
private function getAvailableLocales(): array
|
||||||
{
|
{
|
||||||
$availableLocales = Locales::getNames();
|
$availableLocales = Locales::getNames();
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
use Webmozart\Assert\Assert;
|
||||||
|
|
||||||
final class DatabaseSetupCommandsProvider implements DatabaseSetupCommandsProviderInterface
|
final class DatabaseSetupCommandsProvider implements DatabaseSetupCommandsProviderInterface
|
||||||
{
|
{
|
||||||
|
|
@ -131,6 +132,9 @@ final class DatabaseSetupCommandsProvider implements DatabaseSetupCommandsProvid
|
||||||
|
|
||||||
private function getEntityManager(): EntityManagerInterface
|
private function getEntityManager(): EntityManagerInterface
|
||||||
{
|
{
|
||||||
return $this->doctrineRegistry->getManager();
|
$objectManager = $this->doctrineRegistry->getManager();
|
||||||
|
Assert::isInstanceOf($objectManager, EntityManagerInterface::class);
|
||||||
|
|
||||||
|
return $objectManager;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,10 @@ class UserProvider extends BaseUserProvider implements AccountConnectorInterface
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($oauth instanceof UserOAuthInterface) {
|
if ($oauth instanceof UserOAuthInterface) {
|
||||||
return $oauth->getUser();
|
$user = $oauth->getUser();
|
||||||
|
Assert::isInstanceOf($user, UserInterface::class);
|
||||||
|
|
||||||
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null !== $response->getEmail()) {
|
if (null !== $response->getEmail()) {
|
||||||
|
|
@ -79,6 +82,8 @@ class UserProvider extends BaseUserProvider implements AccountConnectorInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @return SyliusUserInterface&UserInterface
|
||||||
|
*
|
||||||
* Ad-hoc creation of user.
|
* Ad-hoc creation of user.
|
||||||
*/
|
*/
|
||||||
private function createUserByOAuthUserResponse(UserResponseInterface $response): SyliusUserInterface
|
private function createUserByOAuthUserResponse(UserResponseInterface $response): SyliusUserInterface
|
||||||
|
|
@ -128,11 +133,14 @@ class UserProvider extends BaseUserProvider implements AccountConnectorInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @return SyliusUserInterface&UserInterface
|
||||||
|
*
|
||||||
* Attach OAuth sign-in provider account to existing user.
|
* Attach OAuth sign-in provider account to existing user.
|
||||||
*/
|
*/
|
||||||
private function updateUserByOAuthUserResponse(UserInterface $user, UserResponseInterface $response): SyliusUserInterface
|
private function updateUserByOAuthUserResponse(UserInterface $user, UserResponseInterface $response): SyliusUserInterface
|
||||||
{
|
{
|
||||||
/** @var SyliusUserInterface $user */
|
/** @var SyliusUserInterface $user */
|
||||||
|
Assert::isInstanceOf($user, UserInterface::class);
|
||||||
Assert::isInstanceOf($user, SyliusUserInterface::class);
|
Assert::isInstanceOf($user, SyliusUserInterface::class);
|
||||||
|
|
||||||
/** @var UserOAuthInterface $oauth */
|
/** @var UserOAuthInterface $oauth */
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ namespace Sylius\Bundle\CoreBundle\Provider;
|
||||||
use Symfony\Component\HttpFoundation\RequestStack;
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
|
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
|
||||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||||
|
use Webmozart\Assert\Assert;
|
||||||
|
|
||||||
final class FlashBagProvider
|
final class FlashBagProvider
|
||||||
{
|
{
|
||||||
|
|
@ -27,9 +28,15 @@ final class FlashBagProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($requestStackSessionOrFlashBag instanceof SessionInterface) {
|
if ($requestStackSessionOrFlashBag instanceof SessionInterface) {
|
||||||
return $requestStackSessionOrFlashBag->getBag('flashes');
|
$flashBag = $requestStackSessionOrFlashBag->getBag('flashes');
|
||||||
|
Assert::isInstanceOf($flashBag, FlashBagInterface::class);
|
||||||
|
|
||||||
|
return $flashBag;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $requestStackSessionOrFlashBag->getSession()->getBag('flashes');
|
$flashBag = $requestStackSessionOrFlashBag->getSession()->getBag('flashes');
|
||||||
|
Assert::isInstanceOf($flashBag, FlashBagInterface::class);
|
||||||
|
|
||||||
|
return $flashBag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ class GetStatus extends BaseGetStatus
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @psalm-suppress NonInvariantDocblockPropertyType
|
* @psalm-suppress NonInvariantDocblockPropertyType
|
||||||
|
* @phpstan-ignore-next-line
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -59,9 +59,15 @@ final class GenerateProductVariantsSubscriber implements EventSubscriberInterfac
|
||||||
private function getFlashBag(): FlashBagInterface
|
private function getFlashBag(): FlashBagInterface
|
||||||
{
|
{
|
||||||
if ($this->requestStackOrSession instanceof RequestStack) {
|
if ($this->requestStackOrSession instanceof RequestStack) {
|
||||||
return $this->requestStackOrSession->getSession()->getBag('flashes');
|
$flashBag = $this->requestStackOrSession->getSession()->getBag('flashes');
|
||||||
|
Assert::isInstanceOf($flashBag, FlashBagInterface::class);
|
||||||
|
|
||||||
|
return $flashBag;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->requestStackOrSession->getBag('flashes');
|
$flashBag = $this->requestStackOrSession->getBag('flashes');
|
||||||
|
Assert::isInstanceOf($flashBag, FlashBagInterface::class);
|
||||||
|
|
||||||
|
return $flashBag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,11 +57,14 @@ final class LocaleStrippingRouter implements RouterInterface, WarmableInterface
|
||||||
return $this->router->getRouteCollection();
|
return $this->router->getRouteCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function warmUp($cacheDir): void
|
/** @return string[] */
|
||||||
|
public function warmUp($cacheDir): array
|
||||||
{
|
{
|
||||||
if ($this->router instanceof WarmableInterface) {
|
if ($this->router instanceof WarmableInterface) {
|
||||||
$this->router->warmUp($cacheDir);
|
return $this->router->warmUp($cacheDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function removeUnusedQueryArgument(string $url, string $key, string $value): string
|
private function removeUnusedQueryArgument(string $url, string $key, string $value): string
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,10 @@ abstract class AbstractRoleCommand extends ContainerAwareCommand
|
||||||
{
|
{
|
||||||
$class = $this->getUserModelClass($userType);
|
$class = $this->getUserModelClass($userType);
|
||||||
|
|
||||||
return $this->getEntityManager($userType)->getRepository($class);
|
$userRepository = $this->getEntityManager($userType)->getRepository($class);
|
||||||
|
Assert::isInstanceOf($userRepository, UserRepositoryInterface::class);
|
||||||
|
|
||||||
|
return $userRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getAvailableUserTypes(): array
|
protected function getAvailableUserTypes(): array
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,15 @@ declare(strict_types=1);
|
||||||
namespace Sylius\Bundle\UserBundle\Provider;
|
namespace Sylius\Bundle\UserBundle\Provider;
|
||||||
|
|
||||||
use Symfony\Component\Security\Core\User\UserInterface;
|
use Symfony\Component\Security\Core\User\UserInterface;
|
||||||
|
use Webmozart\Assert\Assert;
|
||||||
|
|
||||||
class EmailProvider extends AbstractUserProvider
|
class EmailProvider extends AbstractUserProvider
|
||||||
{
|
{
|
||||||
protected function findUser(string $uniqueIdentifier): ?UserInterface
|
protected function findUser(string $uniqueIdentifier): ?UserInterface
|
||||||
{
|
{
|
||||||
return $this->userRepository->findOneByEmail($uniqueIdentifier);
|
$user = $this->userRepository->findOneByEmail($uniqueIdentifier);
|
||||||
|
Assert::nullOrIsInstanceOf($user, UserInterface::class);
|
||||||
|
|
||||||
|
return $user;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,15 +14,22 @@ declare(strict_types=1);
|
||||||
namespace Sylius\Bundle\UserBundle\Provider;
|
namespace Sylius\Bundle\UserBundle\Provider;
|
||||||
|
|
||||||
use Symfony\Component\Security\Core\User\UserInterface;
|
use Symfony\Component\Security\Core\User\UserInterface;
|
||||||
|
use Webmozart\Assert\Assert;
|
||||||
|
|
||||||
class UsernameOrEmailProvider extends AbstractUserProvider
|
class UsernameOrEmailProvider extends AbstractUserProvider
|
||||||
{
|
{
|
||||||
protected function findUser(string $uniqueIdentifier): ?UserInterface
|
protected function findUser(string $uniqueIdentifier): ?UserInterface
|
||||||
{
|
{
|
||||||
if (filter_var($uniqueIdentifier, \FILTER_VALIDATE_EMAIL)) {
|
if (filter_var($uniqueIdentifier, \FILTER_VALIDATE_EMAIL)) {
|
||||||
return $this->userRepository->findOneByEmail($uniqueIdentifier);
|
$user = $this->userRepository->findOneByEmail($uniqueIdentifier);
|
||||||
|
Assert::nullOrIsInstanceOf($user, UserInterface::class);
|
||||||
|
|
||||||
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->userRepository->findOneBy(['usernameCanonical' => $uniqueIdentifier]);
|
$user = $this->userRepository->findOneBy(['usernameCanonical' => $uniqueIdentifier]);
|
||||||
|
Assert::nullOrIsInstanceOf($user, UserInterface::class);
|
||||||
|
|
||||||
|
return $user;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,15 @@ declare(strict_types=1);
|
||||||
namespace Sylius\Bundle\UserBundle\Provider;
|
namespace Sylius\Bundle\UserBundle\Provider;
|
||||||
|
|
||||||
use Symfony\Component\Security\Core\User\UserInterface;
|
use Symfony\Component\Security\Core\User\UserInterface;
|
||||||
|
use Webmozart\Assert\Assert;
|
||||||
|
|
||||||
class UsernameProvider extends AbstractUserProvider
|
class UsernameProvider extends AbstractUserProvider
|
||||||
{
|
{
|
||||||
protected function findUser(string $uniqueIdentifier): ?UserInterface
|
protected function findUser(string $uniqueIdentifier): ?UserInterface
|
||||||
{
|
{
|
||||||
return $this->userRepository->findOneBy(['usernameCanonical' => $uniqueIdentifier]);
|
$user = $this->userRepository->findOneBy(['usernameCanonical' => $uniqueIdentifier]);
|
||||||
|
Assert::nullOrIsInstanceOf($user, UserInterface::class);
|
||||||
|
|
||||||
|
return $user;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ namespace Sylius\Component\Channel\Context;
|
||||||
|
|
||||||
use Sylius\Component\Channel\Model\ChannelInterface;
|
use Sylius\Component\Channel\Model\ChannelInterface;
|
||||||
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
|
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
|
||||||
|
use Webmozart\Assert\Assert;
|
||||||
|
|
||||||
final class SingleChannelContext implements ChannelContextInterface
|
final class SingleChannelContext implements ChannelContextInterface
|
||||||
{
|
{
|
||||||
|
|
@ -29,7 +30,9 @@ final class SingleChannelContext implements ChannelContextInterface
|
||||||
if (1 !== count($channels)) {
|
if (1 !== count($channels)) {
|
||||||
throw new ChannelNotFoundException();
|
throw new ChannelNotFoundException();
|
||||||
}
|
}
|
||||||
|
$channel = reset($channels);
|
||||||
|
Assert::isInstanceOf($channel, ChannelInterface::class);
|
||||||
|
|
||||||
return current($channels);
|
return $channel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ use Sylius\Component\Channel\Factory\ChannelFactoryInterface;
|
||||||
use Sylius\Component\Channel\Model\ChannelInterface;
|
use Sylius\Component\Channel\Model\ChannelInterface;
|
||||||
use Sylius\Component\Core\Model\ChannelInterface as CoreChannelInterface;
|
use Sylius\Component\Core\Model\ChannelInterface as CoreChannelInterface;
|
||||||
use Sylius\Component\Resource\Factory\FactoryInterface;
|
use Sylius\Component\Resource\Factory\FactoryInterface;
|
||||||
|
use Webmozart\Assert\Assert;
|
||||||
|
|
||||||
final class ChannelFactory implements ChannelFactoryInterface
|
final class ChannelFactory implements ChannelFactoryInterface
|
||||||
{
|
{
|
||||||
|
|
@ -36,13 +37,11 @@ final class ChannelFactory implements ChannelFactoryInterface
|
||||||
return $channel;
|
return $channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return CoreChannelInterface
|
|
||||||
*/
|
|
||||||
public function createNamed(string $name): ChannelInterface
|
public function createNamed(string $name): ChannelInterface
|
||||||
{
|
{
|
||||||
$channel = $this->createNew();
|
$channel = $this->createNew();
|
||||||
$channel->setName($name);
|
$channel->setName($name);
|
||||||
|
Assert::isInstanceOf($channel, ChannelInterface::class);
|
||||||
|
|
||||||
return $channel;
|
return $channel;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ namespace Sylius\Component\Core\Model;
|
||||||
|
|
||||||
use Sylius\Component\Addressing\Model\Address as BaseAddress;
|
use Sylius\Component\Addressing\Model\Address as BaseAddress;
|
||||||
use Sylius\Component\Customer\Model\CustomerInterface as BaseCustomerInterface;
|
use Sylius\Component\Customer\Model\CustomerInterface as BaseCustomerInterface;
|
||||||
|
use Webmozart\Assert\Assert;
|
||||||
|
|
||||||
class Address extends BaseAddress implements AddressInterface
|
class Address extends BaseAddress implements AddressInterface
|
||||||
{
|
{
|
||||||
|
|
@ -28,6 +29,7 @@ class Address extends BaseAddress implements AddressInterface
|
||||||
|
|
||||||
public function setCustomer(?BaseCustomerInterface $customer): void
|
public function setCustomer(?BaseCustomerInterface $customer): void
|
||||||
{
|
{
|
||||||
|
Assert::nullOrIsInstanceOf($customer, CustomerInterface::class);
|
||||||
$this->customer = $customer;
|
$this->customer = $customer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ use Doctrine\Common\Collections\Collection;
|
||||||
use Sylius\Component\Channel\Model\ChannelInterface as BaseChannelInterface;
|
use Sylius\Component\Channel\Model\ChannelInterface as BaseChannelInterface;
|
||||||
use Sylius\Component\Promotion\Model\CatalogPromotion as BaseCatalogPromotion;
|
use Sylius\Component\Promotion\Model\CatalogPromotion as BaseCatalogPromotion;
|
||||||
use Sylius\Component\Promotion\Model\CatalogPromotionTranslation;
|
use Sylius\Component\Promotion\Model\CatalogPromotionTranslation;
|
||||||
|
use Webmozart\Assert\Assert;
|
||||||
|
|
||||||
class CatalogPromotion extends BaseCatalogPromotion implements CatalogPromotionInterface
|
class CatalogPromotion extends BaseCatalogPromotion implements CatalogPromotionInterface
|
||||||
{
|
{
|
||||||
|
|
@ -41,6 +42,7 @@ class CatalogPromotion extends BaseCatalogPromotion implements CatalogPromotionI
|
||||||
*/
|
*/
|
||||||
public function getChannels(): Collection
|
public function getChannels(): Collection
|
||||||
{
|
{
|
||||||
|
/** @phpstan-ignore-next-line */
|
||||||
return $this->channels;
|
return $this->channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -128,6 +128,7 @@ class Order extends BaseOrder implements OrderInterface
|
||||||
|
|
||||||
public function setChannel(?BaseChannelInterface $channel): void
|
public function setChannel(?BaseChannelInterface $channel): void
|
||||||
{
|
{
|
||||||
|
Assert::isInstanceOf($channel, ChannelInterface::class);
|
||||||
$this->channel = $channel;
|
$this->channel = $channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -208,6 +209,7 @@ class Order extends BaseOrder implements OrderInterface
|
||||||
*/
|
*/
|
||||||
public function getPayments(): Collection
|
public function getPayments(): Collection
|
||||||
{
|
{
|
||||||
|
/** @phpstan-ignore-next-line */
|
||||||
return $this->payments;
|
return $this->payments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -132,6 +132,8 @@ interface OrderInterface extends
|
||||||
* @psalm-return Collection<array-key, OrderItemInterface>
|
* @psalm-return Collection<array-key, OrderItemInterface>
|
||||||
*
|
*
|
||||||
* @psalm-suppress ImplementedReturnTypeMismatch
|
* @psalm-suppress ImplementedReturnTypeMismatch
|
||||||
|
*
|
||||||
|
* @phpstan-ignore-next-line
|
||||||
*/
|
*/
|
||||||
public function getItems(): Collection;
|
public function getItems(): Collection;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,10 @@ class OrderItem extends BaseOrderItem implements OrderItemInterface
|
||||||
|
|
||||||
public function getProduct(): ?ProductInterface
|
public function getProduct(): ?ProductInterface
|
||||||
{
|
{
|
||||||
return $this->variant->getProduct();
|
$product = $this->variant->getProduct();
|
||||||
|
Assert::nullOrIsInstanceOf($product, ProductInterface::class);
|
||||||
|
|
||||||
|
return $product;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getProductName(): ?string
|
public function getProductName(): ?string
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ class OrderItemUnit extends BaseOrderItemUnit implements OrderItemUnitInterface
|
||||||
|
|
||||||
public function setShipment(?BaseShipmentInterface $shipment): void
|
public function setShipment(?BaseShipmentInterface $shipment): void
|
||||||
{
|
{
|
||||||
|
Assert::nullOrIsInstanceOf($shipment, ShipmentInterface::class);
|
||||||
$this->shipment = $shipment;
|
$this->shipment = $shipment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ namespace Sylius\Component\Core\Model;
|
||||||
|
|
||||||
use Sylius\Component\Order\Model\OrderInterface as BaseOrderInterface;
|
use Sylius\Component\Order\Model\OrderInterface as BaseOrderInterface;
|
||||||
use Sylius\Component\Payment\Model\Payment as BasePayment;
|
use Sylius\Component\Payment\Model\Payment as BasePayment;
|
||||||
|
use Webmozart\Assert\Assert;
|
||||||
|
|
||||||
class Payment extends BasePayment implements PaymentInterface
|
class Payment extends BasePayment implements PaymentInterface
|
||||||
{
|
{
|
||||||
|
|
@ -23,6 +24,8 @@ class Payment extends BasePayment implements PaymentInterface
|
||||||
|
|
||||||
public function getOrder(): ?BaseOrderInterface
|
public function getOrder(): ?BaseOrderInterface
|
||||||
{
|
{
|
||||||
|
Assert::isInstanceOf($this->order, OrderInterface::class);
|
||||||
|
|
||||||
return $this->order;
|
return $this->order;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -149,6 +149,7 @@ class Product extends BaseProduct implements ProductInterface, ReviewableProduct
|
||||||
*/
|
*/
|
||||||
public function getChannels(): Collection
|
public function getChannels(): Collection
|
||||||
{
|
{
|
||||||
|
/** @phpstan-ignore-next-line */
|
||||||
return $this->channels;
|
return $this->channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -272,7 +273,10 @@ class Product extends BaseProduct implements ProductInterface, ReviewableProduct
|
||||||
*/
|
*/
|
||||||
public function getTranslation(?string $locale = null): TranslationInterface
|
public function getTranslation(?string $locale = null): TranslationInterface
|
||||||
{
|
{
|
||||||
return parent::getTranslation($locale);
|
$productTranslation = parent::getTranslation($locale);
|
||||||
|
Assert::isInstanceOf($productTranslation, ProductTranslationInterface::class);
|
||||||
|
|
||||||
|
return $productTranslation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ use Doctrine\Common\Comparable;
|
||||||
use Sylius\Component\Product\Model\ProductVariant as BaseVariant;
|
use Sylius\Component\Product\Model\ProductVariant as BaseVariant;
|
||||||
use Sylius\Component\Shipping\Model\ShippingCategoryInterface;
|
use Sylius\Component\Shipping\Model\ShippingCategoryInterface;
|
||||||
use Sylius\Component\Taxation\Model\TaxCategoryInterface;
|
use Sylius\Component\Taxation\Model\TaxCategoryInterface;
|
||||||
|
use Webmozart\Assert\Assert;
|
||||||
|
|
||||||
class ProductVariant extends BaseVariant implements ProductVariantInterface, Comparable, \Stringable
|
class ProductVariant extends BaseVariant implements ProductVariantInterface, Comparable, \Stringable
|
||||||
{
|
{
|
||||||
|
|
@ -291,6 +292,7 @@ class ProductVariant extends BaseVariant implements ProductVariantInterface, Com
|
||||||
*/
|
*/
|
||||||
public function getImages(): Collection
|
public function getImages(): Collection
|
||||||
{
|
{
|
||||||
|
/** @phpstan-ignore-next-line */
|
||||||
return $this->images;
|
return $this->images;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -300,9 +302,13 @@ class ProductVariant extends BaseVariant implements ProductVariantInterface, Com
|
||||||
*/
|
*/
|
||||||
public function getImagesByType(string $type): Collection
|
public function getImagesByType(string $type): Collection
|
||||||
{
|
{
|
||||||
return $this->images->filter(function (ProductImageInterface $image) use ($type): bool {
|
/** @var Collection<array-key, ImageInterface> $imagesByType */
|
||||||
|
$imagesByType = $this->images->filter(function (ProductImageInterface $image) use ($type): bool {
|
||||||
return $type === $image->getType();
|
return $type === $image->getType();
|
||||||
});
|
});
|
||||||
|
Assert::allIsInstanceOf($imagesByType, ImageInterface::class);
|
||||||
|
|
||||||
|
return $imagesByType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasImages(): bool
|
public function hasImages(): bool
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ class Promotion extends BasePromotion implements PromotionInterface
|
||||||
*/
|
*/
|
||||||
public function getChannels(): Collection
|
public function getChannels(): Collection
|
||||||
{
|
{
|
||||||
|
/** @phpstan-ignore-next-line */
|
||||||
return $this->channels;
|
return $this->channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ use Doctrine\Common\Collections\Collection;
|
||||||
use Sylius\Component\Order\Model\AdjustmentInterface as BaseAdjustmentInterface;
|
use Sylius\Component\Order\Model\AdjustmentInterface as BaseAdjustmentInterface;
|
||||||
use Sylius\Component\Order\Model\OrderInterface as BaseOrderInterface;
|
use Sylius\Component\Order\Model\OrderInterface as BaseOrderInterface;
|
||||||
use Sylius\Component\Shipping\Model\Shipment as BaseShipment;
|
use Sylius\Component\Shipping\Model\Shipment as BaseShipment;
|
||||||
|
use Webmozart\Assert\Assert;
|
||||||
|
|
||||||
class Shipment extends BaseShipment implements ShipmentInterface
|
class Shipment extends BaseShipment implements ShipmentInterface
|
||||||
{
|
{
|
||||||
|
|
@ -44,6 +45,7 @@ class Shipment extends BaseShipment implements ShipmentInterface
|
||||||
|
|
||||||
public function getOrder(): ?BaseOrderInterface
|
public function getOrder(): ?BaseOrderInterface
|
||||||
{
|
{
|
||||||
|
Assert::nullOrIsInstanceOf($this->order, OrderInterface::class);
|
||||||
return $this->order;
|
return $this->order;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@ class ShippingMethod extends BaseShippingMethod implements ShippingMethodInterfa
|
||||||
*/
|
*/
|
||||||
public function getChannels(): Collection
|
public function getChannels(): Collection
|
||||||
{
|
{
|
||||||
|
/** @phpstan-ignore-next-line */
|
||||||
return $this->channels;
|
return $this->channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ use Sylius\Component\Payment\Factory\PaymentFactoryInterface;
|
||||||
use Sylius\Component\Payment\PaymentTransitions;
|
use Sylius\Component\Payment\PaymentTransitions;
|
||||||
use Sylius\Component\Payment\Resolver\DefaultPaymentMethodResolverInterface;
|
use Sylius\Component\Payment\Resolver\DefaultPaymentMethodResolverInterface;
|
||||||
use Sylius\Component\Resource\StateMachine\StateMachineInterface;
|
use Sylius\Component\Resource\StateMachine\StateMachineInterface;
|
||||||
|
use Webmozart\Assert\Assert;
|
||||||
|
|
||||||
final class OrderPaymentProvider implements OrderPaymentProviderInterface
|
final class OrderPaymentProvider implements OrderPaymentProviderInterface
|
||||||
{
|
{
|
||||||
|
|
@ -72,8 +73,10 @@ final class OrderPaymentProvider implements OrderPaymentProviderInterface
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$payment->setOrder($order);
|
$payment->setOrder($order);
|
||||||
|
$paymentMethod = $this->defaultPaymentMethodResolver->getDefaultPaymentMethod($payment);
|
||||||
|
Assert::isInstanceOf($paymentMethod, PaymentMethodInterface::class);
|
||||||
|
|
||||||
return $this->defaultPaymentMethodResolver->getDefaultPaymentMethod($payment);
|
return $paymentMethod;
|
||||||
} catch (UnresolvedDefaultPaymentMethodException) {
|
} catch (UnresolvedDefaultPaymentMethodException) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -122,8 +122,12 @@ final class OrderPaymentStateResolver implements StateResolverInterface
|
||||||
*/
|
*/
|
||||||
private function getPaymentsWithState(OrderInterface $order, string $state): Collection
|
private function getPaymentsWithState(OrderInterface $order, string $state): Collection
|
||||||
{
|
{
|
||||||
return $order->getPayments()->filter(function (PaymentInterface $payment) use ($state) {
|
/** @var Collection<array-key, PaymentInterface> $payments */
|
||||||
|
$payments = $order->getPayments()->filter(function (PaymentInterface $payment) use ($state) {
|
||||||
return $state === $payment->getState();
|
return $state === $payment->getState();
|
||||||
});
|
});
|
||||||
|
Assert::allIsInstanceOf($payments, PaymentInterface::class);
|
||||||
|
|
||||||
|
return $payments;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,9 @@ use Sylius\Component\Core\Model\AdjustmentInterface;
|
||||||
use Sylius\Component\Core\Model\OrderItemInterface;
|
use Sylius\Component\Core\Model\OrderItemInterface;
|
||||||
use Sylius\Component\Core\Model\OrderItemUnitInterface;
|
use Sylius\Component\Core\Model\OrderItemUnitInterface;
|
||||||
use Sylius\Component\Core\Model\ProductVariantInterface;
|
use Sylius\Component\Core\Model\ProductVariantInterface;
|
||||||
|
use Sylius\Component\Core\Model\ShipmentInterface;
|
||||||
use Sylius\Component\Inventory\Model\InventoryUnitInterface;
|
use Sylius\Component\Inventory\Model\InventoryUnitInterface;
|
||||||
use Sylius\Component\Order\Model\OrderItemUnit as BaseOrderItemUnit;
|
use Sylius\Component\Order\Model\OrderItemUnit as BaseOrderItemUnit;
|
||||||
use Sylius\Component\Shipping\Model\ShipmentInterface;
|
|
||||||
use Sylius\Component\Shipping\Model\ShipmentUnitInterface;
|
use Sylius\Component\Shipping\Model\ShipmentUnitInterface;
|
||||||
|
|
||||||
final class OrderItemUnitSpec extends ObjectBehavior
|
final class OrderItemUnitSpec extends ObjectBehavior
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ use Sylius\Component\Payment\Exception\UnresolvedDefaultPaymentMethodException;
|
||||||
use Sylius\Component\Payment\Model\PaymentInterface;
|
use Sylius\Component\Payment\Model\PaymentInterface;
|
||||||
use Sylius\Component\Payment\Model\PaymentMethodInterface;
|
use Sylius\Component\Payment\Model\PaymentMethodInterface;
|
||||||
use Sylius\Component\Payment\Repository\PaymentMethodRepositoryInterface;
|
use Sylius\Component\Payment\Repository\PaymentMethodRepositoryInterface;
|
||||||
|
use Webmozart\Assert\Assert;
|
||||||
|
|
||||||
final class DefaultPaymentMethodResolver implements DefaultPaymentMethodResolverInterface
|
final class DefaultPaymentMethodResolver implements DefaultPaymentMethodResolverInterface
|
||||||
{
|
{
|
||||||
|
|
@ -33,7 +34,9 @@ final class DefaultPaymentMethodResolver implements DefaultPaymentMethodResolver
|
||||||
if (empty($paymentMethods)) {
|
if (empty($paymentMethods)) {
|
||||||
throw new UnresolvedDefaultPaymentMethodException();
|
throw new UnresolvedDefaultPaymentMethodException();
|
||||||
}
|
}
|
||||||
|
$paymentMethod = $paymentMethods[0];
|
||||||
|
Assert::isInstanceOf($paymentMethod, PaymentMethodInterface::class);
|
||||||
|
|
||||||
return $paymentMethods[0];
|
return $paymentMethod;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ use Sylius\Component\Shipping\Exception\UnresolvedDefaultShippingMethodException
|
||||||
use Sylius\Component\Shipping\Model\ShipmentInterface;
|
use Sylius\Component\Shipping\Model\ShipmentInterface;
|
||||||
use Sylius\Component\Shipping\Model\ShippingMethodInterface;
|
use Sylius\Component\Shipping\Model\ShippingMethodInterface;
|
||||||
use Sylius\Component\Shipping\Repository\ShippingMethodRepositoryInterface;
|
use Sylius\Component\Shipping\Repository\ShippingMethodRepositoryInterface;
|
||||||
|
use Webmozart\Assert\Assert;
|
||||||
|
|
||||||
final class DefaultShippingMethodResolver implements DefaultShippingMethodResolverInterface
|
final class DefaultShippingMethodResolver implements DefaultShippingMethodResolverInterface
|
||||||
{
|
{
|
||||||
|
|
@ -30,7 +31,9 @@ final class DefaultShippingMethodResolver implements DefaultShippingMethodResolv
|
||||||
if (empty($shippingMethods)) {
|
if (empty($shippingMethods)) {
|
||||||
throw new UnresolvedDefaultShippingMethodException();
|
throw new UnresolvedDefaultShippingMethodException();
|
||||||
}
|
}
|
||||||
|
$shippingMethod = $shippingMethods[0];
|
||||||
|
Assert::isInstanceOf($shippingMethod, ShippingMethodInterface::class);
|
||||||
|
|
||||||
return $shippingMethods[0];
|
return $shippingMethod;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue