Skip to content

Commit 2d931a2

Browse files
authored
Merge pull request #7 from Aeliot-Tm/dev_tools
Install PHPStan into dev dependencies
2 parents e8852d2 + 93b1683 commit 2d931a2

17 files changed

+149
-11
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,6 @@ jobs:
4545

4646
- name: Run test suite
4747
run: composer run-script test
48+
49+
- name: PHPStan analyse
50+
run: vendor/bin/phpstan analyse

composer.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
},
1212
"require-dev": {
1313
"phpunit/phpunit": "^9.5",
14-
"dg/bypass-finals": "^1.4"
14+
"dg/bypass-finals": "^1.4",
15+
"phpstan/phpstan": "^1.9",
16+
"phpstan/phpstan-phpunit": "^1.3",
17+
"phpstan/extension-installer": "^1.2"
1518
},
1619
"autoload": {
1720
"psr-4": {
@@ -28,6 +31,12 @@
2831
"bin/pccb_clover_compare"
2932
],
3033
"scripts": {
31-
"test": "vendor/bin/phpunit"
34+
"test": "vendor/bin/phpunit",
35+
"phpstan-analise": "vendor/bin/phpstan analyse"
36+
},
37+
"config": {
38+
"allow-plugins": {
39+
"phpstan/extension-installer": true
40+
}
3241
}
3342
}

phpstan-baseline.neon

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Return type of call to method PHPUnit\\\\Framework\\\\TestCase\\:\\:createMock\\(\\) contains unresolvable type\\.$#"
5+
count: 2
6+
path: tests/Unit/BaselineBuilderTest.php
7+
8+
-
9+
message: "#^Return type of call to method PHPUnit\\\\Framework\\\\TestCase\\:\\:createMock\\(\\) contains unresolvable type\\.$#"
10+
count: 2
11+
path: tests/Unit/ComparatorTest.php
12+
13+
-
14+
message: "#^Return type of call to method PHPUnit\\\\Framework\\\\TestCase\\:\\:createMock\\(\\) contains unresolvable type\\.$#"
15+
count: 1
16+
path: tests/Unit/Console/OptionsReaderTest.php
17+
18+
-
19+
message: "#^Return type of call to method PHPUnit\\\\Framework\\\\TestCase\\:\\:createMock\\(\\) contains unresolvable type\\.$#"
20+
count: 1
21+
path: tests/Unit/Model/ConsoleTableTest.php

phpstan.neon.dist

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
includes:
2+
- phpstan-baseline.neon
3+
4+
parameters:
5+
level: 7
6+
reportUnmatchedIgnoredErrors: false
7+
8+
paths:
9+
- bin
10+
- src
11+
- tests

src/Console/OptionsReader.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ private function filterDefinedByBothNames(array $data): array
8181
return $duplicates;
8282
}
8383

84+
/**
85+
* @param array<string,mixed> $data
86+
*
87+
* @return array<string,mixed>
88+
*/
8489
private function setDefaults(array $data): array
8590
{
8691
$options = $this->config->getOptions();

src/Model/ComparingRow.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public function hasRegress(): bool
3434
return 0 > $this->progress;
3535
}
3636

