diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 00000000000..ba37b09d767 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,24 @@ +parameters: + excludes_analyse: + # Makes PHPStan crash + - '**/DependencyInjection/Configuration.php' + + # Test dependencies + - '**/Bundle/*/test/app/**.php' + - '**/Bundle/*/test/src/**.php' + + # These packages aren't in require-dev of the global package + - '**MongoDB**' + - '**ODM**' + + ignoreErrors: + # Specs autoloading - needs a project-wide change to Sylius\Foo\Bar\spec\... + - '/Class spec\\Sylius\\[^ ]++ was not found while trying to analyse it - autoloading is not probably configured properly./' + + # Webmozart assertions (methods defined by docblocks on class are not recognised) + - '/Call to an undefined static method Webmozart\\Assert\\Assert::all/' + - '/Call to an undefined static method Webmozart\\Assert\\Assert::nullOr/' + + # These packages aren't in require-dev of the global package + - '/Class Doctrine\\Bundle\\MongoDBBundle/' + - '/Class Doctrine\\Bundle\\PHPCRBundle/' diff --git a/src/Sylius/Behat/Context/Ui/Shop/LocaleContext.php b/src/Sylius/Behat/Context/Ui/Shop/LocaleContext.php index fb7db6e8524..3f0a116f473 100644 --- a/src/Sylius/Behat/Context/Ui/Shop/LocaleContext.php +++ b/src/Sylius/Behat/Context/Ui/Shop/LocaleContext.php @@ -74,7 +74,7 @@ public function iShouldNotBeAbleToShopUsingTheLocale($locale) if (in_array($locale, $this->homePage->getAvailableLocales(), true)) { throw new \InvalidArgumentException(sprintf( 'Expected "%s" not to be in "%s"', - $localeName, + $locale, implode('", "', $this->homePage->getAvailableLocales()) )); } diff --git a/src/Sylius/Behat/Page/Admin/ShippingMethod/CreatePage.php b/src/Sylius/Behat/Page/Admin/ShippingMethod/CreatePage.php index 7a6e0103953..035a2fd242f 100644 --- a/src/Sylius/Behat/Page/Admin/ShippingMethod/CreatePage.php +++ b/src/Sylius/Behat/Page/Admin/ShippingMethod/CreatePage.php @@ -73,7 +73,7 @@ public function chooseZone($name) */ public function chooseCalculator($name) { - $this->getDocument()->selectFieldOption(\Calculator::class, $name); + $this->getDocument()->selectFieldOption('Calculator', $name); } /** diff --git a/src/Sylius/Behat/Page/Admin/TaxRate/CreatePage.php b/src/Sylius/Behat/Page/Admin/TaxRate/CreatePage.php index b76e14b1184..8ed75131ad6 100644 --- a/src/Sylius/Behat/Page/Admin/TaxRate/CreatePage.php +++ b/src/Sylius/Behat/Page/Admin/TaxRate/CreatePage.php @@ -46,7 +46,7 @@ public function chooseCategory($name) */ public function chooseCalculator($name) { - $this->getDocument()->selectFieldOption(\Calculator::class, $name); + $this->getDocument()->selectFieldOption('Calculator', $name); } /** diff --git a/src/Sylius/Bundle/CoreBundle/Command/SetupCommand.php b/src/Sylius/Bundle/CoreBundle/Command/SetupCommand.php index 41424bf6393..e9938149668 100644 --- a/src/Sylius/Bundle/CoreBundle/Command/SetupCommand.php +++ b/src/Sylius/Bundle/CoreBundle/Command/SetupCommand.php @@ -130,7 +130,7 @@ private function configureNewUser(AdminUserInterface $user, InputInterface $inpu private function createEmailQuestion(OutputInterface $output): Question { return (new Question('E-mail:')) - ->setValidator(function ($value) use ($output) { + ->setValidator(function ($value) { /** @var ConstraintViolationListInterface $errors */ $errors = $this->get('validator')->validate((string) $value, [new Email(), new NotBlank()]); foreach ($errors as $error) { @@ -153,7 +153,7 @@ private function getAdministratorPassword(InputInterface $input, OutputInterface { /** @var QuestionHelper $questionHelper */ $questionHelper = $this->getHelper('question'); - $validator = $this->getPasswordQuestionValidator($output); + $validator = $this->getPasswordQuestionValidator(); do { $passwordQuestion = $this->createPasswordQuestion('Choose password:', $validator); @@ -171,15 +171,11 @@ private function getAdministratorPassword(InputInterface $input, OutputInterface } /** - * @param OutputInterface $output - * * @return \Closure - * - * @throws \DomainException */ - private function getPasswordQuestionValidator(OutputInterface $output): \Closure + private function getPasswordQuestionValidator(): \Closure { - return function ($value) use ($output) { + return function ($value) { /** @var ConstraintViolationListInterface $errors */ $errors = $this->get('validator')->validate($value, [new NotBlank()]); foreach ($errors as $error) { diff --git a/src/Sylius/Bundle/CoreBundle/Form/Type/Product/ProductReviewType.php b/src/Sylius/Bundle/CoreBundle/Form/Type/Product/ProductReviewType.php index ea95110c575..d50ec654641 100644 --- a/src/Sylius/Bundle/CoreBundle/Form/Type/Product/ProductReviewType.php +++ b/src/Sylius/Bundle/CoreBundle/Form/Type/Product/ProductReviewType.php @@ -34,7 +34,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void { parent::buildForm($builder, $options); - $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($options): void { + $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event): void { $form = $event->getForm(); $review = $event->getData(); diff --git a/src/Sylius/Bundle/CoreBundle/Tests/Fixture/CurrencyFixtureTest.php b/src/Sylius/Bundle/CoreBundle/Tests/Fixture/CurrencyFixtureTest.php index 17ffff3624a..fe44a764477 100644 --- a/src/Sylius/Bundle/CoreBundle/Tests/Fixture/CurrencyFixtureTest.php +++ b/src/Sylius/Bundle/CoreBundle/Tests/Fixture/CurrencyFixtureTest.php @@ -48,8 +48,7 @@ protected function getConfiguration(): CurrencyFixture { return new CurrencyFixture( $this->getMockBuilder(FactoryInterface::class)->getMock(), - $this->getMockBuilder(ObjectManager::class)->getMock(), - 'DEFAULT_CURRENCY_CODE' + $this->getMockBuilder(ObjectManager::class)->getMock() ); } } diff --git a/src/Sylius/Bundle/ProductBundle/Controller/ProductAttributeController.php b/src/Sylius/Bundle/ProductBundle/Controller/ProductAttributeController.php index c01d07d3ee0..c33a8cbce0a 100644 --- a/src/Sylius/Bundle/ProductBundle/Controller/ProductAttributeController.php +++ b/src/Sylius/Bundle/ProductBundle/Controller/ProductAttributeController.php @@ -84,6 +84,7 @@ public function renderAttributeValueFormsAction(Request $request): Response $localeCodes = $this->get('sylius.translation_locale_provider')->getDefinedLocalesCodes(); + $forms = []; foreach ($attributes as $attribute) { $forms[$attribute->getCode()] = $this->getAttributeFormsInAllLocales($attribute, $localeCodes); } diff --git a/src/Sylius/Bundle/ProductBundle/Form/Type/ProductAssociationTypeChoiceType.php b/src/Sylius/Bundle/ProductBundle/Form/Type/ProductAssociationTypeChoiceType.php index 715d7bbb7d4..a18bcfaa1e7 100644 --- a/src/Sylius/Bundle/ProductBundle/Form/Type/ProductAssociationTypeChoiceType.php +++ b/src/Sylius/Bundle/ProductBundle/Form/Type/ProductAssociationTypeChoiceType.php @@ -13,12 +13,12 @@ namespace Sylius\Bundle\ProductBundle\Form\Type; -use FOS\RestBundle\Controller\Annotations\Options; use Sylius\Component\Resource\Repository\RepositoryInterface; use Symfony\Bridge\Doctrine\Form\DataTransformer\CollectionToArrayTransformer; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\OptionsResolver; /** diff --git a/src/Sylius/Bundle/PromotionBundle/Form/Type/AbstractConfigurablePromotionElementType.php b/src/Sylius/Bundle/PromotionBundle/Form/Type/AbstractConfigurablePromotionElementType.php index 0a900a8988c..535394ae4ac 100644 --- a/src/Sylius/Bundle/PromotionBundle/Form/Type/AbstractConfigurablePromotionElementType.php +++ b/src/Sylius/Bundle/PromotionBundle/Form/Type/AbstractConfigurablePromotionElementType.php @@ -50,7 +50,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void parent::buildForm($builder, $options); $builder - ->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($options) { + ->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event): void { $type = $this->getRegistryIdentifier($event->getForm(), $event->getData()); if (null === $type) { return; @@ -66,7 +66,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $event->getForm()->get('type')->setData($type); }) - ->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use ($options) { + ->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event): void { $data = $event->getData(); if (!isset($data['type'])) { diff --git a/src/Sylius/Component/Attribute/AttributeType/TextareaAttributeType.php b/src/Sylius/Component/Attribute/AttributeType/TextareaAttributeType.php index 085bad440fd..d6e18e60b59 100644 --- a/src/Sylius/Component/Attribute/AttributeType/TextareaAttributeType.php +++ b/src/Sylius/Component/Attribute/AttributeType/TextareaAttributeType.php @@ -55,7 +55,7 @@ public function validate( $value = $attributeValue->getValue(); - foreach ($this->getValidationErrors($context, $value, $configuration) as $error) { + foreach ($this->getValidationErrors($context, $value) as $error) { $context ->buildViolation($error->getMessage()) ->atPath('value') diff --git a/src/Sylius/Component/Core/Model/Image.php b/src/Sylius/Component/Core/Model/Image.php index c51724de47c..0eed0fe89c2 100644 --- a/src/Sylius/Component/Core/Model/Image.php +++ b/src/Sylius/Component/Core/Model/Image.php @@ -19,7 +19,7 @@ abstract class Image implements ImageInterface { /** - * @var int + * @var mixed */ protected $id; @@ -43,11 +43,6 @@ abstract class Image implements ImageInterface */ protected $owner; - public function __construct() - { - $this->createdAt = new \DateTime(); - } - /** * @return int */ diff --git a/src/Sylius/Component/Core/Model/ProductImage.php b/src/Sylius/Component/Core/Model/ProductImage.php index af8350f9b21..b5d0038f24c 100644 --- a/src/Sylius/Component/Core/Model/ProductImage.php +++ b/src/Sylius/Component/Core/Model/ProductImage.php @@ -28,8 +28,6 @@ class ProductImage extends Image implements ProductImageInterface public function __construct() { - parent::__construct(); - $this->productVariants = new ArrayCollection(); } diff --git a/src/Sylius/Component/Core/Model/Taxon.php b/src/Sylius/Component/Core/Model/Taxon.php index ffdeb64ae78..ffd1be532be 100644 --- a/src/Sylius/Component/Core/Model/Taxon.php +++ b/src/Sylius/Component/Core/Model/Taxon.php @@ -36,7 +36,6 @@ public function __construct() parent::__construct(); $this->createdAt = new \DateTime(); - $this->products = new ArrayCollection(); $this->images = new ArrayCollection(); }