diff --git a/phpstan.neon.dist b/phpstan.neon.dist index a3ec122..efe939b 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -7,5 +7,3 @@ parameters: ignoreErrors: excludePaths: - - checkMissingIterableValueType: false diff --git a/src/Concerns/HasSqids.php b/src/Concerns/HasSqids.php index bd877c7..fbe5387 100644 --- a/src/Concerns/HasSqids.php +++ b/src/Concerns/HasSqids.php @@ -42,7 +42,6 @@ public function getRouteKeyName(): string * @param Model|Relation $query * @param mixed $value * @param null $field - * @return Builder|Relation */ public function resolveRouteBindingQuery($query, $value, $field = null): Builder|Relation { diff --git a/src/Contracts/Prefix.php b/src/Contracts/Prefix.php index 222102a..f011f80 100644 --- a/src/Contracts/Prefix.php +++ b/src/Contracts/Prefix.php @@ -10,7 +10,6 @@ interface Prefix { /** * @param class-string $model - * @return string */ public function prefix(string $model): string; } diff --git a/src/Mixins/FindBySqidMixin.php b/src/Mixins/FindBySqidMixin.php index 89227e7..f1a49d4 100644 --- a/src/Mixins/FindBySqidMixin.php +++ b/src/Mixins/FindBySqidMixin.php @@ -13,6 +13,6 @@ class FindBySqidMixin public function findBySqid(): Closure { /** @phpstan-ignore-next-line */ - return fn(string $sqid, array $columns = ['*']) => $this->find(id: $this->getModel()->keyFromSqid(sqid: $sqid), columns: $columns); + return fn (string $sqid, array $columns = ['*']) => $this->find(id: $this->getModel()->keyFromSqid(sqid: $sqid), columns: $columns); } } diff --git a/src/Mixins/FindBySqidOrFailMixin.php b/src/Mixins/FindBySqidOrFailMixin.php index 7bbf6b9..d502a44 100644 --- a/src/Mixins/FindBySqidOrFailMixin.php +++ b/src/Mixins/FindBySqidOrFailMixin.php @@ -13,6 +13,6 @@ class FindBySqidOrFailMixin public function findBySqidOrFail(): Closure { /** @phpstan-ignore-next-line */ - return fn(string $sqid, array $columns = ['*']) => $this->findOrFail(id: $this->getModel()->keyFromSqid(sqid: $sqid), columns: $columns); + return fn (string $sqid, array $columns = ['*']) => $this->findOrFail(id: $this->getModel()->keyFromSqid(sqid: $sqid), columns: $columns); } } diff --git a/src/Mixins/WhereSqidInMixin.php b/src/Mixins/WhereSqidInMixin.php index 8b63526..f1c4658 100644 --- a/src/Mixins/WhereSqidInMixin.php +++ b/src/Mixins/WhereSqidInMixin.php @@ -18,7 +18,7 @@ public function whereSqidIn(): Closure $model = $this->getModel(); /** @phpstan-ignore-next-line */ - $values = array_map(callback: fn(string $sqid) => $this->getModel()->keyFromSqid(sqid: $sqid), array: $sqids); + $values = array_map(callback: fn (string $sqid) => $this->getModel()->keyFromSqid(sqid: $sqid), array: $sqids); return $this->whereIn(column: $column, values: $values, boolean: $boolean, not: $not); }; diff --git a/src/Mixins/WhereSqidMixin.php b/src/Mixins/WhereSqidMixin.php index 5319b74..910d812 100644 --- a/src/Mixins/WhereSqidMixin.php +++ b/src/Mixins/WhereSqidMixin.php @@ -13,6 +13,6 @@ class WhereSqidMixin public function whereSqid(): Closure { /** @phpstan-ignore-next-line */ - return fn(string $sqid) => $this->whereKey(id: $this->getModel()->keyFromSqid(sqid: $sqid)); + return fn (string $sqid) => $this->whereKey(id: $this->getModel()->keyFromSqid(sqid: $sqid)); } } diff --git a/src/Model.php b/src/Model.php index afd1eef..984863e 100644 --- a/src/Model.php +++ b/src/Model.php @@ -29,7 +29,7 @@ public static function find(string $sqid): ?EloquentModel /** @var class-string|null $model */ $model = $models[$prefix] ?? null; - if (!$model) { + if (! $model) { return null; } @@ -45,7 +45,7 @@ public static function findOrFail(string $sqid): EloquentModel /** @var class-string|null $model */ $model = $models[$prefix] ?? null; - if (!$model) { + if (! $model) { throw new ModelNotFoundException(); } @@ -60,7 +60,7 @@ protected static function models(): array { /** @var array> $models */ $models = collect(static::getFilesRecursively()) - ->map(fn(SplFileInfo $file) => self::fullQualifiedClassNameFromFile(file: $file)) + ->map(fn (SplFileInfo $file) => self::fullQualifiedClassNameFromFile(file: $file)) ->map(function (string $class): ?ReflectionClass { try { /** @phpstan-ignore-next-line */ @@ -71,11 +71,11 @@ protected static function models(): array }) ->filter() /** @phpstan-ignore-next-line */ - ->filter(fn(ReflectionClass $class): bool => $class->isSubclassOf(class: EloquentModel::class)) + ->filter(fn (ReflectionClass $class): bool => $class->isSubclassOf(class: EloquentModel::class)) /** @phpstan-ignore-next-line */ - ->filter(fn(ReflectionClass $class) => !$class->isAbstract()) + ->filter(fn (ReflectionClass $class) => ! $class->isAbstract()) /** @phpstan-ignore-next-line */ - ->filter(fn(ReflectionClass $class) => in_array(needle: HasSqids::class, haystack: $class->getTraitNames())) + ->filter(fn (ReflectionClass $class) => in_array(needle: HasSqids::class, haystack: $class->getTraitNames())) /** @phpstan-ignore-next-line */ ->mapWithKeys(function (ReflectionClass $reflectionClass): array { /** @var class-string $model */ @@ -90,11 +90,14 @@ protected static function models(): array return $models; } + /** + * @return array + */ protected static function namespaces(): array { $composer = File::json(path: base_path(path: 'composer.json')); - /** @var array $namespaces */ + /** @var array $namespaces */ $namespaces = Arr::get(array: $composer, key: 'autoload.psr-4', default: []); return array_flip($namespaces); diff --git a/src/Prefixes/ConsonantPrefix.php b/src/Prefixes/ConsonantPrefix.php index ae2190d..e3cee42 100644 --- a/src/Prefixes/ConsonantPrefix.php +++ b/src/Prefixes/ConsonantPrefix.php @@ -14,7 +14,6 @@ class ConsonantPrefix implements Prefix * Use the first 3 consonants as the model prefix. * * @param class-string $model - * @return string */ public function prefix(string $model): string { diff --git a/src/Prefixes/SimplePrefix.php b/src/Prefixes/SimplePrefix.php index 07351e7..80c4e06 100644 --- a/src/Prefixes/SimplePrefix.php +++ b/src/Prefixes/SimplePrefix.php @@ -14,7 +14,6 @@ class SimplePrefix implements Prefix * Use the first 3 characters as the model prefix. * * @param class-string $model - * @return string */ public function prefix(string $model): string { diff --git a/src/Sqids.php b/src/Sqids.php index 1b745d7..d589a93 100644 --- a/src/Sqids.php +++ b/src/Sqids.php @@ -24,7 +24,6 @@ public static function forModel(Model $model): string /** * @param class-string $model - * @return string */ public static function prefixForModel(string $model): ?string { @@ -38,7 +37,7 @@ public static function prefixForModel(string $model): ?string return $modelPrefix; } - if (!$prefixClass) { + if (! $prefixClass) { return null; } @@ -50,6 +49,9 @@ public static function encodeId(string $model, int $id): string return static::encoder(model: $model)->encode(numbers: [$id]); } + /** + * @return array + */ public static function decodeId(string $model, string $id): array { return static::encoder(model: $model)->decode(id: $id); @@ -72,7 +74,7 @@ public static function alphabetForModel(string $model): string $shuffle = $model . Config::shuffleKey(); $shuffleLength = mb_strlen(string: $shuffle); - if (!$shuffleLength) { + if (! $shuffleLength) { return Config::alphabet(); } @@ -92,6 +94,9 @@ public static function alphabetForModel(string $model): string return implode(separator: '', array: $alphabetArray); } + /** + * @return array + */ protected static function multiByteSplit(string $string): array { return preg_split(pattern: '/(?!^)(?=.)/u', subject: $string) ?: []; diff --git a/src/SqidsServiceProvider.php b/src/SqidsServiceProvider.php index 88f29a0..8eb103f 100644 --- a/src/SqidsServiceProvider.php +++ b/src/SqidsServiceProvider.php @@ -8,8 +8,8 @@ use Illuminate\Support\ServiceProvider; use RedExplosion\Sqids\Mixins\FindBySqidMixin; use RedExplosion\Sqids\Mixins\FindBySqidOrFailMixin; -use RedExplosion\Sqids\Mixins\WhereSqidMixin; use RedExplosion\Sqids\Mixins\WhereSqidInMixin; +use RedExplosion\Sqids\Mixins\WhereSqidMixin; use RedExplosion\Sqids\Mixins\WhereSqidNotInMixin; class SqidsServiceProvider extends ServiceProvider diff --git a/src/Support/Config.php b/src/Support/Config.php index 7e5cc45..242252b 100644 --- a/src/Support/Config.php +++ b/src/Support/Config.php @@ -14,6 +14,9 @@ class Config protected static int $defaultMinLength = 10; + /** + * @var array + */ protected static array $defaultBlacklist = []; protected static string $defaultSeparator = '_'; @@ -26,7 +29,7 @@ public static function shuffleKey(): ?string { $shuffleKey = config(key: 'sqids.shuffle_key'); - if (!is_string($shuffleKey)) { + if (! is_string($shuffleKey)) { return null; } @@ -37,7 +40,7 @@ public static function alphabet(): string { $alphabet = config(key: 'sqids.alphabet'); - if (!$alphabet || !is_string($alphabet)) { + if (! $alphabet || ! is_string($alphabet)) { return static::$defaultAlphabet; } @@ -49,18 +52,21 @@ public static function minLength(): int /** @var int|null $minLength */ $minLength = config(key: 'sqids.min_length', default: static::$defaultMinLength); - if (!$minLength || !is_int($minLength)) { + if (! $minLength || ! is_int($minLength)) { return static::$defaultMinLength; } return $minLength; } + /** + * @return array + */ public static function blacklist(): array { $blacklist = config(key: 'sqids.blacklist', default: static::$defaultBlacklist); - if (!is_array($blacklist)) { + if (! is_array($blacklist)) { return static::$defaultBlacklist; } @@ -71,7 +77,7 @@ public static function separator(): string { $separator = config(key: 'sqids.separator', default: static::$defaultSeparator); - if (!$separator || !is_string(value: $separator)) { + if (! $separator || ! is_string(value: $separator)) { return static::$defaultSeparator; } @@ -82,7 +88,7 @@ public static function prefixClass(): ?Prefix { $prefix = config(key: 'sqids.prefix_class'); - if (!$prefix) { + if (! $prefix) { return null; } @@ -92,7 +98,7 @@ public static function prefixClass(): ?Prefix return new SimplePrefix(); } - if (!$prefix instanceof Prefix) { + if (! $prefix instanceof Prefix) { return new SimplePrefix(); } diff --git a/tests/Prefixes/ConstantPrefixTest.php b/tests/Prefixes/ConsonantPrefixTest.php similarity index 98% rename from tests/Prefixes/ConstantPrefixTest.php rename to tests/Prefixes/ConsonantPrefixTest.php index 47bb24e..6080e33 100644 --- a/tests/Prefixes/ConstantPrefixTest.php +++ b/tests/Prefixes/ConsonantPrefixTest.php @@ -12,5 +12,4 @@ ->toBe(expected: 'cst') ->prefix(model: Charge::class) ->toBe(expected: 'chr'); - ; }); diff --git a/tests/Prefixes/DefaultPrefixTest.php b/tests/Prefixes/DefaultPrefixTest.php index 6c0eddf..2e99e8e 100644 --- a/tests/Prefixes/DefaultPrefixTest.php +++ b/tests/Prefixes/DefaultPrefixTest.php @@ -12,5 +12,4 @@ ->toBe(expected: 'cus') ->prefix(model: Charge::class) ->toBe(expected: 'cha'); - ; }); diff --git a/tests/RouteModelBindingTest.php b/tests/RouteModelBindingTest.php index 875a869..a49abef 100644 --- a/tests/RouteModelBindingTest.php +++ b/tests/RouteModelBindingTest.php @@ -24,6 +24,6 @@ it('returns a 404 if the sqid is invalid', function (): void { $this - ->get(uri: "/customers/invalid-sqid") + ->get(uri: '/customers/invalid-sqid') ->assertNotFound(); }); diff --git a/workbench/database/migrations/2023_11_27_193203_create_customers_table.php b/workbench/database/migrations/2023_11_27_193203_create_customers_table.php index 1db1e11..dab92fe 100644 --- a/workbench/database/migrations/2023_11_27_193203_create_customers_table.php +++ b/workbench/database/migrations/2023_11_27_193203_create_customers_table.php @@ -6,7 +6,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class () extends Migration { +return new class() extends Migration +{ /** * Run the migrations. */ diff --git a/workbench/database/migrations/2023_11_27_193747_create_charges_table.php b/workbench/database/migrations/2023_11_27_193747_create_charges_table.php index 8f3babb..3706177 100644 --- a/workbench/database/migrations/2023_11_27_193747_create_charges_table.php +++ b/workbench/database/migrations/2023_11_27_193747_create_charges_table.php @@ -6,7 +6,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class () extends Migration { +return new class() extends Migration +{ /** * Run the migrations. */ diff --git a/workbench/routes/web.php b/workbench/routes/web.php index 284d914..a071dba 100644 --- a/workbench/routes/web.php +++ b/workbench/routes/web.php @@ -5,4 +5,4 @@ use Illuminate\Support\Facades\Route; use Workbench\App\Models\Customer; -Route::get(uri: 'customers/{customer}', action: fn(Customer $customer) => $customer->name); +Route::get(uri: 'customers/{customer}', action: fn (Customer $customer) => $customer->name);