-
-
Notifications
You must be signed in to change notification settings - Fork 22
Possibly a simpler reproducer for #323 #326
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Spaze\PHPStan\Rules\Disallowed\Usages; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Name\FullyQualified; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Rules\Rule; | ||
use PHPStan\Rules\RuleError; | ||
use PHPStan\Rules\RuleErrorBuilder; | ||
|
||
/** | ||
* @implements Rule<Node> | ||
*/ | ||
class Reproducer2Usages implements Rule | ||
{ | ||
|
||
public function getNodeType(): string | ||
{ | ||
return FullyQualified::class; | ||
} | ||
|
||
|
||
/** | ||
* @param FullyQualified $node | ||
* @param Scope $scope | ||
* @return list<RuleError> | ||
*/ | ||
public function processNode(Node $node, Scope $scope): array | ||
{ | ||
return [ | ||
RuleErrorBuilder::message(sprintf('class %s found in method %s', $node->toString(), $scope->getFunction()?->getName() ?? 'null'))->build(), | ||
Check failure on line 33 in src/Usages/Reproducer2Usages.php
|
||
]; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Spaze\PHPStan\Rules\Disallowed\Usages; | ||
|
||
use PHPStan\Rules\Rule; | ||
use PHPStan\Testing\RuleTestCase; | ||
|
||
class Reproducer2Test extends RuleTestCase | ||
{ | ||
|
||
protected function shouldNarrowMethodScopeFromConstructor(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
|
||
protected function getRule(): Rule | ||
{ | ||
return new Reproducer2Usages(); | ||
} | ||
|
||
|
||
public function testRule(): void | ||
{ | ||
$this->analyse([__DIR__ . '/../src/Reproducer2Class.php'], [ | ||
[ | ||
'class DateTime found in method null', | ||
12, | ||
], | ||
[ | ||
'class Baz\Waldo found in method null', | ||
16, | ||
], | ||
]); | ||
} | ||
|
||
|
||
public static function getAdditionalConfigFiles(): array | ||
{ | ||
return [ | ||
__DIR__ . '/../../extension.neon', | ||
]; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Reproducer2; | ||
|
||
class Reproducer2Class | ||
{ | ||
public function __construct() | ||
{ | ||
} | ||
|
||
public function foo(\DateTime $d): void | ||
{ | ||
} | ||
|
||
public function bar(\Baz\Waldo $d): void | ||
{ | ||
} | ||
} |
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.
If I read this test correctly it is now independent from the disallowed-calls extension package, right?
if so, I think we should open a phpstan-src issue and add the reproducer there
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 will port it over into the fixing PR at phpstan/phpstan-src#3944
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.
Perfect, and yes, it is independent now.