Skip to content

Remove PHPStan conflict#149

Merged
mglaman merged 5 commits intomasterfrom
remove-phpstan-conflict
Dec 21, 2020
Merged

Remove PHPStan conflict#149
mglaman merged 5 commits intomasterfrom
remove-phpstan-conflict

Conversation

@mglaman
Copy link
Copy Markdown
Owner

@mglaman mglaman commented Oct 12, 2020

Tries to see if latest PHPStan has anything for fixing #143

Fixes #152 152

@mglaman
Copy link
Copy Markdown
Owner Author

mglaman commented Dec 6, 2020

Here is the problem: \PHPStan\Reflection\BetterReflection\SourceLocator\AutoloadSourceLocator::findReflection

            foreach ($this->classNodes[$identifierName] as $classNode) {
                if ($startLine !== null) {
                    if (\count($classNode->getNode()->attrGroups) > 0 && \PHP_VERSION_ID < 80000) {
                        $startLine--;
                    }
                    if ($startLine !== $classNode->getNode()->getStartLine()) {
                        continue;
                    }
                }

The logic fail is on ($startLine !== $classNode->getNode()->getStartLine()). Due to this reason:

These are lines 10-17 on PhpunitCompatibilityTrait.php

if (!trait_exists(PhpunitVersionDependentTestCompatibilityTrait::class, FALSE)) {
  class_alias("Drupal\TestTools\PhpUnitCompatibility\PhpUnit" . RunnerVersion::getMajor() . "\TestCompatibilityTrait", PhpunitVersionDependentTestCompatibilityTrait::class);
}

/**
 * Makes Drupal's test API forward compatible with multiple versions of PHPUnit.
 */
trait PhpunitCompatibilityTrait {

The reflection from PhpParser for the trait says the startLine is 10 – which is when the if statement is defined. But the autoload source locator is passed in the trait start line of 17. So there is a mismatch and it just quits.

@mglaman
Copy link
Copy Markdown
Owner Author

mglaman commented Dec 6, 2020

If we could have getNode check if we can find the identifier and use the startline from the identifier not whatever is the start line of code.

@mglaman mglaman merged commit 9c53a7b into master Dec 21, 2020
@mglaman mglaman deleted the remove-phpstan-conflict branch December 21, 2020 13:42
markdorison pushed a commit to markdorison/phpstan-drupal that referenced this pull request Jun 17, 2021
Update mglaman/phpstan-drupal and phpstan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

phpstan-drupal should not conflict with phpstan/phpstan versions

1 participant