-
Notifications
You must be signed in to change notification settings - Fork 461
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
Show custom tip for unfound Drupal symbols #2603
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 |
---|---|---|
|
@@ -73,7 +73,7 @@ private function checkConstant(Node\Name $name): ?IdentifierRuleError | |
{ | ||
if (!$this->reflectionProvider->hasConstant($name, null)) { | ||
return RuleErrorBuilder::message(sprintf('Used constant %s not found.', (string) $name)) | ||
->discoveringSymbolsTip() | ||
->discoveringSymbolsTip((string) $name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the passed argument in cases where it's not a class name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So don't do what you asked me to do in the issue?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (I did ask about non-classes in a comment on the issue.)
|
||
->line($name->getLine()) | ||
->identifier('constant.notFound') | ||
->build(); | ||
|
@@ -86,7 +86,7 @@ private function checkFunction(Node\Name $name): ?IdentifierRuleError | |
{ | ||
if (!$this->reflectionProvider->hasFunction($name, null)) { | ||
return RuleErrorBuilder::message(sprintf('Used function %s not found.', (string) $name)) | ||
->discoveringSymbolsTip() | ||
->discoveringSymbolsTip((string) $name) | ||
->line($name->getLine()) | ||
->identifier('function.notFound') | ||
->build(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
use function implode; | ||
use function is_file; | ||
use function sprintf; | ||
use function substr; | ||
|
||
/** | ||
* @api | ||
|
@@ -182,8 +183,11 @@ public function addTip(string $tip): self | |
* @phpstan-this-out self<T&TipRuleError> | ||
* @return self<T&TipRuleError> | ||
*/ | ||
public function discoveringSymbolsTip(): self | ||
public function discoveringSymbolsTip(?string $className = null): self | ||
{ | ||
if (isset($className) && substr($className, 0, 7) === 'Drupal/') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A test would be nice, I'm pretty sure this code is wrong (It's The test should be written for one of the impacted rules, it doesn't matter which one. An error tip is tested with a third array item (https://phpstan.org/developing-extensions/rules#testing-the-rule) - besides the message and the line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right about the backslash. My mistake.
Hmm. I was under the impression that PHPStan supports PHP >= 7.2. The I'll see what I can come up with for a test. |
||
return $this->tip('Learn more at https://github.com/mglaman/phpstan-drupal'); | ||
} | ||
return $this->tip('Learn more at https://phpstan.org/user-guide/discovering-symbols'); | ||
} | ||
|
||
|
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.
Would be nice to do
(string) $node->name)
only once.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 understand your comment below, you actually don't want the argument at all in these cases, since here the symbols are for functions, not classes. Right?