Skip to content

Commit 32f5492

Browse files
authored
Merge branch 'main' into fix/sqid-attribute-return-type
2 parents 5310a20 + d68d86e commit 32f5492

19 files changed

+42
-34
lines changed

phpstan.neon.dist

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,3 @@ parameters:
77
ignoreErrors:
88

99
excludePaths:
10-
11-
checkMissingIterableValueType: false

src/Concerns/HasSqids.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public function getRouteKeyName(): string
4242
* @param Model|Relation $query
4343
* @param mixed $value
4444
* @param null $field
45-
* @return Builder|Relation
4645
*/
4746
public function resolveRouteBindingQuery($query, $value, $field = null): Builder|Relation
4847
{

src/Contracts/Prefix.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ interface Prefix
1010
{
1111
/**
1212
* @param class-string<Model> $model
13-
* @return string
1413
*/
1514
public function prefix(string $model): string;
1615
}

src/Mixins/FindBySqidMixin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ class FindBySqidMixin
1313
public function findBySqid(): Closure
1414
{
1515
/** @phpstan-ignore-next-line */
16-
return fn(string $sqid, array $columns = ['*']) => $this->find(id: $this->getModel()->keyFromSqid(sqid: $sqid), columns: $columns);
16+
return fn (string $sqid, array $columns = ['*']) => $this->find(id: $this->getModel()->keyFromSqid(sqid: $sqid), columns: $columns);
1717
}
1818
}

src/Mixins/FindBySqidOrFailMixin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ class FindBySqidOrFailMixin
1313
public function findBySqidOrFail(): Closure
1414
{
1515
/** @phpstan-ignore-next-line */
16-
return fn(string $sqid, array $columns = ['*']) => $this->findOrFail(id: $this->getModel()->keyFromSqid(sqid: $sqid), columns: $columns);
16+
return fn (string $sqid, array $columns = ['*']) => $this->findOrFail(id: $this->getModel()->keyFromSqid(sqid: $sqid), columns: $columns);
1717
}
1818
}

src/Mixins/WhereSqidInMixin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function whereSqidIn(): Closure
1818
$model = $this->getModel();
1919

2020
/** @phpstan-ignore-next-line */
21-
$values = array_map(callback: fn(string $sqid) => $this->getModel()->keyFromSqid(sqid: $sqid), array: $sqids);
21+
$values = array_map(callback: fn (string $sqid) => $this->getModel()->keyFromSqid(sqid: $sqid), array: $sqids);
2222

2323
return $this->whereIn(column: $column, values: $values, boolean: $boolean, not: $not);
2424
};

src/Mixins/WhereSqidMixin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ class WhereSqidMixin
1313
public function whereSqid(): Closure
1414
{
1515
/** @phpstan-ignore-next-line */
16-
return fn(string $sqid) => $this->whereKey(id: $this->getModel()->keyFromSqid(sqid: $sqid));
16+
return fn (string $sqid) => $this->whereKey(id: $this->getModel()->keyFromSqid(sqid: $sqid));
1717
}
1818
}

src/Model.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static function find(string $sqid): ?EloquentModel
2929
/** @var class-string<EloquentModel>|null $model */
3030
$model = $models[$prefix] ?? null;
3131

