Skip to content

Commit

Permalink
AccessPropertiesRule - tip with article link
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Mar 31, 2023
1 parent 11f8d96 commit e6e2d1a
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Rules/Properties/AccessPropertiesRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ private function processSingleProperty(Scope $scope, PropertyFetch $node, string
));
if ($typeResult->getTip() !== null) {
$ruleErrorBuilder->tip($typeResult->getTip());
} else {
$ruleErrorBuilder->tip('Learn more: <fg=cyan>https://phpstan.org/blog/solving-phpstan-access-to-undefined-property</>');
}

return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ protected function getRule(): Rule

public function testRule(): void
{
$tipText = 'Learn more: <fg=cyan>https://phpstan.org/blog/solving-phpstan-access-to-undefined-property</>';
$this->analyse([__DIR__ . '/data/access-properties-assign.php'], [
[
'Access to an undefined property TestAccessPropertiesAssign\AccessPropertyWithDimFetch::$foo.',
10,
$tipText,
],
[
'Access to an undefined property TestAccessPropertiesAssign\AccessPropertyWithDimFetch::$foo.',
15,
$tipText,
],
]);
}
Expand All @@ -40,42 +43,52 @@ public function testRuleAssignOp(): void
if (PHP_VERSION_ID < 70400) {
self::markTestSkipped('Test requires PHP 7.4.');
}

$tipText = 'Learn more: <fg=cyan>https://phpstan.org/blog/solving-phpstan-access-to-undefined-property</>';
$this->analyse([__DIR__ . '/data/access-properties-assign-op.php'], [
[
'Access to an undefined property TestAccessProperties\AssignOpNonexistentProperty::$flags.',
15,
$tipText,
],
]);
}

public function testRuleExpressionNames(): void
{
$tipText = 'Learn more: <fg=cyan>https://phpstan.org/blog/solving-phpstan-access-to-undefined-property</>';
$this->analyse([__DIR__ . '/data/properties-from-variable-into-object.php'], [
[
'Access to an undefined property PropertiesFromVariableIntoObject\Foo::$noop.',
26,
$tipText,
],
]);
}

public function testRuleExpressionNames2(): void
{
$tipText = 'Learn more: <fg=cyan>https://phpstan.org/blog/solving-phpstan-access-to-undefined-property</>';
$this->analyse([__DIR__ . '/data/properties-from-array-into-object.php'], [
[
'Access to an undefined property PropertiesFromArrayIntoObject\Foo::$noop.',
42,
$tipText,
],
[
'Access to an undefined property PropertiesFromArrayIntoObject\Foo::$noop.',
54,
$tipText,
],
[
'Access to an undefined property PropertiesFromArrayIntoObject\Foo::$noop.',
69,
$tipText,
],
[
'Access to an undefined property PropertiesFromArrayIntoObject\Foo::$noop.',
110,
$tipText,
],
]);
}
Expand Down
Loading

0 comments on commit e6e2d1a

Please sign in to comment.