Skip to content

Commit 4f7c38e

Browse files
committed
use phpstan 2 and remove unnecessary checks that strict typing already covers
1 parent c6b23da commit 4f7c38e

File tree

9 files changed

+25
-98
lines changed

9 files changed

+25
-98
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
},
3434
"require-dev": {
3535
"ramsey/uuid": "^3.5",
36-
"phpunit/phpunit": "^7.5 || ^8.0 || ^9.0",
37-
"phpstan/phpstan": "^1.9",
36+
"phpunit/phpunit": "^9.0",
37+
"phpstan/phpstan": "^2.1",
3838
"friendsofphp/php-cs-fixer": "^3.40"
3939
},
4040
"suggest": {

phpstan.neon.dist

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,3 @@ parameters:
99
message: "#^Empty array passed to foreach\\.$#"
1010
count: 5
1111
path: src/PHPCR/Util/Console/Helper/PhpcrHelper.php
12-
# only formulated in phpdoc that the return value must be countable
13-
-
14-
message: "#expects array|Countable, Iterator<mixed, PHPCR\\Query\\RowInterface> given\\.$#"
15-
count: 1
16-
path: src/PHPCR/Util/Console/Command/NodesUpdateCommand.php

phpstan.tests.neon.dist

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,3 @@ parameters:
66
excludePaths:
77
analyse:
88
- tests/*/Fixtures/*
9-
10-
ignoreErrors:
11-
# too pedantic for tests
12-
-
13-
message: "#^Parameter \\#1 \\.\\.\\.\\$arrays of function array_merge expects array, array\\<int, string\\>\\|false given\\.$#"
14-
count: 1
15-
path: tests/PHPCR/Tests/Util/CND/Reader/FileReaderTest.php
16-
17-
-
18-
message: "#^Parameter \\#3 \\.\\.\\.\\$arrays of function array_merge expects array, array\\<int, string\\>\\|false given\\.$#"
19-
count: 1
20-
path: tests/PHPCR/Tests/Util/CND/Reader/FileReaderTest.php

src/PHPCR/Util/CND/Parser/AbstractParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected function checkToken(int $type, ?string $data = null, bool $ignoreCase
4444
}
4545

4646
if ($data && $token->getData() !== $data) {
47-
if ($ignoreCase && is_string($data) && is_string($token->getData())) {
47+
if ($ignoreCase) {
4848
return 0 !== strcasecmp($data, $token->getData());
4949
}
5050

src/PHPCR/Util/QOM/Sql2Generator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ public function evalColumns(iterable $columns): string
270270
public function evalColumn(string $selectorName, ?string $propertyName = null, ?string $colname = null): string
271271
{
272272
$sql2 = '';
273-
if (null !== $selectorName && null === $propertyName && null === $colname) {
273+
if (null === $propertyName && null === $colname) {
274274
$sql2 .= $this->addBracketsIfNeeded($selectorName).'.*';
275275
} else {
276276
$sql2 .= $this->evalPropertyValue($propertyName, $selectorName);

tests/PHPCR/Tests/Util/CND/Reader/FileReaderTest.php

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,33 @@
99

1010
class FileReaderTest extends TestCase
1111
{
12-
/**
13-
* @var string
14-
*/
15-
private $filepath;
16-
17-
/**
18-
* @var FileReader
19-
*/
20-
private $reader;
12+
private string $filepath;
2113

22-
/**
23-
* @var string[]
24-
*/
25-
private $lines;
14+
private FileReader $reader;
2615

2716
/**
2817
* @var string[]
2918
*/
30-
private $chars;
19+
private array $chars;
3120

3221
public function setUp(): void
3322
{
3423
$this->filepath = __DIR__.'/../Fixtures/files/TestFile.txt';
3524
$this->reader = new FileReader($this->filepath);
3625

37-
$this->lines = [
26+
$lines = [
3827
'This is a test file...',
3928
'',
4029
'...containing dummy content.',
4130
'',
4231
];
4332

4433
$this->chars = array_merge(
45-
preg_split('//', $this->lines[0], -1, PREG_SPLIT_NO_EMPTY),
34+
/* @phpstan-ignore argument.type */ // our fixtures are expected to be without error, no need to check if split worked
35+
preg_split('//', $lines[0], -1, PREG_SPLIT_NO_EMPTY),
4636
["\n", "\n"],
47-
preg_split('//', $this->lines[2], -1, PREG_SPLIT_NO_EMPTY),
37+
/* @phpstan-ignore argument.type */
38+
preg_split('//', $lines[2], -1, PREG_SPLIT_NO_EMPTY),
4839
["\n", "\n"]
4940
);
5041
}

tests/PHPCR/Tests/Util/Console/Command/WorkspaceExportCommandTest.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,12 @@ public function testNodeTypeList(): void
3535
$this->session->expects($this->once())
3636
->method('exportSystemView');
3737

38-
if (method_exists($this, 'assertFileDoesNotExist')) {
39-
$this->assertFileDoesNotExist('test', 'test export file must not exist, it will be overwritten');
40-
} else {
41-
// support phpunit 8 and older, can be removed when we only support php 9 or newer
42-
$this->assertFileNotExists('test', 'test export file must not exist, it will be overwritten');
43-
}
38+
$this->assertFileDoesNotExist('test', 'test export file must not exist, it will be overwritten');
4439

4540
$ct = $this->executeCommand('phpcr:workspace:export', [
4641
'filename' => 'test',
4742
]);
4843

49-
if (method_exists($ct, 'getStatusCode')) {
50-
// Only available since symfony 2.4
51-
$this->assertEquals(0, $ct->getStatusCode());
52-
}
53-
$this->assertFileExists('test');
44+
$this->assertEquals(0, $ct->getStatusCode());
5445
}
5546
}

