8000 WIP [Meta] Add PHPStan to build process by dkarlovi · Pull Request #25536 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

WIP [Meta] Add PHPStan to build process #25536

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

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[Meta] fix issues found via PHPStan in DI component
  • Loading branch information
dkarlovi committed Dec 18, 2017
commit bdeda31c0b01c1b362b5e3c66a18e1550c96ca1e
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ QA_DOCKER_IMAGE=jakzal/phpqa:latest
QA_DOCKER_COMMAND=docker run -it --rm -v "$(shell pwd):/project" -w /project ${QA_DOCKER_IMAGE}

phpstan:
sh -c "${QA_DOCKER_COMMAND} phpstan analyse --configuration phpstan.neon --level 0 src/Symfony/Component/Debug"
sh -c "${QA_DOCKER_COMMAND} phpstan analyse --configuration phpstan.neon --level 0 src/Symfony/Component/DependencyInjection"

##
# Special operations
Expand Down
5 changes: 4 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ parameters:

# not errors, actually expected to fail
- '#Class Symfony\\Bundle\\FrameworkBundle\\Tests\\DependencyInjection\\Compiler\\NotFound not found.#'
- '#Class Symfony\\Component\\DependencyInjection\\Tests\\Compiler\\NotExist not found.#'
- '#Class Symfony\\Bug\\NotExistClass not found and could not be autoloaded.#'
excludes_analyse:
- */src/Symfony/Bridge/*/Tests/Fixtures/*
- */src/Symfony/Bridge/*/Tests/*/Fixtures/*
Expand All @@ -35,7 +37,8 @@ parameters:
- src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php
- src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTest.php

# temporary, loading a NotLoadableClass throws a fatal error
# temporary, loading a non-existant class, these should probably be fixtures
- src/symfony/Component/DependencyInjection/Tests/Compiler/OptionalServiceClass.php
- src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php

# temporary, it's full of actual errors (which are triggers for the handler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class PrototypeConfigurator extends AbstractServiceConfigurator
private $loader;
private $resource;
private $exclude;
private $allowParent;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be kept (same below), this is a false positive: the property is used by a trait

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that makes the trait dependent on the class using it? Which is in turn dependent on the trait it's using?


public function __construct(ServicesConfigurator $parent, PhpFileLoader $loader, Definition $defaults, string $namespace, string $resource, bool $allowParent)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class ServiceConfigurator extends AbstractServiceConfigurator

private $container;
private $instanceof;
private $allowParent;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be reverted

E864


public function __construct(ContainerBuilder $container, array $instanceof, bool $allowParent, ServicesConfigurator $parent, Definition $definition, $id, array $defaultTags)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

trait BindTrait
{
protected $id;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the property is already defined in the classes that use the trait

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, the trait should define the properties it uses, no?


/**
* Sets bindings.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

trait ParentTrait
{
protected $allowParent;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

visibility change, should be reverted

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, the properties used by the trait were moved to the trait.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two traits defining a same property cannot be used by the same class
so nope, it shouldn't

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, SHOULD traits share a property?

Having a property inside a class is similar as being in concrete instead of abstract class, your abstraction depends on the implementation and vice-versa at the same time.

I mean, I can easily ignore these traits, but this seems broken. PHPStorm and PHPStan seem to agree.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is perfectly fine as is, and intended as is. So the answer is YES :)


/**
* Sets the Definition to inherit from.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testSimpleProcessor()
(new RegisterEnvVarProcessorsPass())->process($container);

$this->assertTrue($container->has('container.env_var_processors_locator'));
$this->assertInstanceof(SimpleProcessor::class, $container->get('container.env_var_processors_locator')->get('foo'));
$this->assertInstanceOf(SimpleProcessor::class, $container->get('container.env_var_processors_locator')->get('foo'));

$expected = array(
'foo' => array('string'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function testProcess()
$parent = 'instanceof.'.parent::class.'.0.foo';
$def = $container->getDefinition('foo');
$this->assertEmpty($def->getInstanceofConditionals());
$this->assertInstanceof(ChildDefinition::class, $def);
$this->assertInstanceOf(ChildDefinition::class, $def);
$this->assertTrue($def->isAutowired());
$this->assertSame($parent, $def->getParent());
$this->assertSame(array('tag' => array(array()), 'baz' => array(array('attr' => 123))), $def->getTags());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ class ProjectServiceContainer extends Container
public $__foo_bar;
public $__foo_baz;
public $__internal;
private $privates;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be "protected", as in the dumped container

protected $methodMap = array(
'bar' => 'getBarService',
'foo_bar' => 'getFooBarService',
Expand Down
0