37+
/**
38+
* @return array<string,string>
39+
*/
3740
public function getValues(): array
3841
{
3942
$progressPrefix = (0 < $this->progress) ? '+' : '';

src/Model/ConsoleTable.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ final class ConsoleTable
1818
*/
1919
private array $columnsKeys;
2020

21+
/**
22+
* @var array<int,int>
23+
*/
2124
private array $columnsWidth;
2225

2326
/**
@@ -86,6 +89,9 @@ private function buildSeparateLine(): string
8689
return $this->buildTableLine(array_fill(0, count($this->columns), ''), '-');
8790
}
8891

92+
/**
93+
* @param array<int,string> $values
94+
*/
8995
private function buildTableLine(array $values, string $filler = ' '): string
9096
{
9197
foreach ($values as $index => $value) {

src/Reader/BaselineReader.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public function __construct(string $path)
2020
*/
2121
public function read(): array
2222
{
23-
/** @var array<string,int> $baseline */
2423
$baseline = $this->sanitize($this->getBaseline());
2524

2625
if (!$baseline) {
@@ -39,11 +38,11 @@ public function read(): array
3938
*/
4039
private function getBaseline(): array
4140
{
42-
if (!file_exists($this->path)) {
41+
if (!file_exists($this->path) || !is_file($this->path) || !is_readable($this->path)) {
4342
throw new \RuntimeException(sprintf('Code coverage baseline "%s" does not exist.', $this->path));
4443
}
4544

46-
$baseline = json_decode(file_get_contents($this->path), true, 512, JSON_THROW_ON_ERROR);
45+
$baseline = json_decode((string) file_get_contents($this->path), true, 512, JSON_THROW_ON_ERROR);
4746
if (!\is_array($baseline)) {
4847
throw new \DomainException('Cannot read baseline');
4948
}

src/Reader/CloverReader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ private function getAttributes(): \SimpleXMLElement
4848

4949
private function getClover(): \SimpleXMLElement
5050
{
51-
if (!file_exists($this->path)) {
51+
if (!file_exists($this->path) || !is_file($this->path) || !is_readable($this->path)) {
5252
throw new \RuntimeException(
5353
sprintf('Coverage clover file "%s" does not exist. Maybe it is not calculated yet.', $this->path)
5454
);
5555
}
5656

57-
$clover = simplexml_load_string(file_get_contents($this->path));
57+
$clover = simplexml_load_string((string) file_get_contents($this->path));
5858
if (!$clover instanceof \SimpleXMLElement) {
5959
// @codeCoverageIgnoreStart
6060
// NOTE: ignored case PHPUnit transforms Warning generated by simplexml_load_string() function

tests/Unit/BaselineBuilderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ public function testPositiveFlow(): void
1616
$data = ['a' => 1, 'b' => 2];
1717

1818
$baselineWriter = $this->createMock(BaselineWriter::class);
19-
$baselineWriter->expects($this->once())->method('write')->with($data);
19+
$baselineWriter->expects(self::once())->method('write')->with($data);
2020

2121
$cloverReader = $this->createMock(CloverReader::class);
22-
$cloverReader->expects($this->once())->method('read')->willReturn($data);
22+
$cloverReader->expects(self::once())->method('read')->willReturn($data);
2323

2424
(new BaselineBuilder($baselineWriter, $cloverReader))->build();
2525
}

tests/Unit/ComparatorTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ final class ComparatorTest extends TestCase
1313
{
1414
/**
1515
* @dataProvider getDataForTestPositiveFlow
16+
*
17+
* @param string[] $expected
18+
* @param array<string,int> $baseline
19+
* @param array<string,int> $cloverData
1620
*/
17-
public function testPositiveFlow(array $expected, array $baseline, array $cloverData): void
21+
public function testRegressedNamesPositiveFlow(array $expected, array $baseline, array $cloverData): void
1822
{
1923
$baselineReader = $this->createMock(BaselineReader::class);
2024
$baselineReader->method('read')->willReturn($baseline);
@@ -25,6 +29,13 @@ public function testPositiveFlow(array $expected, array $baseline, array $clover
2529
self::assertSame($expected, $comparator->compare()->getRegressedNames());
2630
}
2731

32+
/**
33+
* @return iterable<array{
34+
* 0: array<string>,
35+
* 1: array<string,int>,
36+
* 2: array<string,int>
37+
* }>
38+
*/
2839
public function getDataForTestPositiveFlow(): iterable
2940
{
3041
yield [

tests/Unit/Console/OptionsConfigTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public function testThrowExceptionOnInvalidShortName(): void
7676
(new OptionsConfig())->add('any_key', 'aa', 'any string');
7777
}
7878

79+
/**
80+
* @return iterable<array{ 0: array<string,string>, 1: array<int,array<int,string>> }>
81+
*/
7982
public function getDataForTestAliases(): iterable
8083
{
8184
$dataSet = [[], []];
@@ -88,6 +91,9 @@ public function getDataForTestAliases(): iterable
8891
}
8992
}
9093

94+
/**
95+
* @return iterable<array{ 0: array<string,array<string,string>>, 1: array<int,array<int,string>> }>
96+
*/
9197
public function getDataForTestOptions(): iterable
9298
{
9399
$dataSet = [[], []];
@@ -108,6 +114,9 @@ public function getDataForTestOptions(): iterable
108114
}
109115
}
110116

117+
/**
118+
* @return iterable<array{ 0: array<int,string>, 1: array<int,array<int,string>> }>
119+
*/
111120
public function getDataForTestPrepareLongOptions(): iterable
112121
{
113122
$dataSet = [[], []];
@@ -119,6 +128,9 @@ public function getDataForTestPrepareLongOptions(): iterable
119128
yield $dataSet;
120129
}
121130
}
131+
/**
132+
* @return iterable<array{ 0: string, 1: array<int,array<int,string>> }>
133+
*/
122134

123135
public function getDataForTestPrepareShortOptions(): iterable
124136
{
@@ -132,6 +144,9 @@ public function getDataForTestPrepareShortOptions(): iterable
132144
}
133145
}
134146

147+
/**
148+
* @return iterable<array<array<int,array<int,string>>>>
149+
*/
135150
public function getDataForTestThrowExceptionOnDuplicateName(): iterable
136151
{
137152
yield [[

tests/Unit/Console/OptionsReaderTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ public function testThrowExceptionOnDuplicates(array $values, array $options): v
5050
$this->buildOptionsReader($options, $values)->read();
5151
}
5252

53+
/**
54+
* @return iterable<array{ 0: array<string,string>, 1: array<int,array<string>> }>
55+
*/
5356
public function getDataForTestGetDefaultValues(): iterable
5457
{
5558
$dataSetForLongNames = [[], [], []];
@@ -69,6 +72,13 @@ public function getDataForTestGetDefaultValues(): iterable
6972
}
7073
}
7174

75+
/**
76+
* @return iterable<array{
77+
* 0: array<string,string>,
78+
* 1: array<string,string>,
79+
* 2: array<int,array<string>>
80+
* }>
81+
*/
7282
public function getDataForTestPositiveFlow(): iterable
7383
{
7484
$dataSetForLongNames = [[], [], []];
@@ -91,14 +101,17 @@ public function getDataForTestPositiveFlow(): iterable
91101
}
92102
}
93103

104+
/**
105+
* @return iterable<array{ 0: array<string,string|array<string>>, 1: array<int,array<string>> }>
106+
*/
94107
public function getDataForTestThrowExceptionOnDuplicates(): iterable
95108
{
96109
yield [['a' => ['value1', 'value2']], [['long_a', 'a', 'any string']]];
97110
yield [['a' => 'any string', 'long_a' => 'any string'], [['long_a', 'a', 'any string']]];
98111
}
99112

100113
/**
101-
* @param array<int,array<int,string>> $options
114+
* @param array<int,array<int|string,string>> $options
102115
*/
103116
private function buildOptionsConfig(array $options): OptionsConfig
104117
{
@@ -112,6 +125,7 @@ private function buildOptionsConfig(array $options): OptionsConfig
112125

113126
/**
114127
* @param array<int,array<int,string>> $options
128+
* @param array<string,string|array<int,string>> $values
115129
*/
116130
private function buildOptionsReader(array $options, array $values): OptionsReader
117131
{

tests/Unit/Model/ComparingRowTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,18 @@ public function testContainingOfRegress(): void
2525

2626
/**
2727
* @dataProvider getDataForTestNumbersFormattingOnJsonSerialise
28+
*
29+
* @param array<string,string> $expectedResult
2830
*/
2931
public function testNumbersFormattingOnJsonSerialise(array $expectedResult, float $old, float $new): void
3032
{
3133
$row = new ComparingRow($expectedResult['name'], $old, $new);
3234
self::assertSame($expectedResult, $row->getValues());
3335
}
3436

37+
/**
38+
* @return iterable<array{ 0: array<string,string>, 1: float, 2: float }>
39+
*/
3540
public function getDataForTestNumbersFormattingOnJsonSerialise(): iterable
3641
{
3742
yield 'no coverage' => [

tests/Unit/Model/ConsoleTableTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ public function testPrintHeaders(string $expected, array $columns): void
103103
self::assertSame($expected, (new ConsoleTable($columns))->getContent());
104104
}
105105

106+
/**
107+
* @return iterable<array{ 0: string, 1: array<int|string,string>, 2: array<int|string,string> }>
108+
*/
106109
public function getDataForTestAddComparingPositiveFlow(): iterable
107110
{
108111
yield 'with string keys' => [
@@ -138,6 +141,9 @@ public function getDataForTestAddComparingPositiveFlow(): iterable
138141
];
139142
}
140143

144+
/**
145+
* @return iterable<array{ 0: string, 1: array<int|string,string>, 2: array<int|string,string> }>
146+
*/
141147
public function getDataForTestAddComparingRowSortsValues(): iterable
142148
{
143149
yield 'string keys, sorted columns & values' => [
@@ -237,6 +243,9 @@ public function getDataForTestAddComparingRowSortsValues(): iterable
237243
];
238244
}
239245

246+
/**
247+
* @return iterable<array{ 0: array<int|string,string>, 1: array<int|string,string> }>
248+
*/
240249
public function getDataForTestAddComparingRowThrowsExceptionOnInvalidKey(): iterable
241250
{
242251
yield [
@@ -282,6 +291,9 @@ public function getDataForTestAddComparingRowThrowsExceptionOnInvalidKey(): iter
282291
];
283292
}
284293

294+
/**
295+
* @return iterable<array{ 0: array<int|string,string>, 1: array<int|string,string> }>
296+
*/
285297
public function getDataForTestAddComparingRowThrowsExceptionOnExtraKey(): iterable
286298
{
287299
yield [
@@ -309,12 +321,18 @@ public function getDataForTestAddComparingRowThrowsExceptionOnExtraKey(): iterab
309321
];
310322
}
311323

324+
/**
325+
* @return iterable<array{ 0: array<string>, 1: array<string> }>
326+
*/
312327
public function getDataForTestAddLineThrowsExceptionOnValuesCountNotSameAsColumns(): iterable
313328
{
314329
yield [['Column 1', 'Column 2'], ['Value 1']];
315330
yield [['Column 1', 'Column 2'], ['Value 1', 'Value 2', 'Value 3']];
316331
}
317332

333+
/**
334+
* @return iterable<array{ 0: string, 1: array<string>, 2: array<string> }>
335+
*/
318336
public function getDataForTestExtendsByColumn(): iterable
319337
{
320338
yield [
@@ -337,6 +355,9 @@ public function getDataForTestExtendsByColumn(): iterable
337355
];
338356
}
339357

358+
/**
359+
* @return iterable<array{ 0: string, 1: array<string>, 2: array<string> }>
360+
*/
340361
public function getDataForTestExtendsByValue(): iterable
341362
{
342363
yield [
@@ -359,6 +380,9 @@ public function getDataForTestExtendsByValue(): iterable
359380
];
360381
}
361382

383+
/**
384+
* @return iterable<array{ 0: string, 1: array<string> }>
385+
*/
362386
public function getDataForTestPrintHeaders(): iterable
363387
{
364388
yield [

0 commit comments

Comments
 (0)