Skip to content

Commit 78011f1

Browse files
committed
Add phpstan and fix errors
1 parent 098e1cc commit 78011f1

File tree

12 files changed

+55
-20
lines changed

12 files changed

+55
-20
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"require-dev": {
2727
"phpspec/phpspec": "^7.5",
2828
"rector/rector": "^1.1",
29-
"friendsofphp/php-cs-fixer": "^3.59"
29+
"friendsofphp/php-cs-fixer": "^3.59",
30+
"phpstan/phpstan": "^1.11"
3031
},
3132
"extra": {
3233
"branch-alias": {

phpstan-baseline.neon

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#"
5+
count: 1
6+
path: src/Result/ModifierCollection.php
7+
8+
-
9+
message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#"
10+
count: 1
11+
path: src/Specification.php

phpstan.neon

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
level: max
3+
paths:
4+
- src
5+
6+
includes:
7+
- phpstan-baseline.neon

src/Condition/Between.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class Between extends AbstractSpecification
99
{
10-
public function __construct(string $field, protected $from, protected $to, ?string $dqlAlias = null)
10+
public function __construct(string $field, protected mixed $from, protected mixed $to, ?string $dqlAlias = null)
1111
{
1212
parent::__construct($field, $dqlAlias);
1313
}

src/Query/Having.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class Having implements SpecificationInterface
1515
public const string AND_HAVING = 'andHaving';
1616
public const string OR_HAVING = 'orHaving';
1717

18+
/**
19+
* @var array<string>
20+
*/
1821
protected static array $types = [self::HAVING, self::AND_HAVING, self::OR_HAVING];
1922
protected string $type;
2023

src/Query/IndexBy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class IndexBy extends AbstractSpecification
1818
public function modify(QueryBuilder $queryBuilder, ?string $dqlAlias = null): ?string
1919
{
2020
$queryBuilder->indexBy(
21-
$this->dqlAlias ?? $dqlAlias,
21+
$this->dqlAlias ?? $dqlAlias ?? '',
2222
$this->createPropertyWithAlias($dqlAlias),
2323
);
2424

src/Query/Join.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,17 @@
1010
class Join extends AbstractSpecification
1111
{
1212
public const string JOIN = 'join';
13-
1413
public const string LEFT_JOIN = 'leftJoin';
15-
1614
public const string INNER_JOIN = 'innerJoin';
1715

16+
/**
17+
* @var array<string>
18+
*/
1819
protected static array $types = [self::JOIN, self::LEFT_JOIN, self::INNER_JOIN];
1920

2021
private ?string $conditionType = null;
21-
2222
private string|SpecificationInterface|null $condition = null;
23-
2423
private ?string $indexedBy = null;
25-
2624
private string $type = self::JOIN;
2725

2826
public function __construct(string $field, private readonly string $newAlias, ?string $dqlAlias = null)

src/Query/OrderBy.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
class OrderBy extends AbstractSpecification
1010
{
11-
public const ASC = 'ASC';
12-
13-
public const DESC = 'DESC';
14-
11+
public const string ASC = 'ASC';
12+
public const string DESC = 'DESC';
1513
protected ?string $order;
16-
14+
/**
15+
* @var array<string>
16+
*/
1717
private static array $validOrder = [self::ASC, self::DESC];
1818

1919
/**

src/Query/Select.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
class Select implements SpecificationInterface
1313
{
1414
public const string SELECT = 'select';
15-
1615
public const string ADD_SELECT = 'addSelect';
17-
16+
/**
17+
* @var array<string>
18+
*/
1819
protected static array $types = [self::SELECT, self::ADD_SELECT];
19-
2020
protected string $type;
2121

2222
/**
23+
* @param string|array<string> $select
24+
*
2325
* @throws InvalidArgumentException
2426
*/
2527
public function __construct(protected string|array $select, string $type = self::ADD_SELECT)

src/Result/ModifierCollection.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,25 @@
88

99
/**
1010
* CollectionResultModifierInterface allows to compose one/more ResultModifier classes.
11+
*
12+
* @extends ArrayCollection<int, ModifierInterface>
1113
*/
1214
class ModifierCollection extends ArrayCollection implements ModifierInterface
1315
{
1416
/**
1517
* Compose one or more ResultModifier and evaluate as a single modifier.
18+
*
19+
* @param ModifierInterface ...$modifiers
20+
*
21+
* @throws InvalidArgumentException
1622
*/
1723
public function __construct(mixed ...$modifiers)
1824
{
1925
parent::__construct();
2026

21-
array_map($this->add(...), $modifiers);
27+
foreach ($modifiers as $modifier) {
28+
$this->add($modifier);
29+
}
2230
}
2331

2432
/**
@@ -38,8 +46,6 @@ public function add(mixed $value): void
3846

3947
/**
4048
* Modify the query (e.g. select more fields/relations).
41-
*
42-
* @throws InvalidArgumentException
4349
*/
4450
#[\Override]
4551
public function modify(AbstractQuery $query): void

0 commit comments

Comments
 (0)