tests/PHPCR/Tests/Util/QOM/QueryBuilderTest.php

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ class QueryBuilderTest extends TestCase
2626
public function setUp(): void
2727
{
2828
$this->qf = $this->getMockBuilder(QueryObjectModelFactoryInterface::class)
29-
->setMethods([])
30-
->setConstructorArgs([])
3129
->getMock();
3230
}
3331

@@ -45,18 +43,10 @@ public function testSetMaxResults(): void
4543
$this->assertEquals(15, $qb->getMaxResults());
4644
}
4745

48-
/**
49-
* @return DynamicOperandInterface
50-
*/
51-
private function createDynamicOperandMock()
46+
private function createDynamicOperandMock(): DynamicOperandInterface
5247
{
53-
/** @var DynamicOperandInterface $dynamicOperand */
54-
$dynamicOperand = $this->getMockBuilder(DynamicOperandInterface::class)
55-
->setMethods([])
56-
->setConstructorArgs([])
48+
return $this->getMockBuilder(DynamicOperandInterface::class)
5749
->getMock();
58-
59-
return $dynamicOperand;
6050
}
6151

6252
public function testAddOrderBy(): void
@@ -137,18 +127,10 @@ public function testOrderAscendingIsDefault(): void
137127
$qb->addOrderBy($dynamicOperand);
138128
}
139129

140-
/**
141-
* @return ConstraintInterface
142-
*/
143-
private function createConstraintMock()
130+
private function createConstraintMock(): ConstraintInterface
144131
{
145-
/** @var ConstraintInterface $constraint */
146-
$constraint = $this->getMockBuilder(ConstraintInterface::class)
147-
->setMethods([])
148-
->setConstructorArgs([])
132+
return $this->getMockBuilder(ConstraintInterface::class)
149133
->getMock();
150-
151-
return $constraint;
152134
}
153135

154136
public function testWhere(): void
@@ -206,18 +188,10 @@ public function testAddSelect(): void
206188
$this->assertCount(2, $qb->getColumns());
207189
}
208190

209-
/**
210-
* @return SourceInterface
211-
*/
212-
private function createSourceMock()
191+
private function createSourceMock(): SourceInterface
213192
{
214-
/** @var SourceInterface $source */
215-
$source = $this->getMockBuilder(SourceInterface::class)
216-
->setMethods([])
217-
->setConstructorArgs([])
193+
return $this->getMockBuilder(SourceInterface::class)
218194
->getMock();
219-
220-
return $source;
221195
}
222196

223197
public function testFrom(): void
@@ -229,18 +203,10 @@ public function testFrom(): void
229203
$this->assertEquals($source, $qb->getSource());
230204
}
231205

232-
/**
233-
* @return SameNodeJoinConditionInterface
234-
*/
235-
private function createSameNodeJoinConditionMock()
206+
private function createSameNodeJoinConditionMock(): SameNodeJoinConditionInterface
236207
{
237-
/** @var SameNodeJoinConditionInterface $joinCondition */
238-
$joinCondition = $this->getMockBuilder(SameNodeJoinConditionInterface::class)
239-
->setMethods([])
240-
->setConstructorArgs([])
208+
return $this->getMockBuilder(SameNodeJoinConditionInterface::class)
241209
->getMock();
242-
243-
return $joinCondition;
244210
}
245211

246212
public function testInvalidJoin(): void
@@ -335,12 +301,8 @@ public function testGetQuery(): void
335301
*/
336302
private function createQueryMock()
337303
{
338-
$query = $this->getMockBuilder(QueryObjectModelInterface::class)
339-
->setMethods([])
340-
->setConstructorArgs([])
304+
return $this->getMockBuilder(QueryObjectModelInterface::class)
341305
->getMock();
342-
343-
return $query;
344306
}
345307

346308
public function testGetQueryWithOffsetAndLimit(): void

tests/PHPCR/Tests/Util/ValueConverterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function setUp(): void
2626
}
2727

2828
/**
29-
* @return array<array{0: string, 1: int, 2: mixed, 3: mixed}>
29+
* @return array<array{0: mixed, 1: int, 2: mixed, 3: mixed}>
3030
*/
3131
public function dataConversionMatrix(): array
3232
{
@@ -284,7 +284,7 @@ public function testConvertType(mixed $value, int $srcType, mixed $expected, int
284284
$this->fail('Expected that this conversion would throw an exception');
285285
} catch (ValueFormatException $e) {
286286
// expected
287-
$this->assertTrue(true); // make it assert something
287+
$this->addToAssertionCount(1);
288288
}
289289
} else {
290290
if ($expected instanceof \DateTime) {

0 commit comments

Comments
 (0)