Repository navigation
Expand file tree
/
Copy pathUnusedMethodParametersRuleTest.php
More file actions
85 lines (74 loc) · 2.56 KB
/
Copy pathUnusedMethodParametersRuleTest.php
File metadata and controls
85 lines (74 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Methods;
use PHPStan\Analyser\RuleErrorTransformer;
use PHPStan\Rules\Rule;
use PHPStan\Rules\UnusedParametersCheck;
use PHPStan\Testing\RuleTestCase;
use PHPUnit\Framework\Attributes\RequiresPhp;
/**
* @extends RuleTestCase<UnusedMethodParametersRule>
*/
class UnusedMethodParametersRuleTest extends RuleTestCase
{
protected function getRule(): Rule
{
return new UnusedMethodParametersRule(
self::getContainer()->getByType(UnusedParametersCheck::class),
self::getContainer()->getByType(RuleErrorTransformer::class),
);
}
public function testRule(): void
{
$this->analyse([__DIR__ . '/data/unused-method-parameters.php'], [
[
'Method UnusedMethodParameters\Foo::completelyUnused() has an unused parameter $unused.',
24,
],
[
'Method UnusedMethodParameters\Foo::immediatelyReassigned() has an unused parameter $x.',
29,
],
[
'Method UnusedMethodParameters\Foo::byRefUnused() has an unused parameter $x.',
57,
],
[
'Method UnusedMethodParameters\Foo::staticCompletelyUnused() has an unused parameter $unused.',
69,
],
]);
}
public function testParameterReadOnlyInCatchOfOverridingThrows(): void
{
$this->analyse([__DIR__ . '/data/unused-method-parameters-overriding-throws.php'], []);
}
public function testParameterReadOnlyInCatchOfImplicitConstructorThrows(): void
{
$this->analyse([__DIR__ . '/data/unused-method-parameters-implicit-constructor-throws.php'], []);
}
public function testParameterCapturedByReference(): void
{
$this->analyse([__DIR__ . '/data/unused-method-parameters-by-ref-use.php'], [
[
'Method UnusedMethodParametersByRefUse\Foo::capturedByReferenceAfterOverwrite() has an unused parameter $expectedCalls.',
23,
],
]);
}
public function testValueFlow(): void
{
$this->analyse([__DIR__ . '/data/unused-method-parameters-value-flow.php'], [
['Method UnusedMethodParametersValueFlow\Foo::unusedParameter() has a parameter $input that only flows into values that are never used.', 8],
['Method UnusedMethodParametersValueFlow\Foo::overwrittenParameter() has an unused parameter $input.', 26],
]);
}
#[RequiresPhp('>= 8.1.0')]
public function testBug15405(): void
{
$this->analyse([__DIR__ . '/data/bug-15405.php'], [
['Method Bug15405\OtherForms::stringCallable() has an unused parameter $context.', 54],
['Method Bug15405\NotReferenced::notReferenced() has an unused parameter $context.', 67],
['Method Bug15405\NotReferenced::calledDirectly() has an unused parameter $context.', 72],
]);
}
}