Skip to content

Commit 9f33b82

Browse files
olivernybroenunomaduro
authored andcommitted
[Fix] Silence warnings (nunomaduro#253)
* Fix: When getting tokens, silence php warnings in case file is corrupt * Fix: Silence sniff processor php warnings * Style: Exclude silenced errors file from sniff
1 parent 7453929 commit 9f33b82

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

phpinsights.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use NunoMaduro\PhpInsights\Domain\Sniffs\ForbiddenSetterSniff;
66
use PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff;
7+
use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\NoSilencedErrorsSniff;
78
use SlevomatCodingStandard\Sniffs\TypeHints\DisallowMixedTypeHintSniff;
89

910
return [
@@ -60,6 +61,12 @@
6061
'src/Domain/Details.php',
6162
],
6263
],
64+
NoSilencedErrorsSniff::class => [
65+
'exclude' => [
66+
'src/Domain/Analyser.php',
67+
'src/Domain/File.php',
68+
],
69+
],
6370
],
6471

6572
];

src/Domain/Analyser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function analyse(string $dir, array $files): Collector
7171
private function analyseFile(Collector $collector, string $filename): void
7272
{
7373
$buffer = (string) \file_get_contents($filename);
74-
$tokens = \token_get_all($buffer);
74+
$tokens = @\token_get_all($buffer);
7575
$numTokens = \count($tokens);
7676

7777
unset($buffer);

src/Domain/File.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function process(): void
112112
$this->reportActiveSniffClass($sniff);
113113

114114
try {
115-
$sniff->process($this, $stackPtr);
115+
@$sniff->process($this, $stackPtr);
116116
} catch (\Throwable $e) {
117117
$this->addError('Unparsable php code: syntax error or wrong phpdocs.', $stackPtr, $token['code']);
118118
}

0 commit comments

Comments
 (0)