Skip to content

Commit

Permalink
IgnoredErrorHelper does not produce warnings, only errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Sep 16, 2021
1 parent 01321a6 commit 915fa2e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 26 deletions.
15 changes: 7 additions & 8 deletions src/Analyser/IgnoredErrorHelper.php
Expand Up @@ -41,7 +41,6 @@ public function initialize(): IgnoredErrorHelperResult
{
$otherIgnoreErrors = [];
$ignoreErrorsByFile = [];
$warnings = [];
$errors = [];
foreach ($this->ignoreErrors as $i => $ignoreError) {
try {
Expand Down Expand Up @@ -89,11 +88,11 @@ public function initialize(): IgnoredErrorHelperResult
$validationResult = $this->ignoredRegexValidator->validate($ignoreMessage);
$ignoredTypes = $validationResult->getIgnoredTypes();
if (count($ignoredTypes) > 0) {
$warnings[] = $this->createIgnoredTypesWarning($ignoreMessage, $ignoredTypes);
$errors[] = $this->createIgnoredTypesError($ignoreMessage, $ignoredTypes);
}

if ($validationResult->hasAnchorsInTheMiddle()) {
$warnings[] = $this->createAnchorInTheMiddleWarning($ignoreMessage);
$errors[] = $this->createAnchorInTheMiddleError($ignoreMessage);
}

if ($validationResult->areAllErrorsIgnored()) {
Expand All @@ -109,11 +108,11 @@ public function initialize(): IgnoredErrorHelperResult
$validationResult = $this->ignoredRegexValidator->validate($ignoreMessage);
$ignoredTypes = $validationResult->getIgnoredTypes();
if (count($ignoredTypes) > 0) {
$warnings[] = $this->createIgnoredTypesWarning($ignoreMessage, $ignoredTypes);
$errors[] = $this->createIgnoredTypesError($ignoreMessage, $ignoredTypes);
}

if ($validationResult->hasAnchorsInTheMiddle()) {
$warnings[] = $this->createAnchorInTheMiddleWarning($ignoreMessage);
$errors[] = $this->createAnchorInTheMiddleError($ignoreMessage);
}

if ($validationResult->areAllErrorsIgnored()) {
Expand All @@ -127,15 +126,15 @@ public function initialize(): IgnoredErrorHelperResult
}
}

return new IgnoredErrorHelperResult($this->fileHelper, $errors, $warnings, $otherIgnoreErrors, $ignoreErrorsByFile, $this->ignoreErrors, $this->reportUnmatchedIgnoredErrors);
return new IgnoredErrorHelperResult($this->fileHelper, $errors, $otherIgnoreErrors, $ignoreErrorsByFile, $this->ignoreErrors, $this->reportUnmatchedIgnoredErrors);
}

/**
* @param string $regex
* @param array<string, string> $ignoredTypes
* @return string
*/
private function createIgnoredTypesWarning(string $regex, array $ignoredTypes): string
private function createIgnoredTypesError(string $regex, array $ignoredTypes): string
{
return sprintf(
"Ignored error %s has an unescaped '|' which leads to ignoring more errors than intended. Use '\\|' instead.\n%s",
Expand All @@ -149,7 +148,7 @@ private function createIgnoredTypesWarning(string $regex, array $ignoredTypes):
);
}

private function createAnchorInTheMiddleWarning(string $regex): string
private function createAnchorInTheMiddleError(string $regex): string
{
return sprintf("Ignored error %s has an unescaped anchor '$' in the middle. This leads to unintended behavior. Use '\\$' instead.", $regex);
}
Expand Down
14 changes: 0 additions & 14 deletions src/Analyser/IgnoredErrorHelperResult.php
Expand Up @@ -12,9 +12,6 @@ class IgnoredErrorHelperResult
/** @var string[] */
private array $errors;

/** @var string[] */
private array $warnings;

/** @var array<array<mixed>> */
private array $otherIgnoreErrors;

Expand All @@ -29,7 +26,6 @@ class IgnoredErrorHelperResult
/**
* @param FileHelper $fileHelper
* @param string[] $errors
* @param string[] $warnings
* @param array<array<mixed>> $otherIgnoreErrors
* @param array<string, array<array<mixed>>> $ignoreErrorsByFile
* @param (string|mixed[])[] $ignoreErrors
Expand All @@ -38,7 +34,6 @@ class IgnoredErrorHelperResult
public function __construct(
FileHelper $fileHelper,
array $errors,
array $warnings,
array $otherIgnoreErrors,
array $ignoreErrorsByFile,
array $ignoreErrors,
Expand All @@ -47,7 +42,6 @@ public function __construct(
{
$this->fileHelper = $fileHelper;
$this->errors = $errors;
$this->warnings = $warnings;
$this->otherIgnoreErrors = $otherIgnoreErrors;
$this->ignoreErrorsByFile = $ignoreErrorsByFile;
$this->ignoreErrors = $ignoreErrors;
Expand All @@ -62,14 +56,6 @@ public function getErrors(): array
return $this->errors;
}

/**
* @return string[]
*/
public function getWarnings(): array
{
return $this->warnings;
}

/**
* @param Error[] $errors
* @param string[] $analysedFiles
Expand Down
4 changes: 1 addition & 3 deletions src/Command/AnalyseApplication.php
Expand Up @@ -92,7 +92,6 @@ public function analyse(
$ignoredErrorHelperResult = $this->ignoredErrorHelper->initialize();
if (count($ignoredErrorHelperResult->getErrors()) > 0) {
$errors = $ignoredErrorHelperResult->getErrors();
$warnings = [];
$internalErrors = [];
$savedResultCache = false;
if ($errorOutput->isDebug()) {
Expand All @@ -113,7 +112,6 @@ public function analyse(
$analyserResult = $resultCacheResult->getAnalyserResult();
$internalErrors = $analyserResult->getInternalErrors();
$errors = $ignoredErrorHelperResult->process($analyserResult->getErrors(), $onlyFiles, $files, count($internalErrors) > 0 || $analyserResult->hasReachedInternalErrorsCountLimit());
$warnings = $ignoredErrorHelperResult->getWarnings();
$savedResultCache = $resultCacheResult->isSaved();
if ($analyserResult->hasReachedInternalErrorsCountLimit()) {
$errors[] = sprintf('Reached internal errors count limit of %d, exiting...', $this->internalErrorsCountLimit);
Expand All @@ -138,7 +136,7 @@ public function analyse(
$fileSpecificErrors,
$notFileSpecificErrors,
$internalErrors,
$warnings,
[],
$defaultLevelUsed,
$projectConfigFile,
$savedResultCache
Expand Down
1 change: 0 additions & 1 deletion tests/PHPStan/Analyser/AnalyserTest.php
Expand Up @@ -472,7 +472,6 @@ private function runAnalyser(

return array_merge(
$errors,
$ignoredErrorHelperResult->getWarnings(),
$analyserResult->getInternalErrors()
);
}
Expand Down

0 comments on commit 915fa2e

Please sign in to comment.