Skip to content

Commit

Permalink
refactor: rename method
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Alavi committed Jun 8, 2024
1 parent 3774b42 commit 7c2517b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/Abstracts/Collections/EloquentCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Illuminate\Database\Eloquent\Collection;

/**
* @method static bool containsDecodedHash(string $hashedValue, string $key = 'id')
*/
abstract class EloquentCollection extends Collection
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -19,7 +19,7 @@ public function boot(): void
private function macros(): array
{
return [
'containsHashedId' => ContainsHashedId::class,
'containsDecodedHash' => ContainsDecodedHash::class,
];
}
}

0 comments on commit 7c2517b

Please sign in to comment.