phan --plugin UnknownElementTypePlugin
'exclude_file_list' => [
'Medoo.php',
'SIDB5.php',
'SIDB423.php',
],
./vendor/bin/phan --allow-polyfill-parser
it checks also this files.
./-/
, there is set as include. 'directory_list' => [
'./-/',
],
-/Medoo.php
or ./-/Medoo.php
(I forget which). Or use exclude_file_regex, which allows you to pass patterns to match anything, e.g. those basenames // A regular expression to match files to be excluded
// from parsing and analysis and will not be read at all.
//
// This is useful for excluding groups of test or example
// directories/files, unanalyzable files, or files that
// can't be removed for whatever reason.
// (e.g. '@Test\.php$@', or '@vendor/.*/(tests|Tests)/@')
'exclude_file_regex' => '@^vendor/.*/(tests?|Tests?)/@',
--allow-polyfill-parser
may affect whether issues get emitted, but it doesn't affect the list of files to parse/analyze
$a
has a @param array
or whatever[]
annotation does not clear the error.
vendor/bin/phan
keeps running when it encounters this, but the extension stops running, oh well.
vendor/bin/phan
in phan.analyzedProjectDirectory is newer than the one in /home/lexidor/.vscode/... - The former has the plugin installed, but the latter doesn't. The former would also abort if passed a plugin that didn't exist.
the phanScriptPath can be used to pass a path to phan or phan.phar
"phan.phanScriptPath": {
"type": [
"string",
"null"
],
"default": null,
"markdownDescription": "Optional (Advanced). If provided, this overrides the Phan script to use, e.g. `/path/to/phan_git_checkout/phan`. (Modifying requires restart)"
},
TysonAndre/vscode-php-phan#13 was in the backlog - the largest blocker for that is not having seen any similar language client code to base it or other language client features off of.
Also, I published vscode-php-phan 1.2.1 just now, which updated the bundled phan from 2.3.1 to 2.4.6 (which has that plugin).
I'm being dumb here I think... my composer.json has php version requirement set to >=7.1
"require": {
"php": ">=7.1",
My php version is actually 7.3.14, so that is still in line with the settings.
When I run php vendor/bin/phan --color
I get, among others, this:src/AH/AQueueBundle/Manager/QueueManager.php:13 PhanUndeclaredTypeProperty Property \AH\AQueueBundle\Manager\QueueManager->em has undeclared type \Doctrine\ORM\EntityManager
Here's the thing though, that's only an issue for 7.4 - and only fixable if you use the php 7.4 way of declaring it.
The code in question is this:
class QueueManager
{
/** @var EntityManager $em */
protected $em;
/** @var EntityRepository $repo */
protected $repo;
protected EntityManager @em
then I get (as expected) a PhanSyntaxError because that's a 7.4 thing and I'm on 7.3.
PhanSyntaxError
, it doesn't analyze the file. So that's why you don't get an issue when you change it to protected EntityManager $em
. You can use phan --allow-polyfill-parser
and other options to parse and analyze files even if they do have syntax errors.
\Doctrine\ORM\EntityManager
in your .phan/config.php
's directory_list or file_list, and make sure that it isn't in exclude_file_list
or exclude_file_regex
. To figure out if it's being parsed, you can use phan --dump-parsed-file-list
. Also note that if a file excluded from analysis has a syntax error in the php version used to run Phan, then it's as if the file wasn't parsed as all
that's only an issue for 7.4 - and only fixable if you use the php 7.4 way of declaring it.
I'm not 100% certain of what you meant by that.
Also, Phan currently doesn't use composer.json for anything except phan --init
(but there's a ticket in the backlog for using composer.json elsewhere)
This is deliberate. E.g. if AObject is part of a library, then an application using this library would trigger this bug if they failed to define static::NAME.
I'd recommend suppressing it if you know all subclasses. Either that or adding a dummy value for SOME_CONST in the base class.
It analyzes the classes independently of each other. E.g. it doesn't know if something is a framewerk or a library that will have classes it doesn't know about. Also, (new A())->foo() can be called directly.
See phan/phan#2278 for more details
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