-
Notifications
You must be signed in to change notification settings - Fork 95
Avoid reporting with TestContainer::get as internal #441
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/Type/Symfony/Container/KernelBrowserGetContainerDynamicReturnTypeExtension.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Type\Symfony\Container; | ||
|
||
use PhpParser\Node\Expr\MethodCall; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Reflection\MethodReflection; | ||
use PHPStan\Type\DynamicMethodReturnTypeExtension; | ||
use PHPStan\Type\Type; | ||
|
||
final class KernelBrowserGetContainerDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension | ||
{ | ||
|
||
public function getClass(): string | ||
{ | ||
return 'Symfony\Bundle\FrameworkBundle\KernelBrowser'; | ||
} | ||
|
||
public function isMethodSupported(MethodReflection $methodReflection): bool | ||
{ | ||
return $methodReflection->getName() === 'getContainer'; | ||
} | ||
|
||
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type | ||
{ | ||
return new TestContainerType(); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/Type/Symfony/Container/KernelTestCaseGetContainerDynamicReturnTypeExtension.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Type\Symfony\Container; | ||
|
||
use PhpParser\Node\Expr\StaticCall; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Reflection\MethodReflection; | ||
use PHPStan\Type\DynamicStaticMethodReturnTypeExtension; | ||
use PHPStan\Type\Type; | ||
|
||
final class KernelTestCaseGetContainerDynamicReturnTypeExtension implements DynamicStaticMethodReturnTypeExtension | ||
{ | ||
|
||
public function getClass(): string | ||
{ | ||
return 'Symfony\Bundle\FrameworkBundle\Test\KernelTestCase'; | ||
} | ||
|
||
public function isStaticMethodSupported(MethodReflection $methodReflection): bool | ||
{ | ||
return $methodReflection->getName() === 'getContainer'; | ||
} | ||
|
||
public function getTypeFromStaticMethodCall(MethodReflection $methodReflection, StaticCall $methodCall, Scope $scope): Type | ||
{ | ||
return new TestContainerType(); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Type\Symfony\Container; | ||
|
||
use PHPStan\Reflection\ClassReflection; | ||
use PHPStan\Type\ObjectType; | ||
use PHPStan\Type\Type; | ||
|
||
class TestContainerType extends ObjectType | ||
{ | ||
|
||
public function __construct( | ||
string $class = 'Symfony\Component\DependencyInjection\ContainerInterface', | ||
?Type $subtractedType = null, | ||
?ClassReflection $classReflection = null | ||
) | ||
{ | ||
parent::__construct($class, $subtractedType, $classReflection); | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
stubs/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.stub
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Rules\Symfony; | ||
|
||
use Symfony\Bundle\FrameworkBundle\KernelBrowser; | ||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
|
||
abstract class ExampleTest extends KernelTestCase | ||
{ | ||
|
||
public function bar(): void | ||
{ | ||
$container = self::getContainer(); | ||
$container->get('private'); | ||
} | ||
|
||
public function foo(KernelBrowser $browser): void | ||
{ | ||
$container = $browser->getContainer(); | ||
$container->get('private'); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
services: | ||
- | ||
class: PHPStan\Type\Symfony\Container\KernelBrowserGetContainerDynamicReturnTypeExtension | ||
tags: [phpstan.broker.dynamicMethodReturnTypeExtension] | ||
- | ||
class: PHPStan\Type\Symfony\Container\KernelTestCaseGetContainerDynamicReturnTypeExtension | ||
tags: [phpstan.broker.dynamicStaticMethodReturnTypeExtension] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we simplify this and not report an error when we simply have the upper-most ContainerInterface and are in a subclass of KernelTestCase?
The custom type is wrong since it doesn't implement equals, describe and isSuperTypeOf. But I think we don't need it at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not fully true, but this might be good enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be better with the last commit.