i'm not sure this is exactly the same issue. (We did define a dummy const to quiet this, though.)
I'm not asking about "reference to undeclared constant" in A, but "unreferenced constant" in B.
I agree that we should not assume SOME_CONST
is defined in all subclasses.
However, there's no assumption involved in the inverse conclusion: we don't need to know anything about other subclasses to know that the parent class (A
) does reference static::SOME_CONST
. I don't see any possible question about whether B::SOME_CONST
is referenced or not.
Oh. I was in a hurry and missed the specific issue name - it's should be possible to iterate over all subclasses to check for whether a const of the same name exists, but it's a fairly rare edge case that already has a warning indicating what should be fixed.
I don't think phan has a method to list all subclasses, and that's been avoided since it's inefficient in the daemon mode/language server (and code that requires listing all subclasses is usually the wrong approach analyzing/parsing only part of a codebase, but should be good enough for dead code detection)
i was thinking more along the lines of "i'm looking at this specific subclass, so of course i know what the parent class is, so it's obvious that the const is used." I don't think there would be a need to iterate; it could be determined by looking at that one subclass (and its parent(s)). but i don't know if there's something about how phan parses things that would throw a wrench in that.
thanks for the insights!
Phan uses the language server protocol, so it should work with language server clients, although I haven't tested the language client for phpstorm
https://github.com/phan/phan/wiki/Editor-Support has an example of a command you'd use for "Sublime Text 3", and I'd suggest replacing the psalm command and arguments with the phan command and arguments for the instruction in https://psalm.dev/docs/running_psalm/language_server/#phpstorm
I haven't tried phpstorm, though
ERROR: TypeError: Argument 1 passed to phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService() must be an instance of phpDocumentor\Reflection\DocBlock\object, instance of phpDocumentor\Reflection\FqsenResolver given, called in /Users/<user>/Projects/<name>/vendor/phpdocumentor/reflection-docblock/src/DocBlock/StandardTagFactory.php on line 137 and defined in /Users/<user>/Projects/<name>/vendor/phpdocumentor/reflection-docblock/src/DocBlock/StandardTagFactory.php:159
Stack trace:
#0 /Users/<user>/Projects/<name>/vendor/phpdocumentor/reflection-docblock/src/DocBlock/StandardTagFactory.php(137): phpDocumentor\Reflection\DocBlock\StandardTagFactory->addService(Object(phpDocumentor\Reflection\FqsenResolver), 'phpDocumentor\\R...')
#1 /Users/<user>/Projects/<name>/vendor/phpdocumentor/reflection-docblock/src/DocBlockFactory.php(60): phpDocumentor\Reflection\DocBlock\StandardTagFactory->__construct(Object(phpDocumentor\Reflection\FqsenResolver))
#2 /Users/<user>/Projects/<name>/vendor/felixfbecker/advanced-json-rpc/lib/Dispatcher.php(52): phpDocumentor\Reflection\DocBlockFactory::createInstance()
#3 /Users/<user>/Projects/<name>/vendor/phan/phan/src/Phan/LanguageServer/LanguageServer.php(176): AdvancedJsonRpc\Dispatcher->__construct(Object(Phan\LanguageServer\LanguageServer), '/')
#4 /Users/<user>/Projects/<name>/vendor/phan/phan/src/Phan/LanguageServer/LanguageServer.php(288): Phan\LanguageServer\LanguageServer->__construct(Object(Phan\LanguageServer\ProtocolStreamReader), Object(Phan\LanguageServer\ProtocolStreamWriter), Object(Phan\CodeBase), Object(Closure))
#5 /Users/<user>/Projects/<name>/vendor/phan/phan/src/Phan/LanguageServer/LanguageServer.php(429): Phan\LanguageServer\LanguageServer::Phan\LanguageServer\{closure}(Object(Phan\LanguageServer\ProtocolStreamReader), Object(Phan\LanguageServer\ProtocolStreamWriter))
#6 /Users/<user>/Projects/<name>/vendor/phan/phan/src/Phan/Phan.php(351): Phan\LanguageServer\LanguageServer::run(Object(Phan\CodeBase), Object(Closure), Array)
#7 /Users/<user>/Projects/<name>/vendor/phan/phan/src/phan.php(36): Phan\Phan::analyzeFileList(Object(Phan\CodeBase), Object(Closure))
#8 /Users/<user>/Projects/<name>/vendor/phan/phan/phan(9): require_once('/Users/nicklas....')
#9 {main}
(Phan 2.6.1 crashed due to an uncaught Throwable)
object
exception happened
phpdocumentor/reflection-docblock=^4.3.4.0
should fix that
composer install|upgrade
ran with php 7.2+ and your language server ran with 7.1 locally
Oh, I might have configured something wrong .
Right, the path to the php binary was wrong and pointed to php 7.1, sorry. So I got the intellij-lsp
plugin working with the language server, the errors are displayed but the plugin seems pretty limited. I'll keep using the cli command instead.
It could be issues with case insensitive filesystems or normalizing ./
(e.g. both src and SRC)
Possibly related to gtache/intellij-lsp#91 after a quick search for "diagnostics", could also be related to the way Phan's diagnostics are spread from column 0 of one line to column 0 of the next line.
reflection-docblock
requiring php 7.2+ when run in php 7.1.
You could check the console output in Help > "Toggle Developer Tools" (Ctrl+Shift+I). (if you could post a screenshot, that would help)
I'm assuming you're seeing the path to php 7.2 in vs code's process explorer, but it's worth checking if it's a different installation (e.g. older php, missing php-ast)
You could also try installing an older version of Phan (Ctrl+Shift+X), click on the settings(gear) icon for phan, then "Install Another Version", e.g. 1.2.2 (vscode-php-phan 1.2.3 started adding a check that the files were actually within the project root directory, so it may be an issue with that. Let me know if that works or doesn't work.)
Also, do you see any errors in daemon mode, and do expected diagnostics get emitted (e.g. phan --daemonize-tcp-port default
in one window within the analyzed project directory, phan_client -l src/some_analyzed_file.php
in another
If 1.2.2 works, you could try setting phan.useRelativePatterns to false in 1.2.3
There's a remote possibility it's an issue with case sensitivity (Phan expects the case of folder names to match for events sent by the language client) - probably not symlinks. Enabling phan.enableDebugLog would tell you more in developer tools
tool/pdep
is somewhat related, but not what you wanted - it dumps a graph of the dependencies of classes on other classes. Dumping method/property relationships might be within the scope of what pdep could eventually do, but I'm not the owner of pdep
strlen
, etc /**
* @override
*/
public function addReference(FileRef $file_ref): void
{
if (Config::get_track_references()) {
// Currently, we don't need to track references to PHP-internal methods/functions/constants
// such as PHP_VERSION, strlen(), Closure::bind(), etc.
// This may change in the future.
if ($this->isPHPInternal()) {
return;
}
if ($file_ref instanceof Context && $file_ref->isInFunctionLikeScope() && $file_ref->getFunctionLikeFQSEN() === $this->fqsen) {
// Don't track functions calling themselves
return;
}
$this->reference_list[$file_ref->__toString()] = $file_ref;
}
}