This repository has been archived by the owner on Jun 25, 2024. It is now read-only.
generated from psalm/psalm-plugin-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.php
51 lines (46 loc) · 1.52 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace FutureRockstars\NettePsalmPlugin;
use Nette\Application\UI\Control;
use Nette\Bridges\ApplicationLatte\Template;
use SimpleXMLElement;
use Psalm\Plugin\PluginEntryPointInterface;
use Psalm\Plugin\RegistrationInterface;
use PhpParser\Node;
use Psalm\Codebase;
use Psalm\FileSource;
use Psalm\Plugin\Hook\AfterClassLikeVisitInterface;
use Psalm\Storage\ClassLikeStorage;
class Plugin implements PluginEntryPointInterface, AfterClassLikeVisitInterface
{
public function __invoke(RegistrationInterface $psalm, ?SimpleXMLElement $config = null): void
{
foreach ($this->getStubFiles() as $file) {
$psalm->addStubFile($file);
}
$psalm->registerHooksFromClass(self::class);
}
/** @return array<string> */
private function getStubFiles(): array
{
return glob(__DIR__.'/stubs/*.phpstub') ?: [];
}
public static function afterClassLikeVisit(
Node\Stmt\ClassLike $stmt,
ClassLikeStorage $storage,
FileSource $statements_source,
Codebase $codebase,
array &$file_replacements = []
) {
if ($storage->user_defined
&& !$storage->is_interface
&& \class_exists($storage->name)
) {
$reflection = new \ReflectionClass($storage->name);
if($reflection->isSubclassOf(Control::class)
|| $reflection->isSubclassOf(Template::class)
) {
$storage->suppressed_issues[] = 'PropertyNotSetInConstructor';
}
}
}
}