From 7c2517bbea6a7447922a4ee6798275eedd33d990 Mon Sep 17 00:00:00 2001 From: Mohammad Alavi Date: Sat, 8 Jun 2024 17:49:14 +0330 Subject: [PATCH] refactor: rename method --- src/Abstracts/Collections/EloquentCollection.php | 3 +++ .../{ContainsHashedId.php => ContainsDecodedHash.php} | 8 ++++---- .../MacroProviders/CollectionMacroServiceProvider.php | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) rename src/Macros/Collection/{ContainsHashedId.php => ContainsDecodedHash.php} (60%) diff --git a/src/Abstracts/Collections/EloquentCollection.php b/src/Abstracts/Collections/EloquentCollection.php index 70a25dbe..e88edfd2 100644 --- a/src/Abstracts/Collections/EloquentCollection.php +++ b/src/Abstracts/Collections/EloquentCollection.php @@ -4,6 +4,9 @@ use Illuminate\Database\Eloquent\Collection; +/** + * @method static bool containsDecodedHash(string $hashedValue, string $key = 'id') + */ abstract class EloquentCollection extends Collection { } diff --git a/src/Macros/Collection/ContainsHashedId.php b/src/Macros/Collection/ContainsDecodedHash.php similarity index 60% rename from src/Macros/Collection/ContainsHashedId.php rename to src/Macros/Collection/ContainsDecodedHash.php index 5088b8ad..13db7c5a 100644 --- a/src/Macros/Collection/ContainsHashedId.php +++ b/src/Macros/Collection/ContainsDecodedHash.php @@ -5,17 +5,17 @@ use Illuminate\Support\Collection; use Vinkla\Hashids\Facades\Hashids; -class ContainsHashedId { +class ContainsDecodedHash { public function __invoke(): callable { return /** - * Check if the given hashed id exists in the collection + * Decodes a hashed value and checks if the decoded value exists in the collection under the specified key. */ - function (string $hashedId, string $key = 'id'): bool + function (string $hashedValue, string $key = 'id'): bool { /** @var Collection $this */ - return $this->contains($key, Hashids::decode($hashedId)[0]); + return $this->contains($key, Hashids::decode($hashedValue)[0]); }; } } diff --git a/src/Providers/MacroProviders/CollectionMacroServiceProvider.php b/src/Providers/MacroProviders/CollectionMacroServiceProvider.php index 2c16a899..d60e09db 100644 --- a/src/Providers/MacroProviders/CollectionMacroServiceProvider.php +++ b/src/Providers/MacroProviders/CollectionMacroServiceProvider.php @@ -3,7 +3,7 @@ namespace Apiato\Core\Providers\MacroProviders; use Apiato\Core\Abstracts\Providers\MainServiceProvider as AbstractMainServiceProvider; -use Apiato\Core\Macros\Collection\ContainsHashedId; +use Apiato\Core\Macros\Collection\ContainsDecodedHash; use Illuminate\Support\Collection; final class CollectionMacroServiceProvider extends AbstractMainServiceProvider { @@ -19,7 +19,7 @@ public function boot(): void private function macros(): array { return [ - 'containsHashedId' => ContainsHashedId::class, + 'containsDecodedHash' => ContainsDecodedHash::class, ]; } }