Skip to content

Commit

Permalink
fix: phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubmikita committed Jun 2, 2024
1 parent 2fbe4dc commit 6ee37e8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 27 deletions.
2 changes: 1 addition & 1 deletion compat/src-deprecated/Adapter/JSON.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

declare(strict_types=1);

namespace BracketSpace\Notification\Repository\Adapter;
namespace BracketSpace\Notification\Defaults\Adapter;

use BracketSpace\Notification\Abstracts;

Expand Down
2 changes: 1 addition & 1 deletion compat/src-deprecated/Adapter/WordPress.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions compat/src-deprecated/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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(
Expand Down
13 changes: 13 additions & 0 deletions compat/src-deprecated/namespaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 2 additions & 22 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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\\<string, BracketSpace\\\\Notification\\\\Interfaces\\\\Sendable\\>, enabled\\?\\: bool, extras\\?\\: array\\<string, array\\|bool\\|float\\|int\\|string\\>, version\\?\\: int\\}\\|null\\.$#"
count: 1
Expand All @@ -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\\<string, array\\<string, array\\|bool\\|BracketSpace\\\\Notification\\\\Interfaces\\\\Sendable\\|float\\|int\\|string\\>\\|bool\\|BracketSpace\\\\Notification\\\\Interfaces\\\\Triggerable\\|int\\|string\\>\\|null given\\.$#"
count: 1
Expand All @@ -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\\<int\\>, exclude\\?\\: array\\<int\\>, 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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6ee37e8

Please sign in to comment.