mglaman / drupal-check

Check Drupal code for deprecations and discover bugs via static analysis
GNU General Public License v2.0
333 stars 67 forks source link

Custom method on extended classes are flagged as undefined. #151

Open Beakerboy opened 4 years ago

Beakerboy commented 4 years ago

How is drupal-check installed?

Environment:

Describe the bug Drupal-check flags every call to a custom method as undefined.

Console output Paste the output of the console when running the command with -vvv https://travis-ci.org/github/Beakerboy/sqlsrv/builds/671039483

Beakerboy commented 4 years ago

Some of the “method not found” errors originate from prophecy objects. I installed jangregor/phpstan-prophecy and phpstan/extension-installer, but then get the error:

- /home/travis/build/Beakerboy/drupal-project/vendor/phpstan/phpstan-deprecation-rules/rules.neon
- /home/travis/build/Beakerboy/drupal-project/vendor/mglaman/phpstan-drupal/extension.neon

It can lead to unexpected results. If you're using phpstan/extension-installer, make sure you have removed corresponding neon files from your project config file.

I have no neon file, and I do not see one in your project repository either.

Beakerboy commented 4 years ago

It looks like many of the errors are due to limitations in the way the core doc blocks are used. The function Connection::schema() will always return a child of \Drupal\Core\Database\Schema, not this particular “abstract for all intents and purposes” class.

If I break the following statement

$result = $this->connection->schema()->customFunction();

Into

/** @var \Drupal\Driver\Database\module\Schema $schema */
$schema = $this->connection->schema();
$result = $schema->customFunction();

Then the error goes away. If you think this is the expected behavior, feel free to close it. Prophecy is still an issue though.