1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix #199 - allow classes to suppress PropertyNotSetInConstructor warnings

This commit is contained in:
Matt Brown 2017-09-13 11:32:13 -04:00
parent 439a1ddc97
commit eee8442af6
6 changed files with 30 additions and 1 deletions

View File

@ -639,7 +639,7 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
$this->fq_class_name . ' or in any private methods called in the constructor',
$error_location
),
$this->source->getSuppressedIssues()
array_merge($this->source->getSuppressedIssues(), $storage->suppressed_issues)
)) {
continue;
}

View File

@ -285,6 +285,13 @@ class CommentChecker
$info->deprecated = true;
}
if (isset($comments['specials']['psalm-suppress'])) {
/** @var string $suppress_entry */
foreach ($comments['specials']['psalm-suppress'] as $suppress_entry) {
$info->suppressed_issues[] = preg_split('/[\s]+/', $suppress_entry)[0];
}
}
if (isset($comments['specials']['property'])) {
/** @var string $property */
foreach ($comments['specials']['property'] as $line_number => $property) {

View File

@ -19,4 +19,9 @@ class ClassLikeDocblockComment
* @var array<int, array{name:string, type:string}>
*/
public $properties = [];
/**
* @var array<int, string>
*/
public $suppressed_issues = [];
}

View File

@ -47,6 +47,11 @@ class ClassLikeStorage
*/
public $deprecated = false;
/**
* @var array<int, string>
*/
public $suppressed_issues = [];
/**
* @var string
*/

View File

@ -217,6 +217,8 @@ class DependencyFinderVisitor extends PhpParser\NodeVisitorAbstract implements P
}
$storage->deprecated = $docblock_info->deprecated;
$storage->suppressed_issues = $docblock_info->suppressed_issues;
}
}

View File

@ -407,6 +407,16 @@ class PropertyTypeTest extends TestCase
class E extends \Exception{}',
],
'notSetInEmptyConstructor' => [
'<?php
/** @psalm-suppress PropertyNotSetInConstructor */
class A {
/** @var int */
public $a;
public function __construct() { }
}',
],
];
}