Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPStan: initial config & first fixes #8809

Merged
merged 2 commits into from
Oct 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -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/'
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Context/Ui/Shop/LocaleContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Page/Admin/ShippingMethod/CreatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function chooseZone($name)
*/
public function chooseCalculator($name)
{
$this->getDocument()->selectFieldOption(\Calculator::class, $name);
$this->getDocument()->selectFieldOption('Calculator', $name);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Page/Admin/TaxRate/CreatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function chooseCategory($name)
*/
public function chooseCalculator($name)
{
$this->getDocument()->selectFieldOption(\Calculator::class, $name);
$this->getDocument()->selectFieldOption('Calculator', $name);
}

/**
Expand Down
12 changes: 4 additions & 8 deletions src/Sylius/Bundle/CoreBundle/Command/SetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
7 changes: 1 addition & 6 deletions src/Sylius/Component/Core/Model/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
abstract class Image implements ImageInterface
{
/**
* @var int
* @var mixed
*/
protected $id;

Expand All @@ -43,11 +43,6 @@ abstract class Image implements ImageInterface
*/
protected $owner;

public function __construct()
{
$this->createdAt = new \DateTime();
}

/**
* @return int
*/
Expand Down
2 changes: 0 additions & 2 deletions src/Sylius/Component/Core/Model/ProductImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class ProductImage extends Image implements ProductImageInterface

public function __construct()
{
parent::__construct();

$this->productVariants = new ArrayCollection();
}

Expand Down
1 change: 0 additions & 1 deletion src/Sylius/Component/Core/Model/Taxon.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public function __construct()
parent::__construct();

$this->createdAt = new \DateTime();
$this->products = new ArrayCollection();
$this->images = new ArrayCollection();
}

Expand Down