by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Lexidor Digital
    @lexidor
    Hi, I am so sorry for bothering you all (on new year's day). I've used phan in the past (while version 0.12.13 was still hot of the press). I tried to set up the vscode phan extension, but I must have made a mistake in the process. Running vendor/bin/phan on intentionally broken code reports errors as expected, but there is no red squiggle in the editor. I have the phan extension (1.2.0) enabled globally and I have composer-required phan. My phan.executablePath is set to /usr/bin/php. phan.analyzedProjectDirectory is set to the root of my project. My file association for .php is 'php'. The phan settings in .phan/settings.php check-out (else the stand-alone executable would not work).
    I just realized that I am the only person online. I'll try again tomorrow.
    Lexidor Digital
    @lexidor
    image.png
    Yep, a PEBCAK, as expected.
    Strange that vendor/bin/phan keeps running when it encounters this, but the extension stops running, oh well.
    Tyson Andre
    @TysonAndre

    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)"
            },
    Tyson Andre
    @TysonAndre

    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).

    Lexidor Digital
    @lexidor
    Thanks a ton. I did not know that vscode-php-phan bundled a phan version. I thought it grabbed the one in vendor/bin/phan. Thanks a ton for the new version!
    Sarel van der Walt
    @sarelvdwalt

    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;
    If I change it to protected EntityManager @em then I get (as expected) a PhanSyntaxError because that's a 7.4 thing and I'm on 7.3.
    Tyson Andre
    @TysonAndre
    By default, if Phan emits a 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.
    You'd need to include the file declaring \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)

    Adrian
    @adrian-enspired
    class A {
      public function foo() {
        return static::SOME_CONST;
      }
    }
    
    class B extends A {
      protected const SOME_CONST = 'hello, world';
    }
    This is causing PhanUnreferencedProtectedClassConstant for B::SOME_CONST. Shouldn't phan be able to see the usage in A? using 2.5.0
    Tyson Andre
    @TysonAndre

    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

    Adrian
    @adrian-enspired

    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_CONSTis referenced or not.

    Tyson Andre
    @TysonAndre

    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)

    (And I can't take the normal approach and inherit the reference to the constant in the base class, because there's no constant in the base class)
    I could track references to properties, methods, and class constants that don't exist separately, so they could be inherited
    Adrian
    @adrian-enspired

    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!

    Tyson Andre
    @TysonAndre
    Tracked as phan/phan#3803 - "I could track references to properties, methods, and class constants that don't exist separately, so they could be inherited" (in the base class) was a way that seems viable to do that when just looking at the one subclass
    NicklasWallgren
    @NicklasWallgren
    Hey, has anyone made any effort in adding ide support for phpstorm?
    Tyson Andre
    @TysonAndre

    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

    NicklasWallgren
    @NicklasWallgren
    @TysonAndre Thanks, I gave it a try and got the following exception;
    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)
    Tyson Andre
    @TysonAndre
    What version of reflection-docblock is this
    What version of php is this, I'd have thought phan required 7.1+ to even run the language server, so I'm not sure how the object exception happened
    oh, you're probably using reflection-docblock 5.0.0 and php 7.1
    Downgrading to phpdocumentor/reflection-docblock=^4.3.4.0 should fix that
    I'm guessing composer install|upgrade ran with php 7.2+ and your language server ran with 7.1 locally
    Tyson Andre
    @TysonAndre
    Or install phan in a different directory, or use the phan.phar releases
    NicklasWallgren
    @NicklasWallgren

    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.

    image.png
    The errors are for example duplicated
    Tyson Andre
    @TysonAndre
    It could be related to symlinks if you're using those. The language server deliberately limits errors to the open files. I'm not familiar with the phpstorm client.
    Tyson Andre
    @TysonAndre

    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.

    Tyson Andre
    @TysonAndre
    phan/phan#3826 improves the error message for reflection-docblock requiring php 7.2+ when run in php 7.1.
    Kevin Gregull
    @KevinGregull
    Greetings, I thought I'd come in here to seek some help. I've been trying to get Phan for VS-Code to work for the past 2 Hours, and for some reason it does not seem to work for me. Current steps I've taken: PHP7.2 is installed, got myself AST, disabled all other plugins for vscode, added the analyzed Path in VS-Code. Verified that vs-code can find php by running "php -v". enabled logs for phan. Those tell me that the lang server has started and is accepting connection on localhost:someport (It does also show in vs-codes process explorer). I do have a .phan/config.php file in my project root. Which phan does seem to be able to find, the didChangeWatchedFiles hook does fire on file changes of the config. I have even tried to generate the config with phan --init, because I thought the config might be off. But I am not getting anything. No Error detection, no problems in the problems tab, nothing. If I run my own copy of phan.phar somewhere, it does work and prints a list of errors. I am at a loss here. If you need further info or this is not the place to ask this, please reach out, because I am at a loss. Versions are: Win10 - VS Code 10.43.2 - Analyzer Plugin v 1.2.3
    Tyson Andre
    @TysonAndre

    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

    Tyson Andre
    @TysonAndre

    no problems in the problems tab

    Also, the vscode plugin limits the problems to the currently open files so that responses are fast. If you don't see problems as you're editing files, though, that is a bug.

    Kevin Gregull
    @KevinGregull
    1.2.2 does indeed work for me
    as does disabling relative Patterns
    kapitanluffy
    @kapitanluffy
    Hi guys. Anyone successfully made phan work with sublime text 3?
    I followed the tutorial here: https://github.com/phan/phan/wiki/Editor-Support
    image.png
    but had an error. here's a screenshot
    Tyson Andre
    @TysonAndre
    That's probably a different error from what the https://github.com/sublimelsp/LSP extension encountered. That's what I'd expect to happen if you ran the same command directly in a terminal and then manually sent the running program invalid input (a single blank line)
    https://lsp.readthedocs.io/en/latest/#server-configuration mentions you can configure LSP to log stderr/payloads - I've never used sublime text, though. The instructions were submitted by a user of Phan.
    Adrian
    @__enspired_twitter
    what version does phan start supporting php 7.4? we're on 2.7.1 and it's showing us PhanSyntaxError syntax error, unexpected '?', expecting function (T_FUNCTION) or const (T_CONST) for a nullable property declaration.
    upgrading to 3 is next, but I didn't expect 2.7 to fail ...?