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;
}
}
I noticed phan doesn't know how to parse callbacks of the form
call_user_func(array('B', 'parent::who'));
Where B is a class extending class A both defining Who.
any idea how I can hack this in?
Hello,
With the method below:
private function getDocumentRoot(): string
{
return realpath(__DIR__ . "/web/");
}
Phan returns the following error:
PhanPossiblyFalseTypeReturn Returning realpath((__DIR__ . '/web/')) of type false|string but getDocumentRoot() is declared to return string (false is incompatible)
It is an entirely valid error: realpath()
can return string or false, while getDocumentRoot()
is declared to return a string exclusively.
My question is: how to address this issue in the state of the art?
The options I thought about are the following:
1) Specific Exception:
private function getDocumentRoot(): string
{
$result = realpath(__DIR__ . "/web/");
if (!is_string($result)) {
throw new \RuntimeException("Cannot compute document root");
}
return $result;
}
While this makes the Phan error dissappear, it just changes the way to catch the exception from \TypeError
to \RuntimeException
. Somehow it feels non natural to remap the \TypeError
to something else, this leads to the next option:
2) Throwing \TypeError manually:
private function getDocumentRoot(): string
{
$result = realpath(__DIR__ . "/web/");
if (!is_string($result)) {
throw new \TypeError("Cannot compute document root");
}
return $result;
}
As option 1), it "solves" the reported issue, however it re-implements the natural behaviour of PHP itself: it really feels like boilerplate code.
3) Acknowledging that a TypeError
can occur:
/**
* @throws \TypeError
*/
private function getDocumentRoot(): string
{
return realpath(__DIR__ . "/web/");
}
While potentially no additional code involved, it could "mark" that a \TypeError
is possible and should not be reported as something not handled. However, using @throws
does not make the issue dissappear.
4) Suppressing the issue locally:
/**
* @suppress PhanPossiblyFalseTypeReturn
*/
private function getDocumentRoot(): string
{
return realpath(__DIR__ . "/web/");
}
This is supressing the issue, however, I feel that @suppress
is more like a workaround to tackle edge cases while this seems pretty common. It also feels more like silencing it over declaring an intention.
I'd like to know how you usually deal with that situation and what the best practices are.
While potentially no additional code involved, it could "mark" that a \TypeError is possible and should not be reported as something not handled. However, using @throws does not make the issue dissappear.
I don't plan to implement any support for making @throws
hide phan errors/notices - In general, in code being analyzed, it's also possible to throw a TypeError explicitly. It's also unclear what @throws Error
and @throws Throwable
would/should do since they're parent types.
Again, depending on the specifics of the situation, I've implemented 1/2/4 in the past to work around notices. To add, I'd personally change 4. to add a description such as @suppress PhanPossiblyFalseTypeReturn in abnormal situtations where PHP can't find the directory or the directory was removed, this will throw a TypeError, and there's no great way to handle this
(or bad entries in the realpath cache, or nfs wierdness)