Skip to content

Commit 5331d94

Browse files
authored
Upgrade static analysis to PHPStan level 2 (predis#1043)
* Upgrade static analysis to PHPStan level 2 * Fix CS and CI * Fix coverage path * Start debugging * Stop debugging
1 parent 74d5ad2 commit 5331d94

File tree

7 files changed

+72
-23
lines changed

7 files changed

+72
-23
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
/VERSION export-ignore
1515
/phpunit.xml.dist export-ignore
1616
/phpstan.dist.neon export-ignore
17+
/phpstan-tests.dist.neon export-ignore

.github/workflows/linters.yml

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ jobs:
8282
- name: Perform static analysis
8383
run: composer run phpstan
8484

85+
- name: Perform static analysis on tests
86+
run: composer run phpstan -- --configuration=phpstan-tests.dist.neon
87+
8588
coding_standards:
8689
name: Coding Standards
8790
needs:

.github/workflows/tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464

6565
- name: Run PHPUnit tests with coverage
6666
if: ${{ matrix.php == '8.1' && matrix.redis == '7' }}
67-
run: vendor/bin/phpunit --verbose --coverage-clover build/logs/clover.xml --coverage-filter src
67+
run: vendor/bin/phpunit --verbose --coverage-clover build/logs/clover.xml --coverage-filter ./src
6868

6969
- name: Send coverage to Coveralls
7070
env:

phpstan-tests.dist.neon

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
parameters:
2+
level: 0
3+
4+
paths:
5+
- tests/
6+
7+
ignoreErrors:
8+
# Uses func_get_args()
9+
- message: "#^Static method Predis\\\\Command\\\\RawCommand\\:\\:create\\(\\) invoked with 0 parameters, at least 1 required\\.$#"
10+
count: 1
11+
path: tests/Predis/Command/RawCommandTest.php
12+
# Mockery
13+
- message: "#^Call to an undefined method Predis\\\\Configuration\\\\Option\\\\AggregateTest\\:\\:getMockConnectionClass\\(\\)\\.$#"
14+
count: 2
15+
path: tests/Predis/Configuration/Option/AggregateTest.php

phpstan.dist.neon

+45-14
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,56 @@
11
parameters:
2-
level: 0
2+
level: 2
33

44
paths:
5-
- src
6-
- tests
5+
- src/
76

87
ignoreErrors:
9-
- '#^Function phpiredis_\w+ not found\.$#'
10-
-
11-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
8+
# Tricky ones
9+
- message: "#^Cannot cast Predis\\\\Response\\\\ResponseInterface to string\\.$#"
10+
count: 1
11+
path: src/Client.php
12+
- message: "#^Cannot cast Predis\\\\Connection\\\\ConnectionInterface to string\\.$#"
13+
count: 1
14+
path: src/Client.php
15+
# phpiredis extension is not installed
16+
- "#^Function phpiredis_\\w+ not found\\.$#"
17+
- "#^Constant PHPIREDIS_#"
18+
# "new static" in non-final classes
19+
- message: "#^Unsafe usage of new static\\(\\)\\.$#"
1220
count: 3
1321
path: src/Client.php
14-
-
15-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
22+
- message: "#^Unsafe usage of new static\\(\\)\\.$#"
1623
count: 1
1724
path: src/Connection/Parameters.php
18-
-
19-
message: "#^Static method Predis\\\\Command\\\\RawCommand\\:\\:create\\(\\) invoked with 0 parameters, at least 1 required\\.$#"
25+
# Using an interface as concrete type
26+
- message: "#^Call to an undefined method Predis\\\\Command\\\\FactoryInterface\\:\\:define\\(\\)\\.$#"
27+
count: 1
28+
path: src/Configuration/Option/Commands.php
29+
- message: "#^Call to an undefined method Predis\\\\Command\\\\FactoryInterface\\:\\:undefine\\(\\)\\.$#"
30+
count: 1
31+
path: src/Configuration/Option/Commands.php
32+
- message: "#^Access to an undefined property Predis\\\\Configuration\\\\OptionsInterface\\:\\:\\$parameters\\.$#"
2033
count: 1
21-
path: tests/Predis/Command/RawCommandTest.php
22-
-
23-
message: "#^Call to an undefined method Predis\\\\Configuration\\\\Option\\\\AggregateTest\\:\\:getMockConnectionClass\\(\\)\\.$#"
34+
path: src/Configuration/Option/Connections.php
35+
- message: "#^Access to an undefined property Predis\\\\Connection\\\\ParametersInterface\\:\\:\\$weight\\.$#"
36+
count: 1
37+
path: src/Connection/Cluster/PredisCluster.php
38+
- message: "#^Variable \\$response might not be defined\\.$#"
2439
count: 2
25-
path: tests/Predis/Configuration/Option/AggregateTest.php
40+
path: src/Connection/Cluster/RedisCluster.php
41+
- message: "#^Access to an undefined property Predis\\\\Connection\\\\ParametersInterface\\:\\:\\$role\\.$#"
42+
count: 1
43+
path: src/Connection/Replication/MasterSlaveReplication.php
44+
- message: "#^Access to an undefined property Predis\\\\Connection\\\\ParametersInterface\\:\\:\\$role\\.$#"
45+
count: 1
46+
path: src/Connection/Replication/SentinelReplication.php
47+
# try/catch problems
48+
- message: "#^Variable \\$connection might not be defined\\.$#"
49+
count: 1
50+
path: src/Connection/Replication/MasterSlaveReplication.php
51+
- message: "#^Variable \\$response might not be defined\\.$#"
52+
count: 1
53+
path: src/Connection/Replication/MasterSlaveReplication.php
54+
- message: "#^Variable \\$response might not be defined\\.$#"
55+
count: 1
56+
path: src/Connection/Replication/SentinelReplication.php

tests/PHPUnit/PredisCommandTestCase.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ protected function isPrefixable(): bool
7979
/**
8080
* Returns a new command instance with the specified arguments.
8181
*
82-
* @param ... List of arguments for the command
82+
* @param mixed ...$arguments List of arguments for the command
8383
*
8484
* @return CommandInterface
8585
*/

tests/Predis/Configuration/Option/ConnectionsTest.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
namespace Predis\Configuration\Option;
1414

15-
use PHPUnit\Framework\MockObject\MockObject;
1615
use Predis\Configuration\OptionsInterface;
1716
use PredisTestCase;
1817
use stdClass;
@@ -37,7 +36,7 @@ public function testDefaultOptionValue(): void
3736
*/
3837
public function testAcceptsNamedArrayWithSchemeToConnectionClassMappings(): void
3938
{
40-
/** @var OptionsInterface */
39+
/** @var \Predis\Configuration\OptionsInterface */
4140
$options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock();
4241

4342
$class = get_class($this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock());
@@ -49,7 +48,7 @@ public function testAcceptsNamedArrayWithSchemeToConnectionClassMappings(): void
4948
->method('define')
5049
->with($this->matchesRegularExpression('/^tcp|redis$/'), $class);
5150

52-
/** @var OptionInterface */
51+
/** @var \Predis\Configuration\OptionInterface */
5352
$option = $this->getMockBuilder('Predis\Configuration\Option\Connections')
5453
->onlyMethods(['getDefault'])
5554
->getMock();
@@ -140,7 +139,7 @@ public function testUsesParametersOptionToSetDefaultParameters(): void
140139
{
141140
$parameters = ['database' => 5, 'password' => 'mypassword'];
142141

143-
/** @var OptionsInterface|MockObject */
142+
/** @var \Predis\Configuration\OptionsInterface|\PHPUnit\Framework\MockObject\MockObject\MockObject */
144143
$options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock();
145144
$options
146145
->expects($this->once())
@@ -164,7 +163,7 @@ public function testUsesParametersOptionToSetDefaultParameters(): void
164163
*/
165164
public function testAcceptsConnectionFactoryInstance(): void
166165
{
167-
/** @var OptionInterface */
166+
/** @var \Predis\Configuration\OptionInterface */
168167
$option = $this->getMockBuilder('Predis\Configuration\Option\Connections')
169168
->onlyMethods(['getDefault'])
170169
->getMock();
@@ -185,7 +184,7 @@ public function testAcceptsCallableReturningConnectionFactoryInstance(): void
185184
{
186185
$option = new Connections();
187186

188-
/** @var OptionsInterface */
187+
/** @var \Predis\Configuration\OptionsInterface */
189188
$options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock();
190189

191190
$callable = $this->getMockBuilder('stdClass')
@@ -212,7 +211,7 @@ public function testThrowsExceptionOnInvalidArguments(): void
212211

213212
$option = new Connections();
214213

215-
/** @var OptionsInterface */
214+
/** @var \Predis\Configuration\OptionsInterface */
216215
$options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock();
217216

218217
$option->filter($options, new stdClass());

0 commit comments

Comments
 (0)