Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 6 additions & 1 deletion src/Node/InClassMethodNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ public function __construct(
private Node\Stmt\ClassMethod $originalNode,
)
{
parent::__construct($originalNode->getAttributes());
$attributes = $originalNode->getAttributes();
$nameStartLine = $originalNode->name->getStartLine();
if ($nameStartLine >= $originalNode->getStartLine() && $nameStartLine <= $originalNode->getEndLine()) {
$attributes['startLine'] = $nameStartLine;
}
parent::__construct($attributes);
}

public function getClassReflection(): ClassReflection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ public function testMethodRule(): void
],
[
'Deprecated',
15,
16,
],
[
'Deprecated: msg',
21,
22,
],
[
'Deprecated: msg2',
27,
28,
],
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function testRule(): void
$this->analyse([__DIR__ . '/data/attribute-reflection.php'], [
[
'#[AttributeReflectionTest\MyAttr(one: 7, two: 8)], $test: #[AttributeReflectionTest\MyAttr(one: 9, two: 10)]',
28,
29,
],
[
'#[AttributeReflectionTest\MyAttr()]',
Expand Down
6 changes: 3 additions & 3 deletions tests/PHPStan/Rules/Methods/MethodSignatureRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,15 @@ public function testBug3997(): void
$this->analyse([__DIR__ . '/data/bug-3997.php'], [
[
'Return type (int) of method Bug3997\Baz::count() should be covariant with return type (int<0, max>) of method Countable::count()',
35,
36,
],
[
'Return type (int) of method Bug3997\Lorem::count() should be covariant with return type (int<0, max>) of method Countable::count()',
49,
50,
],
[
'Return type (string) of method Bug3997\Ipsum::count() should be compatible with return type (int<0, max>) of method Countable::count()',
63,
64,
],
]);
}
Expand Down
20 changes: 16 additions & 4 deletions tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ public function testBug10101(): void
$this->analyse([__DIR__ . '/data/bug-10101.php'], [
[
'Return type mixed of method Bug10101\B::next() is not covariant with return type void of method Bug10101\A::next().',
10,
11,
],
]);
}
Expand Down Expand Up @@ -690,7 +690,7 @@ public function testBug10149(): void
$errors = [
[
'Method Bug10149\StdSat::__get() has #[\Override] attribute but does not override any method.',
10,
11,
],
];
$this->analyse([__DIR__ . '/data/bug-10149.php'], $errors);
Expand Down Expand Up @@ -729,11 +729,11 @@ public function testOverrideAttribute(): void
$this->analyse([__DIR__ . '/data/override-attribute.php'], [
[
'Method OverrideAttribute\Bar::test2() has #[\Override] attribute but does not override any method.',
24,
25,
],
[
'Method OverrideAttribute\ChildOfParentWithConstructor::__construct() has #[\Override] attribute but does not override any method.',
42,
43,
],
]);
}
Expand Down Expand Up @@ -853,4 +853,16 @@ public function testFixWithTabs(): void
$this->fix(__DIR__ . '/data/fix-with-tabs.php', __DIR__ . '/data/fix-with-tabs.php.fixed');
}

#[RequiresPhp('>= 8.0')]
public function testBug14398(): void
{
$this->phpVersionId = PHP_VERSION_ID;
$this->analyse([__DIR__ . '/data/bug-14398.php'], [
[
'Private method Bug14398\ChildPrivateOverridesProtected::calculate() overriding protected method Bug14398\BaseProtectedMethod::calculate() should be protected or public.',
17,
],
]);
}

}
21 changes: 21 additions & 0 deletions tests/PHPStan/Rules/Methods/data/bug-14398.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php // lint >= 8.0

namespace Bug14398;

class BaseProtectedMethod
{
protected function calculate(): int
{
return 42;
}
}

class ChildPrivateOverridesProtected extends BaseProtectedMethod
{
// PHPStan: Private method … overriding protected method … should be protected or public.
#[Override]
private function calculate(): int
{
return 99;
}
}
Loading