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
17 changes: 17 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,23 @@ jobs:
../../bin/phpstan clear-result-cache
../bashunit -a exit_code "0" "../../bin/phpstan analyse --error-format=raw -c with-full-baseline.neon"
../bashunit -a exit_code "0" "../../bin/phpstan analyse --error-format=raw -c with-full-baseline.neon"
- script: |
cd e2e/baseline-trait-context-own-error
# A using class may report its own error with the same message and identifier
# as an error deduplicated directly into the trait: --generate-baseline records
# the class's own occurrence under the class path and the deduplicated error
# under the trait path. The trait-pathed entry hides the deduplicated error for
# every using class, so the class-pathed entry accounts only for the class's
# own occurrence: the generated baseline holds on re-run, with both an empty
# and a primed result cache.
../../bin/phpstan clear-result-cache
../../bin/phpstan --generate-baseline=baseline.neon
../bashunit -a contains 'path: src/AMailer.php' "$(cat baseline.neon)"
../bashunit -a contains 'path: src/SomeTrait.php' "$(cat baseline.neon)"
../bashunit -a not_contains 'BMailer.php' "$(cat baseline.neon)"
../../bin/phpstan clear-result-cache
../bashunit -a exit_code "0" "../../bin/phpstan analyse --error-format=raw -c with-baseline.neon"
../bashunit -a exit_code "0" "../../bin/phpstan analyse --error-format=raw -c with-baseline.neon"
- script: |
cd e2e/result-cache-meta-extension
composer install
Expand Down
1 change: 1 addition & 0 deletions e2e/baseline-trait-context-own-error/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
baseline.neon
6 changes: 6 additions & 0 deletions e2e/baseline-trait-context-own-error/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
level: 4
paths:
- src
parallel:
maximumNumberOfProcesses: 1
24 changes: 24 additions & 0 deletions e2e/baseline-trait-context-own-error/src/AMailer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php declare(strict_types = 1);

namespace BaselineTraitContextOwnError;

final class AMailer
{

use SomeTrait;

public function send(bool $flag, ?string $value): void
{
$hash = null;
if ($value !== null) {
if ($flag) {
$hash = $value;
}
}

if ($hash !== null && $flag) {
echo $hash;
}
}

}
10 changes: 10 additions & 0 deletions e2e/baseline-trait-context-own-error/src/BMailer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php declare(strict_types = 1);

namespace BaselineTraitContextOwnError;

final class BMailer
{

use SomeTrait;

}
22 changes: 22 additions & 0 deletions e2e/baseline-trait-context-own-error/src/SomeTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php declare(strict_types = 1);

namespace BaselineTraitContextOwnError;

trait SomeTrait
{

public function run(bool $flag, ?string $value): void
{
$hash = null;
if ($value !== null) {
if ($flag) {
$hash = $value;
}
}

if ($hash !== null && $flag) {
echo $hash;
}
}

}
3 changes: 3 additions & 0 deletions e2e/baseline-trait-context-own-error/with-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
includes:
- phpstan.neon
- baseline.neon
22 changes: 22 additions & 0 deletions src/Analyser/Ignore/IgnoredErrorHelperResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,28 @@ public function process(
$traitContexts = $error->getTraitContexts();
if (count($traitContexts) > 0) {
$errorTraitFilePath = $error->getTraitFilePath();

// An entry scoped to the trait file hides the deduplicated error for every
// using class: it takes precedence over the class-scoped entries, which then
// account only for the errors reported in the class files themselves. This
// is what --generate-baseline records when a using class has its own
// occurrence of the same error (same message and identifier).
if ($errorTraitFilePath !== null) {
$normalizedTraitFilePath = $this->fileHelper->normalizePath($errorTraitFilePath);
if (isset($this->ignoreErrorsByFile[$normalizedTraitFilePath])) {
$matchingTraitFileIgnoreErrors = $ignoreErrorsByFileAndIdentifier[$normalizedTraitFilePath][$identifierKey]
??= self::filterIgnoreErrorsByIdentifier($this->ignoreErrorsByFile[$normalizedTraitFilePath], $identifier);
foreach ($matchingTraitFileIgnoreErrors as $ignoreError) {
$i = $ignoreError['index'];
$ignore = $ignoreError['ignoreError'];
if (!$processIgnoreError($error, $i, $ignore)) {
$ignoredErrors[] = [$error, $ignore];
continue 2;
}
}
}
}

$remainingContexts = $traitContexts;
foreach (array_keys($traitContexts) as $contextFilePath) {
$contextError = $error->asReportedInTraitContext($contextFilePath);
Expand Down
Loading