32-
if (!$model) {
32+
if (! $model) {
3333
return null;
3434
}
3535

@@ -45,7 +45,7 @@ public static function findOrFail(string $sqid): EloquentModel
4545
/** @var class-string<EloquentModel>|null $model */
4646
$model = $models[$prefix] ?? null;
4747

48-
if (!$model) {
48+
if (! $model) {
4949
throw new ModelNotFoundException();
5050
}
5151

@@ -60,7 +60,7 @@ protected static function models(): array
6060
{
6161
/** @var array<string, class-string<EloquentModel>> $models */
6262
$models = collect(static::getFilesRecursively())
63-
->map(fn(SplFileInfo $file) => self::fullQualifiedClassNameFromFile(file: $file))
63+
->map(fn (SplFileInfo $file) => self::fullQualifiedClassNameFromFile(file: $file))
6464
->map(function (string $class): ?ReflectionClass {
6565
try {
6666
/** @phpstan-ignore-next-line */
@@ -71,11 +71,11 @@ protected static function models(): array
7171
})
7272
->filter()
7373
/** @phpstan-ignore-next-line */
74-
->filter(fn(ReflectionClass $class): bool => $class->isSubclassOf(class: EloquentModel::class))
74+
->filter(fn (ReflectionClass $class): bool => $class->isSubclassOf(class: EloquentModel::class))
7575
/** @phpstan-ignore-next-line */
76-
->filter(fn(ReflectionClass $class) => !$class->isAbstract())
76+
->filter(fn (ReflectionClass $class) => ! $class->isAbstract())
7777
/** @phpstan-ignore-next-line */
78-
->filter(fn(ReflectionClass $class) => in_array(needle: HasSqids::class, haystack: $class->getTraitNames()))
78+
->filter(fn (ReflectionClass $class) => in_array(needle: HasSqids::class, haystack: $class->getTraitNames()))
7979
/** @phpstan-ignore-next-line */
8080
->mapWithKeys(function (ReflectionClass $reflectionClass): array {
8181
/** @var class-string<EloquentModel> $model */
@@ -90,11 +90,14 @@ protected static function models(): array
9090
return $models;
9191
}
9292

93+
/**
94+
* @return array<string, string>
95+
*/
9396
protected static function namespaces(): array
9497
{
9598
$composer = File::json(path: base_path(path: 'composer.json'));
9699

97-
/** @var array $namespaces */
100+
/** @var array<string, string> $namespaces */
98101
$namespaces = Arr::get(array: $composer, key: 'autoload.psr-4', default: []);
99102

100103
return array_flip($namespaces);

src/Prefixes/ConsonantPrefix.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class ConsonantPrefix implements Prefix
1414
* Use the first 3 consonants as the model prefix.
1515
*
1616
* @param class-string<Model> $model
17-
* @return string
1817
*/
1918
public function prefix(string $model): string
2019
{

src/Prefixes/SimplePrefix.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class SimplePrefix implements Prefix
1414
* Use the first 3 characters as the model prefix.
1515
*
1616
* @param class-string<Model> $model
17-
* @return string
1817
*/
1918
public function prefix(string $model): string
2019
{

src/Sqids.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public static function forModel(Model $model): string
2424

2525
/**
2626
* @param class-string<Model> $model
27-
* @return string
2827
*/
2928
public static function prefixForModel(string $model): ?string
3029
{
@@ -38,7 +37,7 @@ public static function prefixForModel(string $model): ?string
3837
return $modelPrefix;
3938
}
4039

41-
if (!$prefixClass) {
40+
if (! $prefixClass) {
4241
return null;
4342
}
4443

@@ -50,6 +49,9 @@ public static function encodeId(string $model, int $id): string
5049
return static::encoder(model: $model)->encode(numbers: [$id]);
5150
}
5251

52+
/**
53+
* @return array<int, int>
54+
*/
5355
public static function decodeId(string $model, string $id): array
5456
{
5557
return static::encoder(model: $model)->decode(id: $id);
@@ -72,7 +74,7 @@ public static function alphabetForModel(string $model): string
7274
$shuffle = $model . Config::shuffleKey();
7375
$shuffleLength = mb_strlen(string: $shuffle);
7476

75-
if (!$shuffleLength) {
77+
if (! $shuffleLength) {
7678
return Config::alphabet();
7779
}
7880

@@ -92,6 +94,9 @@ public static function alphabetForModel(string $model): string
9294
return implode(separator: '', array: $alphabetArray);
9395
}
9496

97+
/**
98+
* @return array<int, string>
99+
*/
95100
protected static function multiByteSplit(string $string): array
96101
{
97102
return preg_split(pattern: '/(?!^)(?=.)/u', subject: $string) ?: [];

src/SqidsServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
use Illuminate\Support\ServiceProvider;
99
use RedExplosion\Sqids\Mixins\FindBySqidMixin;
1010
use RedExplosion\Sqids\Mixins\FindBySqidOrFailMixin;
11-
use RedExplosion\Sqids\Mixins\WhereSqidMixin;
1211
use RedExplosion\Sqids\Mixins\WhereSqidInMixin;
12+
use RedExplosion\Sqids\Mixins\WhereSqidMixin;
1313
use RedExplosion\Sqids\Mixins\WhereSqidNotInMixin;
1414

1515
class SqidsServiceProvider extends ServiceProvider

src/Support/Config.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class Config
1414

1515
protected static int $defaultMinLength = 10;
1616

17+
/**
18+
* @var array<int, string>
19+
*/
1720
protected static array $defaultBlacklist = [];
1821

1922
protected static string $defaultSeparator = '_';
@@ -26,7 +29,7 @@ public static function shuffleKey(): ?string
2629
{
2730
$shuffleKey = config(key: 'sqids.shuffle_key');
2831

29-
if (!is_string($shuffleKey)) {
32+
if (! is_string($shuffleKey)) {
3033
return null;
3134
}
3235

@@ -37,7 +40,7 @@ public static function alphabet(): string
3740
{
3841
$alphabet = config(key: 'sqids.alphabet');
3942

40-
if (!$alphabet || !is_string($alphabet)) {
43+
if (! $alphabet || ! is_string($alphabet)) {
4144
return static::$defaultAlphabet;
4245
}
4346

@@ -49,18 +52,21 @@ public static function minLength(): int
4952
/** @var int|null $minLength */
5053
$minLength = config(key: 'sqids.min_length', default: static::$defaultMinLength);
5154

52-
if (!$minLength || !is_int($minLength)) {
55+
if (! $minLength || ! is_int($minLength)) {
5356
return static::$defaultMinLength;
5457
}
5558

5659
return $minLength;
5760
}
5861

62+
/**
63+
* @return array<int, string>
64+
*/
5965
public static function blacklist(): array
6066
{
6167
$blacklist = config(key: 'sqids.blacklist', default: static::$defaultBlacklist);
6268

63-
if (!is_array($blacklist)) {
69+
if (! is_array($blacklist)) {
6470
return static::$defaultBlacklist;
6571
}
6672

@@ -71,7 +77,7 @@ public static function separator(): string
7177
{
7278
$separator = config(key: 'sqids.separator', default: static::$defaultSeparator);
7379

74-
if (!$separator || !is_string(value: $separator)) {
80+
if (! $separator || ! is_string(value: $separator)) {
7581
return static::$defaultSeparator;
7682
}
7783

@@ -82,7 +88,7 @@ public static function prefixClass(): ?Prefix
8288
{
8389
$prefix = config(key: 'sqids.prefix_class');
8490

85-
if (!$prefix) {
91+
if (! $prefix) {
8692
return null;
8793
}
8894

@@ -92,7 +98,7 @@ public static function prefixClass(): ?Prefix
9298
return new SimplePrefix();
9399
}
94100

95-
if (!$prefix instanceof Prefix) {
101+
if (! $prefix instanceof Prefix) {
96102
return new SimplePrefix();
97103
}
98104

tests/Prefixes/ConstantPrefixTest.php renamed to tests/Prefixes/ConsonantPrefixTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@
1212
->toBe(expected: 'cst')
1313
->prefix(model: Charge::class)
1414
->toBe(expected: 'chr');
15-
;
1615
});

tests/Prefixes/DefaultPrefixTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@
1212
->toBe(expected: 'cus')
1313
->prefix(model: Charge::class)
1414
->toBe(expected: 'cha');
15-
;
1615
});

tests/RouteModelBindingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424

2525
it('returns a 404 if the sqid is invalid', function (): void {
2626
$this
27-
->get(uri: "/customers/invalid-sqid")
27+
->get(uri: '/customers/invalid-sqid')
2828
->assertNotFound();
2929
});

workbench/database/migrations/2023_11_27_193203_create_customers_table.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
use Illuminate\Database\Schema\Blueprint;
77
use Illuminate\Support\Facades\Schema;
88

9-
return new class () extends Migration {
9+
return new class() extends Migration
10+
{
1011
/**
1112
* Run the migrations.
1213
*/

workbench/database/migrations/2023_11_27_193747_create_charges_table.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
use Illuminate\Database\Schema\Blueprint;
77
use Illuminate\Support\Facades\Schema;
88

9-
return new class () extends Migration {
9+
return new class() extends Migration
10+
{
1011
/**
1112
* Run the migrations.
1213
*/

workbench/routes/web.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
use Illuminate\Support\Facades\Route;
66
use Workbench\App\Models\Customer;
77

8-
Route::get(uri: 'customers/{customer}', action: fn(Customer $customer) => $customer->name);
8+
Route::get(uri: 'customers/{customer}', action: fn (Customer $customer) => $customer->name);

0 commit comments

Comments
 (0)