From cfdccb61f0c37d84a9fbdeb87b3933f40b8b7ad3 Mon Sep 17 00:00:00 2001 From: Alies Lapatsin Date: Mon, 24 Feb 2025 10:30:00 +0100 Subject: [PATCH 1/3] #361 Useproperty type hints --- src/Handlers/SuppressHandler.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Handlers/SuppressHandler.php b/src/Handlers/SuppressHandler.php index d87b1bfb..dad642bf 100644 --- a/src/Handlers/SuppressHandler.php +++ b/src/Handlers/SuppressHandler.php @@ -148,10 +148,7 @@ 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)) { $storage->suppressed_issues[] = $issue; From ea53c45cba6886a63e643c8b4e65bd3c7046364b Mon Sep 17 00:00:00 2001 From: Alies Lapatsin Date: Mon, 24 Feb 2025 10:30:33 +0100 Subject: [PATCH 2/3] #361 Cleanup Laravel app baseline file from PropertyNotSetInConstructor --- tests/Application/laravel-test-baseline.xml | 35 --------------------- 1 file changed, 35 deletions(-) diff --git a/tests/Application/laravel-test-baseline.xml b/tests/Application/laravel-test-baseline.xml index 24a684d8..3c8634e8 100644 --- a/tests/Application/laravel-test-baseline.xml +++ b/tests/Application/laravel-test-baseline.xml @@ -23,13 +23,6 @@ - - - - - - - @@ -55,17 +48,6 @@ - - - - - - - - - - - @@ -96,16 +78,6 @@ - - - - - - - - - - @@ -130,9 +102,6 @@ - - - @@ -160,10 +129,6 @@ - - - - From b74b627725b2e8a15323ed1c048f65fb41543ed2 Mon Sep 17 00:00:00 2001 From: Alies Lapatsin Date: Mon, 24 Feb 2025 11:46:09 +0100 Subject: [PATCH 3/3] #361 Avoid null ref issue --- src/Handlers/SuppressHandler.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Handlers/SuppressHandler.php b/src/Handlers/SuppressHandler.php index dad642bf..d475ed1d 100644 --- a/src/Handlers/SuppressHandler.php +++ b/src/Handlers/SuppressHandler.php @@ -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); + } } } @@ -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); + } } } } @@ -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); + } } } } @@ -150,7 +159,7 @@ public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event): voi 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; } }