Skip to content
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

UnusedMethod false positive #2154

Closed
iluuu1994 opened this issue Sep 20, 2019 · 10 comments

Comments

@iluuu1994
Copy link
Contributor

commented Sep 20, 2019

image

ERROR: UnusedMethod - lib/command/TestCommand.php:134:22 - Cannot find any calls to private method sv\command\TestCommand::runProcess

Unfortunately, this only happens on our CI server even though I run Psalm in the exact same way.

The code loosely translates to this:

class Foo {
  public function bar(): void {
    $projectDir = __DIR__;
    $checks = [];

    if (file_exists($projectDir . '/vendor/friendsofphp/php-cs-fixer/php-cs-fixer')) {
      $checks['php-cs-fixer'] = ['php', '-d', 'memory_limit=-1', $projectDir . '/vendor/friendsofphp/php-cs-fixer/php-cs-fixer', 'fix', '--dry-run', '--ansi'];
    }

    if (file_exists($projectDir . '/vendor/phpstan/phpstan/bin/phpstan')) {
      $checks['phpstan'] = ['php', '-d', 'memory_limit=-1', $projectDir . '/vendor/phpstan/phpstan/bin/phpstan', 'analyze', '-c', 'phpstan.neon', '--ansi'];
    }

    if (file_exists($projectDir . '/vendor/vimeo/psalm/psalm')) {
      $checks['psalm'] = ['php', '-d', 'memory_limit=-1', $projectDir . '/vendor/vimeo/psalm/psalm', '--show-info=false'];
    }

    if (file_exists($projectDir . '/vendor/phpunit/phpunit/phpunit')) {
      $checks['phpunit'] = ['php', '-d', 'memory_limit=-1', $projectDir . '/vendor/phpunit/phpunit/phpunit', '--configuration', 'phpunit.xml.dist'];
    }

    foreach ($checks as $checkName => $checkArguments) {
      $this->baz($checkName, $checkArguments);
    }
  }

  private function baz(string $name, array $parts): void {
    echo $name . "\n";
    exec(join(" ", $parts));
  }
}

(new Foo())->bar();

https://psalm.dev/r/4a8a27c2c9

Can I provide more helpful information?

Both CI and local run with the newest master (f6b0de0).

@muglug

This comment has been minimized.

Copy link
Member

commented Sep 20, 2019

Very weird. Does Psalm run with --threads=X and, if so, does the message remain when running in a single process?

@iluuu1994

This comment has been minimized.

Copy link
Contributor Author

commented Sep 20, 2019

CI always runs on a single thread. Running it locally in a single thread doesn't result in the error.

@muglug

This comment has been minimized.

Copy link
Member

commented Sep 20, 2019

Can you isolate Psalm to just run on the file in question? I usually do this via the Psalm config.

@iluuu1994

This comment has been minimized.

Copy link
Contributor Author

commented Sep 20, 2019

You mean by just doing this?

<projectFiles>
    <file name="lib/command/TestCommand.php" />
</projectFiles>
@iluuu1994

This comment has been minimized.

Copy link
Contributor Author

commented Sep 20, 2019

It's super annoying to debug this in the CI environment. I'll try tonight by using the Docker image locally.

@muglug

This comment has been minimized.

Copy link
Member

commented Sep 20, 2019

Ok, sorry!

@iluuu1994

This comment has been minimized.

Copy link
Contributor Author

commented Sep 20, 2019

It's no problem, I've suppressed the issue and our build is green. I'll see if I can figure out what's going on here.

@iluuu1994

This comment has been minimized.

Copy link
Contributor Author

commented Sep 23, 2019

Unfortunately it's not reproducible in the Docker container either. 🙃 It only fails on the actual CI that then runs the Docker container.

@muglug

This comment has been minimized.

Copy link
Member

commented Sep 25, 2019

If you have control over the CI (and it won't block other people) you could narrow down to just that file as above. We've had issues at Vimeo in the past where things would break because dockerised environments running on Apple machines were case-insensitive, whereas dockerised envs running on Linux machines are very much case-sensitive.

@muglug

This comment has been minimized.

Copy link
Member

commented Sep 25, 2019

I'm going to close in the meantime.

@muglug muglug closed this Sep 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.