From 6ee37e83a8e3117bde1bd608ba269a12351ee35b Mon Sep 17 00:00:00 2001 From: Jakub Mikita Date: Sun, 2 Jun 2024 15:38:43 +0200 Subject: [PATCH] fix: phpstan --- compat/src-deprecated/Adapter/JSON.php | 2 +- compat/src-deprecated/Adapter/WordPress.php | 2 +- compat/src-deprecated/functions.php | 6 +++--- compat/src-deprecated/namespaces.php | 13 +++++++++++ phpstan-baseline.neon | 24 ++------------------- 5 files changed, 20 insertions(+), 27 deletions(-) diff --git a/compat/src-deprecated/Adapter/JSON.php b/compat/src-deprecated/Adapter/JSON.php index 1f4ae0f4..952d27d9 100644 --- a/compat/src-deprecated/Adapter/JSON.php +++ b/compat/src-deprecated/Adapter/JSON.php @@ -8,7 +8,7 @@ declare(strict_types=1); -namespace BracketSpace\Notification\Repository\Adapter; +namespace BracketSpace\Notification\Defaults\Adapter; use BracketSpace\Notification\Abstracts; diff --git a/compat/src-deprecated/Adapter/WordPress.php b/compat/src-deprecated/Adapter/WordPress.php index 5f885ff7..e86616ef 100644 --- a/compat/src-deprecated/Adapter/WordPress.php +++ b/compat/src-deprecated/Adapter/WordPress.php @@ -8,7 +8,7 @@ declare(strict_types=1); -namespace BracketSpace\Notification\Repository\Adapter; +namespace BracketSpace\Notification\Defaults\Adapter; use BracketSpace\Notification\Abstracts; use BracketSpace\Notification\Core\Notification; diff --git a/compat/src-deprecated/functions.php b/compat/src-deprecated/functions.php index d5a6e8c0..7b81fb28 100644 --- a/compat/src-deprecated/functions.php +++ b/compat/src-deprecated/functions.php @@ -114,7 +114,7 @@ function notification_get_post_by_hash( $hash ) { function notification_post_is_new( $post ) { _deprecated_function( __FUNCTION__, '8.0.0' ); - /** @var BracketSpace\Notification\Repository\Adapter\WordPress $notification */ + /** @var BracketSpace\Notification\Defaults\Adapter\WordPress $notification */ $notification = notification_adapt_from( 'WordPress', $post ); return $notification->isNew(); } @@ -482,8 +482,8 @@ function notification_adapt($adapterName, \BracketSpace\Notification\Core\Notifi if (class_exists($adapterName)) { $adapter = new $adapterName($notification); - } elseif (class_exists('BracketSpace\\Notification\\Repository\\Adapter\\' . $adapterName)) { - $adapterName = 'BracketSpace\\Notification\\Repository\\Adapter\\' . $adapterName; + } elseif (class_exists('BracketSpace\\Notification\\Defaults\\Adapter\\' . $adapterName)) { + $adapterName = 'BracketSpace\\Notification\\Defaults\\Adapter\\' . $adapterName; $adapter = new $adapterName($notification); } else { throw new \Exception( diff --git a/compat/src-deprecated/namespaces.php b/compat/src-deprecated/namespaces.php index 6fd2eeac..f42fcc4e 100644 --- a/compat/src-deprecated/namespaces.php +++ b/compat/src-deprecated/namespaces.php @@ -12,12 +12,25 @@ ], ]; + // Classes meant to be left as is, ie. deprecated ones. + $exclusions = [ + 'BracketSpace\Notification\Defaults\Adapter', + ]; + foreach ($deprecations as $version => $map) { foreach ($map as $oldNamespace => $newNamespace) { + // Match the loaded classname. if (strpos($class, $oldNamespace) !== 0) { continue; } + // Check for exclusions. + foreach ($exclusions as $excludedNamespace) { + if (strpos($class, $excludedNamespace) !== 0) { + continue; + } + } + $newClass = str_replace($oldNamespace, $newNamespace, $class); notification_deprecated_class($class, $version, $newClass); diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 64b12d9e..ecaef05e 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -420,11 +420,6 @@ parameters: count: 1 path: compat/src-deprecated/Adapter/JSON.php - - - message: "#^Call to method save\\(\\) on an unknown class BracketSpace\\\\Notification\\\\Defaults\\\\Adapter\\\\JSON\\.$#" - count: 1 - path: compat/src-deprecated/Adapter/WordPress.php - - message: "#^Offset 'enabled' does not exist on array\\{hash\\?\\: string, title\\?\\: string, trigger\\?\\: BracketSpace\\\\Notification\\\\Interfaces\\\\Triggerable, carriers\\?\\: array\\, enabled\\?\\: bool, extras\\?\\: array\\, version\\?\\: int\\}\\|null\\.$#" count: 1 @@ -440,11 +435,6 @@ parameters: count: 1 path: compat/src-deprecated/Adapter/WordPress.php - - - message: "#^PHPDoc tag @var contains unknown class BracketSpace\\\\Notification\\\\Defaults\\\\Adapter\\\\JSON\\.$#" - count: 1 - path: compat/src-deprecated/Adapter/WordPress.php - - message: "#^Parameter \\#1 \\$data of function notification_convert_data expects array, array\\\\|bool\\|BracketSpace\\\\Notification\\\\Interfaces\\\\Triggerable\\|int\\|string\\>\\|null given\\.$#" count: 1 @@ -456,15 +446,10 @@ parameters: path: compat/src-deprecated/Adapter/WordPress.php - - message: "#^Property BracketSpace\\\\Notification\\\\Repository\\\\Adapter\\\\WordPress\\:\\:\\$post \\(WP_Post\\) in empty\\(\\) is not falsy\\.$#" + message: "#^Property BracketSpace\\\\Notification\\\\Defaults\\\\Adapter\\\\WordPress\\:\\:\\$post \\(WP_Post\\) in empty\\(\\) is not falsy\\.$#" count: 2 path: compat/src-deprecated/Adapter/WordPress.php - - - message: "#^Unable to resolve the template type T in call to function wp_slash$#" - count: 1 - path: compat/src-deprecated/Adapter/WordPress.php - - message: "#^Parameter \\#1 \\$args of function get_posts expects array\\{numberposts\\?\\: int, category\\?\\: int\\|string, include\\?\\: array\\, exclude\\?\\: array\\, suppress_filters\\?\\: bool, attachment_id\\?\\: int, author\\?\\: int\\|string, author_name\\?\\: string, \\.\\.\\.\\}\\|null, array\\{posts_per_page\\: \\-1, post_type\\: 'notification', post_status\\?\\: array\\{'publish', 'draft'\\}, suppress_filters\\?\\: 0\\} given\\.$#" count: 1 @@ -537,14 +522,9 @@ parameters: - message: "#^$#" - count: 1 + count: 2 path: compat/src-deprecated/helpers.php - - - message: "#^Class \"BracketSpace\\\\Notification\\\\Repository\\\\Adapter\\\\JSON\" not found$#" - count: 1 - path: compat/src-deprecated/namespaces.php - - message: "#^Call to static method create\\(\\) on an unknown class StubsGenerator\\\\Finder\\.$#" count: 1