Skip to content

Commit e2f2e3b

Browse files
committed
improve phpstan
1 parent d3ac27f commit e2f2e3b

10 files changed

+74
-5
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"phpstan/extension-installer": "^1.2",
3131
"phpstan/phpstan-deprecation-rules": "^1.1.3",
3232
"phpstan/phpstan-phpunit": "^1.3.10",
33+
"phpstan/phpstan-strict-rules": "^1.5",
3334
"phpunit/phpunit": "^10.0.18",
3435
"rector/rector": "^0.15.23"
3536
},

phpstan-baseline.neon

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
parameters:
22
ignoreErrors:
3+
-
4+
message: "#^Only booleans are allowed in a negated boolean, array\\|bool\\|string\\|null given\\.$#"
5+
count: 1
6+
path: src/Commands/DeleteCommand.php
7+
8+
-
9+
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
10+
count: 1
11+
path: src/Commands/IndexCommand.php
12+
13+
-
14+
message: "#^Only booleans are allowed in a negated boolean, mixed given\\.$#"
15+
count: 1
16+
path: src/Commands/IndexCommand.php
17+
318
-
419
message: "#^Parameter \\#2 \\$haystack of function in_array expects array, array\\|string\\|true given\\.$#"
520
count: 1
@@ -20,6 +35,41 @@ parameters:
2035
count: 1
2136
path: src/Index/AbstractIndex.php
2237

38+
-
39+
message: "#^Casting to string something that's already string\\.$#"
40+
count: 1
41+
path: src/Index/AbstractIndex.php
42+
43+
-
44+
message: "#^Method Limenet\\\\LaravelElasticaBridge\\\\Index\\\\AbstractIndex\\:\\:getCreateArguments\\(\\) return type has no value type specified in iterable type array\\.$#"
45+
count: 1
46+
path: src/Index/AbstractIndex.php
47+
48+
-
49+
message: "#^Method Limenet\\\\LaravelElasticaBridge\\\\Index\\\\AbstractIndex\\:\\:getMapping\\(\\) return type has no value type specified in iterable type array\\.$#"
50+
count: 1
51+
path: src/Index/AbstractIndex.php
52+
53+
-
54+
message: "#^Method Limenet\\\\LaravelElasticaBridge\\\\Index\\\\AbstractIndex\\:\\:getSettings\\(\\) return type has no value type specified in iterable type array\\.$#"
55+
count: 1
56+
path: src/Index/AbstractIndex.php
57+
58+
-
59+
message: "#^Method Limenet\\\\LaravelElasticaBridge\\\\Index\\\\IndexInterface\\:\\:getCreateArguments\\(\\) return type has no value type specified in iterable type array\\.$#"
60+
count: 1
61+
path: src/Index/IndexInterface.php
62+
63+
-
64+
message: "#^Method Limenet\\\\LaravelElasticaBridge\\\\Index\\\\IndexInterface\\:\\:getMapping\\(\\) return type has no value type specified in iterable type array\\.$#"
65+
count: 1
66+
path: src/Index/IndexInterface.php
67+
68+
-
69+
message: "#^Method Limenet\\\\LaravelElasticaBridge\\\\Index\\\\IndexInterface\\:\\:getSettings\\(\\) return type has no value type specified in iterable type array\\.$#"
70+
count: 1
71+
path: src/Index/IndexInterface.php
72+
2373
-
2474
message: "#^Cannot access offset 'events' on Illuminate\\\\Contracts\\\\Foundation\\\\Application\\.$#"
2575
count: 1

phpstan.neon.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ parameters:
1010
tmpDir: build/phpstan
1111
checkOctaneCompatibility: true
1212
checkModelProperties: true
13-
checkMissingIterableValueType: false
13+
checkMissingIterableValueType: true
1414

src/Commands/DeleteCommand.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public function handle(): int
4545
return self::SUCCESS;
4646
}
4747

48+
/**
49+
* @return string[]
50+
*/
4851
private function inidices(): array
4952
{
5053
$indices = [];

src/Jobs/AbstractIndexJob.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public function uniqueId(): string
2727
return $this->indexConfig::class;
2828
}
2929

30+
/**
31+
* @return array<int,object>
32+
*/
3033
public function middleware(): array
3134
{
3235
return [

src/Jobs/PopulateBatchIndex.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(
3434

3535
public function handle(): void
3636
{
37-
if ($this->batch()?->cancelled()) {
37+
if ($this->batch()?->cancelled() === true) {
3838
return;
3939
}
4040

src/Jobs/PopulateIndex.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function __construct(
1818

1919
public function handle(): void
2020
{
21-
if ($this->batch()?->cancelled()) {
21+
if ($this->batch()?->cancelled() === true) {
2222
return;
2323
}
2424

src/Jobs/SetupIndex.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function __construct(
2424

2525
public function handle(ElasticaClient $elastica): void
2626
{
27-
if ($this->batch()?->cancelled()) {
27+
if ($this->batch()?->cancelled() === true) {
2828
return;
2929
}
3030
$this->migrate($elastica);

src/Model/ElasticsearchableInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ interface ElasticsearchableInterface
1414
*/
1515
public function getElasticsearchId(): string;
1616

17+
/**
18+
* @return array<int|string,mixed>
19+
*/
1720
public function toElasticsearch(IndexInterface $indexConfig): array;
1821

1922
public function shouldIndex(IndexInterface $indexConfig): bool;

src/Repository/IndexRepository.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@
1313
*/
1414
class IndexRepository
1515
{
16+
/**
17+
* @var array<class-string<IndexInterface>,IndexInterface>
18+
*/
1619
private array $indices;
1720

21+
/**
22+
* @param IndexInterface[] $indices
23+
*/
1824
public function __construct(array $indices)
1925
{
2026
foreach ($indices as $index) {
@@ -23,13 +29,16 @@ public function __construct(array $indices)
2329
}
2430

2531
/**
26-
* @return array<string,IndexInterface>
32+
* @return array<class-string<IndexInterface>,IndexInterface>
2733
*/
2834
public function all(): array
2935
{
3036
return $this->indices;
3137
}
3238

39+
/**
40+
* @param class-string<IndexInterface> $key
41+
*/
3342
public function get(string $key): IndexInterface
3443
{
3544
return $this->indices[$key];

0 commit comments

Comments
 (0)