Skip to content

Commit 57ec3e5

Browse files
staabmspazeruudk
committed
added test
Co-Authored-By: Michal Špaček <[email protected]> Co-Authored-By: Ruud Kamphuis <[email protected]>
1 parent 150b731 commit 57ec3e5

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Analyser;
4+
5+
use PhpParser\Node;
6+
use PhpParser\Node\Name\FullyQualified;
7+
use PHPStan\Analyser\Scope;
8+
use PHPStan\Rules\Rule;
9+
use PHPStan\Rules\RuleError;
10+
use PHPStan\Rules\RuleErrorBuilder;
11+
use PHPStan\Testing\RuleTestCase;
12+
13+
class InstanceMethodsParameterScopeTest extends RuleTestCase
14+
{
15+
16+
protected function getRule(): Rule
17+
{
18+
return new class implements Rule
19+
{
20+
public function getNodeType(): string
21+
{
22+
return FullyQualified::class;
23+
}
24+
25+
/**
26+
* @param FullyQualified $node
27+
* @param Scope $scope
28+
* @return list<RuleError>
29+
*/
30+
public function processNode(Node $node, Scope $scope): array
31+
{
32+
return [
33+
RuleErrorBuilder::message(sprintf('Name %s found in method %s', $node->toString(), $scope->getFunction()?->getName() ?? 'null'))->build(),
34+
];
35+
}
36+
};
37+
}
38+
39+
protected function shouldNarrowMethodScopeFromConstructor(): bool
40+
{
41+
return true;
42+
}
43+
44+
public function testRule(): void
45+
{
46+
$this->analyse([__DIR__ . '/data/instance-methods-parameter-scope.php'], [
47+
[
48+
'Name DateTime found in method null',
49+
12,
50+
],
51+
[
52+
'Name Baz\Waldo found in method null',
53+
16,
54+
],
55+
]);
56+
}
57+
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
declare(strict_types = 1);
3+
4+
namespace InstanceMethodsParameterScopeTest;
5+
6+
class HelloWorld
7+
{
8+
public function __construct()
9+
{
10+
}
11+
12+
public function foo(\DateTime $d): void
13+
{
14+
}
15+
16+
public function bar(\Baz\Waldo $d): void
17+
{
18+
}
19+
}

0 commit comments

Comments
 (0)