Skip to content

[WIP] Suppress common issues #394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/Handlers/SuppressHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event): voi
foreach (self::BY_CLASS_METHOD as $issue => $method_by_class) {
foreach ($method_by_class[$class->name] ?? [] as $method_name) {
/** @psalm-suppress RedundantFunctionCall */
self::suppress($issue, $class->methods[strtolower($method_name)] ?? null);
$method_storage = $class->methods[strtolower($method_name)] ?? null;
if ($method_storage instanceof MethodStorage) {
self::suppress($issue, $method_storage);
}
}
}

Expand All @@ -114,7 +117,10 @@ public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event): voi
}

foreach ($method_names as $method_name) {
self::suppress($issue, $class->methods[strtolower($method_name)] ?? null);
$method_storage = $class->methods[strtolower($method_name)] ?? null;
if ($method_storage instanceof MethodStorage) {
self::suppress($issue, $method_storage);
}
}
}
}
Expand All @@ -134,7 +140,10 @@ public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event): voi
}

foreach ($property_names as $property_name) {
self::suppress($issue, $class->properties[$property_name] ?? null);
$property_storage = $class->properties[$property_name] ?? null;
if ($property_storage instanceof PropertyStorage) {
self::suppress($issue, $property_storage);
}
}
}
}
Expand All @@ -148,12 +157,9 @@ public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event): voi
}
}

/**
* @param ClassLikeStorage|PropertyStorage|MethodStorage|null $storage
*/
private static function suppress(string $issue, $storage): void
private static function suppress(string $issue, ClassLikeStorage|PropertyStorage|MethodStorage $storage): void
{
if ($storage && !in_array($issue, $storage->suppressed_issues, true)) {
if (!in_array($issue, $storage->suppressed_issues, true)) {
$storage->suppressed_issues[] = $issue;
}
}
Expand Down
35 changes: 0 additions & 35 deletions tests/Application/laravel-test-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@
<NonInvariantDocblockPropertyType>
<code><![CDATA[$description]]></code>
</NonInvariantDocblockPropertyType>
<PropertyNotSetInConstructor>
<code><![CDATA[ExampleCommand]]></code>
<code><![CDATA[ExampleCommand]]></code>
<code><![CDATA[ExampleCommand]]></code>
<code><![CDATA[ExampleCommand]]></code>
<code><![CDATA[ExampleCommand]]></code>
</PropertyNotSetInConstructor>
<UnusedClass>
<code><![CDATA[ExampleCommand]]></code>
</UnusedClass>
Expand All @@ -55,17 +48,6 @@
</UnusedClass>
</file>
<file src="app/Http/Requests/ExampleRequest.php">
<PropertyNotSetInConstructor>
<code><![CDATA[ExampleRequest]]></code>
<code><![CDATA[ExampleRequest]]></code>
<code><![CDATA[ExampleRequest]]></code>
<code><![CDATA[ExampleRequest]]></code>
<code><![CDATA[ExampleRequest]]></code>
<code><![CDATA[ExampleRequest]]></code>
<code><![CDATA[ExampleRequest]]></code>
<code><![CDATA[ExampleRequest]]></code>
<code><![CDATA[ExampleRequest]]></code>
</PropertyNotSetInConstructor>
<UnusedClass>
<code><![CDATA[ExampleRequest]]></code>
</UnusedClass>
Expand Down Expand Up @@ -96,16 +78,6 @@
<code><![CDATA[content]]></code>
<code><![CDATA[envelope]]></code>
</PossiblyUnusedMethod>
<PropertyNotSetInConstructor>
<code><![CDATA[ExampleMail]]></code>
<code><![CDATA[ExampleMail]]></code>
<code><![CDATA[ExampleMail]]></code>
<code><![CDATA[ExampleMail]]></code>
<code><![CDATA[ExampleMail]]></code>
<code><![CDATA[ExampleMail]]></code>
<code><![CDATA[ExampleMail]]></code>
<code><![CDATA[ExampleMail]]></code>
</PropertyNotSetInConstructor>
</file>
<file src="app/Models/Example.php">
<UnusedClass>
Expand All @@ -130,9 +102,6 @@
<code><![CDATA[toMail]]></code>
<code><![CDATA[via]]></code>
</PossiblyUnusedMethod>
<PropertyNotSetInConstructor>
<code><![CDATA[ExampleNotification]]></code>
</PropertyNotSetInConstructor>
</file>
<file src="app/Observers/ExampleObserver.php">
<UnusedClass>
Expand Down Expand Up @@ -160,10 +129,6 @@
</UnusedClass>
</file>
<file src="app/View/Components/ExampleComponent.php">
<PropertyNotSetInConstructor>
<code><![CDATA[ExampleComponent]]></code>
<code><![CDATA[ExampleComponent]]></code>
</PropertyNotSetInConstructor>
<UnusedClass>
<code><![CDATA[ExampleComponent]]></code>
</UnusedClass>
Expand Down
Loading