Skip to content

Commit 71fd796

Browse files
PHPStan level 2 (#1179)
* PHPStan level 2 * Don't rely on phpdoc_to_comment * Enforce use of comments with @phpstan-ignore
1 parent 33ce9c3 commit 71fd796

File tree

148 files changed

+1592
-859
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+1592
-859
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2424
- Added union type declarations to method signatures
2525
- Solarium\Core\Query\Helper::formatDate() throws a `TypeError` instead of returning `false` if called with an incompatibly typed parameter
2626
- Managed resources queries no longer work around SOLR-6853 by default. Set the 'useDoubleEncoding' option to `true` if this bug affects you.
27+
- Solarium codebase is now analysed at PHPStan level 2
2728

2829
### Removed
2930
- Solarium\Component\Result\Stats\FacetValue::getFacets(), always returned `null`

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"nyholm/psr7": "^1.8",
3232
"php-http/guzzle7-adapter": "^1.0",
3333
"phpstan/extension-installer": "^1.4",
34-
"phpstan/phpstan": "^2.1",
34+
"phpstan/phpstan": "^2.1.41",
3535
"phpstan/phpstan-deprecation-rules": "^2.0",
3636
"phpstan/phpstan-phpunit": "^2.0",
3737
"phpunit/phpunit": "^10.5",

phpstan.dist.neon

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
parameters:
2-
level: 1
2+
level: 2
3+
reportIgnoresWithoutComments: true
34
paths:
45
- src
56
- tests
7+
universalObjectCratesClasses:
8+
- Solarium\Core\Query\DocumentInterface
9+
- Solarium\Core\Query\Result\QueryType

src/Builder/Analytics/AnalyticsExpressionVisitor.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ public function dispatch(ExpressionInterface $expr)
4242

4343
/**
4444
* {@inheritdoc}
45+
*
46+
* @param ExpressionInterface&FunctionInterface $expression
47+
*
48+
* @return mixed
4549
*/
4650
public function walkExpression(ExpressionInterface $expression)
4751
{

src/Builder/Analytics/FunctionBuilder.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Solarium\Builder\Analytics;
1313

1414
use Solarium\Builder\ExpressionInterface;
15+
use Solarium\Builder\FunctionInterface;
1516

1617
/**
1718
* FunctionBuilder.
@@ -20,7 +21,7 @@
2021
*/
2122
class FunctionBuilder
2223
{
23-
private ExpressionInterface $function;
24+
private ExpressionInterface&FunctionInterface $function;
2425

2526
private static ?ExpressionBuilder $expressionBuilder = null;
2627

@@ -45,21 +46,21 @@ public static function expr(): ExpressionBuilder
4546
}
4647

4748
/**
48-
* @param ExpressionInterface $function
49+
* @param ExpressionInterface&FunctionInterface $function
4950
*
5051
* @return self Provides fluent interface
5152
*/
52-
public function where(ExpressionInterface $function): self
53+
public function where(ExpressionInterface&FunctionInterface $function): self
5354
{
5455
$this->function = $function;
5556

5657
return $this;
5758
}
5859

5960
/**
60-
* @return ExpressionInterface
61+
* @return ExpressionInterface&FunctionInterface
6162
*/
62-
public function getFunction(): ExpressionInterface
63+
public function getFunction(): ExpressionInterface&FunctionInterface
6364
{
6465
return $this->function;
6566
}

src/Component/ComponentAwareQueryInterface.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ interface ComponentAwareQueryInterface
104104
/**
105105
* Get all registered component types.
106106
*
107-
* @return array
107+
* @return array<self::COMPONENT_*|string> An array of self::COMPONENT_* and/or self-registered keys
108108
*/
109109
public function getComponentTypes(): array;
110110

@@ -131,9 +131,9 @@ public function getComponents(): array;
131131
* You can optionally supply an autoload class to create a new component
132132
* instance if there is no registered component for the given key yet.
133133
*
134-
* @param string $key Use one of the constants
135-
* @param bool $autoload Autoload if component needs to be created
136-
* @param array|null $config Configuration to use for autoload
134+
* @param self::COMPONENT_*|string $key A self::COMPONENT_* or self-registered key
135+
* @param bool $autoload Autoload if component needs to be created
136+
* @param array|null $config Configuration to use for autoload
137137
*
138138
* @throws OutOfBoundsException
139139
*
@@ -146,8 +146,8 @@ public function getComponent(string $key, ?bool $autoload = false, ?array $confi
146146
*
147147
* This overwrites any existing component registered with the same key.
148148
*
149-
* @param string $key
150-
* @param AbstractComponent $component
149+
* @param self::COMPONENT_*|string $key A self::COMPONENT_* or self-registered key
150+
* @param AbstractComponent $component
151151
*
152152
* @return self Provides fluent interface
153153
*/
@@ -158,7 +158,7 @@ public function setComponent(string $key, AbstractComponent $component): self;
158158
*
159159
* You can remove a component by passing its key or the component instance.
160160
*
161-
* @param string|AbstractComponent $component
161+
* @param self::COMPONENT_*|string|AbstractComponent $component
162162
*
163163
* @return self Provides fluent interface
164164
*/

src/Component/ComponentAwareQueryTrait.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ trait ComponentAwareQueryTrait
3131
/**
3232
* Get all registered component types.
3333
*
34-
* @return array
34+
* @return array<self::COMPONENT_*|string> An array of self::COMPONENT_* and/or self-registered keys
3535
*/
3636
public function getComponentTypes(): array
3737
{
@@ -69,9 +69,9 @@ public function getComponents(): array
6969
* You can optionally supply an autoload class to create a new component
7070
* instance if there is no registered component for the given key yet.
7171
*
72-
* @param string $key Use one of the constants
73-
* @param bool $autoload Autoload if component needs to be created
74-
* @param array|null $config Configuration to use for autoload
72+
* @param self::COMPONENT_*|string $key A self::COMPONENT_* or self-registered key
73+
* @param bool $autoload Autoload if component needs to be created
74+
* @param array|null $config Configuration to use for autoload
7575
*
7676
* @throws OutOfBoundsException
7777
*
@@ -104,8 +104,8 @@ public function getComponent(string $key, ?bool $autoload = false, ?array $confi
104104
*
105105
* This overwrites any existing component registered with the same key.
106106
*
107-
* @param string $key
108-
* @param AbstractComponent $component
107+
* @param self::COMPONENT_*|string $key A self::COMPONENT_* or self-registered key
108+
* @param AbstractComponent $component
109109
*
110110
* @return self Provides fluent interface
111111
*/
@@ -122,7 +122,7 @@ public function setComponent(string $key, AbstractComponent $component): self
122122
*
123123
* You can remove a component by passing its key or the component instance.
124124
*
125-
* @param string|AbstractComponent $component
125+
* @param self::COMPONENT_*|string|AbstractComponent $component
126126
*
127127
* @return self Provides fluent interface
128128
*/

src/Component/Facet/FieldValueParametersInterface.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ public function getMatches(): ?string;
105105
/**
106106
* Set the facet sort type.
107107
*
108-
* Use one of the SORT_* constants as the value.
109-
*
110-
* @param string $sort
108+
* @param self::SORT_* $sort
111109
*/
112110
public function setSort(string $sort): static;
113111

@@ -177,9 +175,7 @@ public function getMissing(): ?bool;
177175
/**
178176
* Set the facet method.
179177
*
180-
* Use one of the METHOD_* constants as value.
181-
*
182-
* @param string $method
178+
* @param self::METHOD_* $method
183179
*/
184180
public function setMethod(string $method): static;
185181

src/Component/Facet/FieldValueParametersTrait.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ public function getMatches(): ?string
105105
/**
106106
* Set the facet sort type.
107107
*
108-
* Use one of the SORT_* constants as the value.
109-
*
110-
* @param string $sort
108+
* @param self::SORT_* $sort
111109
*/
112110
public function setSort(string $sort): static
113111
{
@@ -217,9 +215,7 @@ public function getMissing(): ?bool
217215
/**
218216
* Set the facet method.
219217
*
220-
* Use one of the METHOD_* constants as value.
221-
*
222-
* @param string $method
218+
* @param self::METHOD_* $method
223219
*/
224220
public function setMethod(string $method): static
225221
{

src/Component/Facet/JsonFacetInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
* @see https://solr.apache.org/guide/json-facet-api.html
1616
*/
17-
interface JsonFacetInterface
17+
interface JsonFacetInterface extends FacetInterface
1818
{
1919
/**
2020
* Serializes nested facets as option "facet" and returns that array structure.

0 commit comments

Comments
 (0)