Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,29 @@ jobs:
echo "$OUTPUT"
../bashunit assert contains 'Result cache not used because the metadata do not match: executedFilesHashes' "$OUTPUT"
../bashunit assert contains 'Foo.php:10:Method ResultCacheE2EBootstrap\Foo::doFoo() should return int but returns string.' "$OUTPUT"
- script: |
cd e2e/result-cache-trait-ignore
rm -rf tmp/cache tmp/resultCache.php
../../bin/phpstan analyse --no-progress --error-format raw -vvv > tmp/cold.txt 2> tmp/cold-log.txt || test "$?" -eq 1
../../bin/phpstan analyse --no-progress --error-format raw -vvv > tmp/warm.txt 2> tmp/warm-log.txt || test "$?" -eq 1
grep -F 'Result cache is saved.' tmp/cold-log.txt
grep -F 'Result cache restored. 0 files will be reanalysed.' tmp/warm-log.txt
grep -F 'MyTrait.php (in context of class Repro\A):10:Ignore with identifier method.notFound has no comment.' tmp/cold.txt
grep -F 'MyTrait.php (in context of class Repro\B):10:Ignore with identifier method.notFound has no comment.' tmp/cold.txt
grep -F 'MyTrait.php (in context of class Repro\A):12:Ignoring all errors on a line is not allowed.' tmp/cold.txt
grep -F 'MyTrait.php (in context of class Repro\B):12:Ignoring all errors on a line is not allowed.' tmp/cold.txt
diff -u tmp/cold.txt tmp/warm.txt
cp src/A.php tmp/A.php
../../bin/phpstan analyse --no-progress --error-format raw --tmp-file tmp/A.php --instead-of src/A.php > tmp/editor.txt 2> tmp/editor-log.txt || test "$?" -eq 1
grep -F 'MyTrait.php (in context of class Repro\A):10:Ignore with identifier method.notFound has no comment.' tmp/editor.txt
grep -F 'MyTrait.php (in context of class Repro\A):12:Ignoring all errors on a line is not allowed.' tmp/editor.txt
grep -v 'use MyTrait;' tmp/A.php > src/A.php
../../bin/phpstan analyse --no-progress --error-format raw -vvv > tmp/partial.txt 2> tmp/partial-log.txt || test "$?" -eq 1
grep -F 'Result cache restored. 1 file will be reanalysed.' tmp/partial-log.txt
if grep -F 'in context of class Repro\A' tmp/partial.txt; then exit 1; fi
grep -F 'MyTrait.php (in context of class Repro\B):10:Ignore with identifier method.notFound has no comment.' tmp/partial.txt
grep -F 'MyTrait.php (in context of class Repro\B):12:Ignoring all errors on a line is not allowed.' tmp/partial.txt
cp tmp/A.php src/A.php
- script: |
cd e2e/result-cache-traits
../../bin/phpstan analyse
Expand Down
6 changes: 6 additions & 0 deletions e2e/result-cache-trait-ignore/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
level: 5
paths:
- src
tmpDir: tmp
reportIgnoresWithoutComments: true
8 changes: 8 additions & 0 deletions e2e/result-cache-trait-ignore/src/A.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Repro;

class A
{
use MyTrait;
}
8 changes: 8 additions & 0 deletions e2e/result-cache-trait-ignore/src/B.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Repro;

class B
{
use MyTrait;
}
14 changes: 14 additions & 0 deletions e2e/result-cache-trait-ignore/src/MyTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Repro;

trait MyTrait
{
public function doFoo(): void
{
// @phpstan-ignore method.notFound
$this->undefinedMethod();
// @phpstan-ignore-next-line
$this->anotherUndefinedMethod();
}
}
2 changes: 2 additions & 0 deletions e2e/result-cache-trait-ignore/tmp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.*
9 changes: 3 additions & 6 deletions src/Analyser/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,20 @@ public function getFilePath(): string

public function changeFilePath(string $newFilePath): self
{
if ($this->traitFilePath !== null) {
throw new ShouldNotHappenException('Errors in traits not yet supported');
}

return new self(
$this->message,
$newFilePath,
$this->traitFilePath !== null ? $this->file : $newFilePath,
$this->line,
$this->canBeIgnored,
$newFilePath,
null,
$this->traitFilePath,
$this->tip,
$this->nodeLine,
$this->nodeType,
$this->identifier,
$this->metadata,
$this->fixedErrorDiff,
$this->traitContexts,
);
}

Expand Down
8 changes: 4 additions & 4 deletions src/Analyser/FileAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ public function analyseFile(
$ignoredFile,
$line,
false,
$ignoredFile,
null,
$file,
$nodeCallback->getTraitFilePaths()[$ignoredFile] ?? null,
'Use @phpstan-ignore with an identifier and a comment (in parentheses).',
))->withIdentifier('ignore.allLineErrors');
unset($linesToIgnore[$ignoredFile][$line]);
Expand All @@ -174,8 +174,8 @@ public function analyseFile(
$ignoredFile,
$line,
false,
$ignoredFile,
null,
$file,
$nodeCallback->getTraitFilePaths()[$ignoredFile] ?? null,
'Explain why this ignore is necessary in parentheses after the identifier.',
))->withIdentifier('ignore.noComment');
unset($linesToIgnore[$ignoredFile][$line]);
Expand Down
12 changes: 12 additions & 0 deletions src/Analyser/FileAnalyserCallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ final class FileAnalyserCallback
/** @var LinesToIgnore */
private array $unmatchedLineIgnores;

/** @var array<string, string> */
private array $traitFilePaths = [];

/**
* The registries answer per node class and cache that themselves; this keeps the answer for the
* classes met in this file, so that the walk does not ask them again for every node of a class.
Expand Down Expand Up @@ -119,6 +122,7 @@ public function __invoke(Node $node, Scope $scope): void

$traitFileName = $node->getTraitReflection()->getFileName();
if ($traitFileName !== null) {
$this->traitFilePaths[$fileDescription] = $traitFileName;
$this->processedFiles[] = $traitFileName;
}
}
Expand Down Expand Up @@ -314,6 +318,14 @@ public function getUnmatchedLineIgnores(): array
return $this->unmatchedLineIgnores;
}

/**
* @return array<string, string>
*/
public function getTraitFilePaths(): array
{
return $this->traitFilePaths;
}

/**
* @return list<Error>
*/
Expand Down
Loading