-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38e2c96
commit d026655
Showing
6 changed files
with
178 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Analyser; | ||
|
||
use function array_key_exists; | ||
use function array_values; | ||
use function count; | ||
use function is_array; | ||
|
||
/** | ||
* @phpstan-import-type LinesToIgnore from FileAnalyserResult | ||
*/ | ||
class LocalIgnoresProcessor | ||
{ | ||
|
||
/** | ||
* @param list<Error> $temporaryFileErrors | ||
* @param LinesToIgnore $linesToIgnore | ||
* @param LinesToIgnore $unmatchedLineIgnores | ||
*/ | ||
public function process( | ||
array $temporaryFileErrors, | ||
array $linesToIgnore, | ||
array $unmatchedLineIgnores, | ||
): LocalIgnoresProcessorResult | ||
{ | ||
$fileErrors = []; | ||
$locallyIgnoredErrors = []; | ||
foreach ($temporaryFileErrors as $tmpFileError) { | ||
$line = $tmpFileError->getLine(); | ||
if ( | ||
$line !== null | ||
&& $tmpFileError->canBeIgnored() | ||
&& array_key_exists($tmpFileError->getFile(), $linesToIgnore) | ||
&& array_key_exists($line, $linesToIgnore[$tmpFileError->getFile()]) | ||
) { | ||
$identifiers = $linesToIgnore[$tmpFileError->getFile()][$line]; | ||
if ($identifiers === null) { | ||
$locallyIgnoredErrors[] = $tmpFileError; | ||
unset($unmatchedLineIgnores[$tmpFileError->getFile()][$line]); | ||
continue; | ||
} | ||
|
||
if ($tmpFileError->getIdentifier() === null) { | ||
$fileErrors[] = $tmpFileError; | ||
continue; | ||
} | ||
|
||
foreach ($identifiers as $i => $ignoredIdentifier) { | ||
if ($ignoredIdentifier !== $tmpFileError->getIdentifier()) { | ||
continue; | ||
} | ||
|
||
unset($identifiers[$i]); | ||
|
||
if (count($identifiers) > 0) { | ||
$linesToIgnore[$tmpFileError->getFile()][$line] = array_values($identifiers); | ||
} else { | ||
unset($linesToIgnore[$tmpFileError->getFile()][$line]); | ||
} | ||
|
||
if ( | ||
array_key_exists($tmpFileError->getFile(), $unmatchedLineIgnores) | ||
&& array_key_exists($line, $unmatchedLineIgnores[$tmpFileError->getFile()]) | ||
) { | ||
$unmatchedIgnoredIdentifiers = $unmatchedLineIgnores[$tmpFileError->getFile()][$line]; | ||
if (is_array($unmatchedIgnoredIdentifiers)) { | ||
foreach ($unmatchedIgnoredIdentifiers as $j => $unmatchedIgnoredIdentifier) { | ||
if ($ignoredIdentifier !== $unmatchedIgnoredIdentifier) { | ||
continue; | ||
} | ||
|
||
unset($unmatchedIgnoredIdentifiers[$j]); | ||
|
||
if (count($unmatchedIgnoredIdentifiers) > 0) { | ||
$unmatchedLineIgnores[$tmpFileError->getFile()][$line] = array_values($unmatchedIgnoredIdentifiers); | ||
} else { | ||
unset($unmatchedLineIgnores[$tmpFileError->getFile()][$line]); | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
|
||
$locallyIgnoredErrors[] = $tmpFileError; | ||
continue 2; | ||
} | ||
} | ||
|
||
$fileErrors[] = $tmpFileError; | ||
} | ||
|
||
return new LocalIgnoresProcessorResult( | ||
$fileErrors, | ||
$locallyIgnoredErrors, | ||
$linesToIgnore, | ||
$unmatchedLineIgnores, | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Analyser; | ||
|
||
/** | ||
* @phpstan-import-type LinesToIgnore from FileAnalyserResult | ||
*/ | ||
class LocalIgnoresProcessorResult | ||
{ | ||
|
||
/** | ||
* @param list<Error> $fileErrors | ||
* @param list<Error> $locallyIgnoredErrors | ||
* @param LinesToIgnore $linesToIgnore | ||
* @param LinesToIgnore $unmatchedLineIgnores | ||
*/ | ||
public function __construct( | ||
private array $fileErrors, | ||
private array $locallyIgnoredErrors, | ||
private array $linesToIgnore, | ||
private array $unmatchedLineIgnores, | ||
) | ||
{ | ||
} | ||
|
||
/** | ||
* @return list<Error> | ||
*/ | ||
public function getFileErrors(): array | ||
{ | ||
return $this->fileErrors; | ||
} | ||
|
||
/** | ||
* @return list<Error> | ||
*/ | ||
public function getLocallyIgnoredErrors(): array | ||
{ | ||
return $this->locallyIgnoredErrors; | ||
} | ||
|
||
/** | ||
* @return LinesToIgnore | ||
*/ | ||
public function getLinesToIgnore(): array | ||
{ | ||
return $this->linesToIgnore; | ||
} | ||
|
||
/** | ||
* @return LinesToIgnore | ||
*/ | ||
public function getUnmatchedLineIgnores(): array | ||
{ | ||
return $this->unmatchedLineIgnores; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters