Skip to content

Commit d68deea

Browse files
committed
update phpcs & phpstan
1 parent 362e56f commit d68deea

10 files changed

+53
-40
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
},
3030
"require-dev": {
3131
"ext-json": "*",
32-
"keboola/coding-standard": "^13.0",
32+
"keboola/coding-standard": "^15.0",
3333
"php-parallel-lint/php-parallel-lint": "^1.3",
34-
"phpstan/phpstan": "^1.4",
34+
"phpstan/phpstan": "^1.10",
3535
"phpunit/phpunit": ">=7.5 <=9.6",
36-
"phpstan/phpdoc-parser": "1.5.*"
36+
"phpstan/phpdoc-parser": "^1.25"
3737
},
3838
"scripts": {
3939
"phpstan": "phpstan analyse ./src ./tests --level=max --no-progress -c phpstan.neon",

phpcs.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@
2121
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
2222
<exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing"/>
2323
</rule>
24-
</ruleset>
24+
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration">
25+
<exclude name="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration.MissingTrailingComma"/>
26+
</rule>
27+
</ruleset>

phpstan-baseline-8+.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@ parameters:
275275
count: 1
276276
path: tests/CsvReadTest.php
277277

278+
-
279+
message: "#^Method Keboola\\\\Csv\\\\Tests\\\\CsvReadTest\\:\\:testNewlineDetectionEdgecaseWithCrLf\\(\\) has no return type specified\\.$#"
280+
count: 1
281+
path: tests/CsvReadTest.php
282+
278283
-
279284
message: "#^Method Keboola\\\\Csv\\\\Tests\\\\CsvReadTest\\:\\:testParse\\(\\) has no return type specified\\.$#"
280285
count: 1

phpstan-baseline.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@ parameters:
280280
count: 1
281281
path: tests/CsvReadTest.php
282282

283+
-
284+
message: "#^Method Keboola\\\\Csv\\\\Tests\\\\CsvReadTest\\:\\:testNewlineDetectionEdgecaseWithCrLf\\(\\) has no return type specified\\.$#"
285+
count: 1
286+
path: tests/CsvReadTest.php
287+
283288
-
284289
message: "#^Method Keboola\\\\Csv\\\\Tests\\\\CsvReadTest\\:\\:testParse\\(\\) has no return type specified\\.$#"
285290
count: 1

src/CsvOptions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected function validateEnclosure($enclosure)
5050
if (strlen($enclosure) > 1) {
5151
throw new InvalidArgumentException(
5252
'Enclosure must be a single character. ' . json_encode($enclosure) . ' received',
53-
Exception::INVALID_PARAM
53+
Exception::INVALID_PARAM,
5454
);
5555
}
5656
}
@@ -64,14 +64,14 @@ protected function validateDelimiter($delimiter)
6464
if (strlen($delimiter) > 1) {
6565
throw new InvalidArgumentException(
6666
'Delimiter must be a single character. ' . json_encode($delimiter) . ' received',
67-
Exception::INVALID_PARAM
67+
Exception::INVALID_PARAM,
6868
);
6969
}
7070

7171
if (strlen($delimiter) === 0) {
7272
throw new InvalidArgumentException(
7373
'Delimiter cannot be empty.',
74-
Exception::INVALID_PARAM
74+
Exception::INVALID_PARAM,
7575
);
7676
}
7777
}

src/CsvReader.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ protected function validateSkipLines($skipLines)
9393
if (!is_int($skipLines) || $skipLines < 0) {
9494
throw new InvalidArgumentException(
9595
"Number of lines to skip must be a positive integer. \"$skipLines\" received.",
96-
Exception::INVALID_PARAM
96+
Exception::INVALID_PARAM,
9797
);
9898
}
9999
}
@@ -107,14 +107,14 @@ protected function openCsvFile($fileName)
107107
if (!is_file($fileName)) {
108108
throw new Exception(
109109
'Cannot open file ' . $fileName,
110-
Exception::FILE_NOT_EXISTS
110+
Exception::FILE_NOT_EXISTS,
111111
);
112112
}
113113
$this->filePointer = @fopen($fileName, 'r');
114114
if (!$this->filePointer) {
115115
throw new Exception(
116116
"Cannot open file {$fileName} " . error_get_last()['message'],
117-
Exception::FILE_NOT_EXISTS
117+
Exception::FILE_NOT_EXISTS,
118118
);
119119
}
120120
}
@@ -126,7 +126,7 @@ protected function detectLineBreak()
126126
{
127127
@rewind($this->getFilePointer());
128128
$sample = @fread($this->getFilePointer(), self::SAMPLE_SIZE);
129-
if (substr($sample, -1) === "\r") {
129+
if (substr((string) $sample, -1) === "\r") {
130130
// we might have hit the file in the middle of CR+LF, only getting CR
131131
@rewind($this->getFilePointer());
132132
$sample = @fread($this->getFilePointer(), self::SAMPLE_SIZE+1);
@@ -161,7 +161,7 @@ protected function validateLineBreak()
161161

162162
throw new InvalidArgumentException(
163163
"Invalid line break. Please use unix \\n or win \\r\\n line breaks.",
164-
Exception::INVALID_PARAM
164+
Exception::INVALID_PARAM,
165165
);
166166
}
167167

src/CsvWriter.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private function validateLineBreak($lineBreak)
5555
throw new Exception(
5656
'Invalid line break: ' . json_encode($lineBreak) .
5757
' allowed line breaks: ' . json_encode($allowedLineBreaks),
58-
Exception::INVALID_PARAM
58+
Exception::INVALID_PARAM,
5959
);
6060
}
6161
}
@@ -72,14 +72,14 @@ protected function openCsvFile($fileName)
7272
throw new Exception(
7373
"Cannot open file {$fileName} " . $e->getMessage(),
7474
Exception::FILE_NOT_EXISTS,
75-
$e
75+
$e,
7676
);
7777
}
7878

7979
if (!$this->filePointer) {
8080
throw new Exception(
8181
"Cannot open file {$fileName} " . error_get_last()['message'],
82-
Exception::FILE_NOT_EXISTS
82+
Exception::FILE_NOT_EXISTS,
8383
);
8484
}
8585
}
@@ -100,7 +100,7 @@ public function writeRow(array $row)
100100
' Return: false' .
101101
' To write: ' . strlen($str) . ' Written: 0',
102102
Exception::WRITE_ERROR,
103-
$e
103+
$e,
104104
);
105105
}
106106

@@ -114,7 +114,7 @@ public function writeRow(array $row)
114114
($ret === false && error_get_last() ? 'Error: ' . error_get_last()['message'] : '') .
115115
' Return: ' . json_encode($ret) .
116116
' To write: ' . strlen($str) . ' Written: ' . (int) $ret,
117-
Exception::WRITE_ERROR
117+
Exception::WRITE_ERROR,
118118
);
119119
}
120120
}
@@ -138,7 +138,7 @@ public function rowToStr(array $row)
138138
)) {
139139
throw new Exception(
140140
'Cannot write data into column: ' . var_export($column, true),
141-
Exception::WRITE_ERROR
141+
Exception::WRITE_ERROR,
142142
);
143143
}
144144

tests/CsvReadTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public function testSkipsHeaders()
273273
CsvOptions::DEFAULT_DELIMITER,
274274
CsvOptions::DEFAULT_ENCLOSURE,
275275
CsvOptions::DEFAULT_ESCAPED_BY,
276-
1
276+
1,
277277
);
278278
self::assertEquals(['id', 'isImported'], $csvFile->getHeader());
279279
self::assertEquals([
@@ -292,7 +292,7 @@ public function testSkipNoLines()
292292
CsvOptions::DEFAULT_DELIMITER,
293293
CsvOptions::DEFAULT_ENCLOSURE,
294294
CsvOptions::DEFAULT_ESCAPED_BY,
295-
0
295+
0,
296296
);
297297
self::assertEquals(['id', 'isImported'], $csvFile->getHeader());
298298
self::assertEquals([
@@ -312,7 +312,7 @@ public function testSkipsMultipleLines()
312312
CsvOptions::DEFAULT_DELIMITER,
313313
CsvOptions::DEFAULT_ENCLOSURE,
314314
CsvOptions::DEFAULT_ESCAPED_BY,
315-
3
315+
3,
316316
);
317317
self::assertEquals(['id', 'isImported'], $csvFile->getHeader());
318318
self::assertEquals([
@@ -329,7 +329,7 @@ public function testSkipsOverflow()
329329
CsvOptions::DEFAULT_DELIMITER,
330330
CsvOptions::DEFAULT_ENCLOSURE,
331331
CsvOptions::DEFAULT_ESCAPED_BY,
332-
100
332+
100,
333333
);
334334
self::assertEquals(['id', 'isImported'], $csvFile->getHeader());
335335
self::assertEquals([], iterator_to_array($csvFile));
@@ -403,7 +403,7 @@ public function testInvalidSkipLines($skipLines, $message)
403403
CsvOptions::DEFAULT_DELIMITER,
404404
CsvOptions::DEFAULT_ENCLOSURE,
405405
CsvOptions::DEFAULT_ENCLOSURE,
406-
$skipLines
406+
$skipLines,
407407
);
408408
}
409409

@@ -482,9 +482,9 @@ public function testWriteReadInTheMiddle()
482482
'"1","first"',
483483
'"2","second"',
484484
'',
485-
]
485+
],
486486
),
487-
$data
487+
$data,
488488
);
489489
}
490490

@@ -532,7 +532,7 @@ public function testInvalidFile()
532532
public function testPerformance($fileContent, $expectedRows, $maxDuration)
533533
{
534534
self::markTestSkipped(
535-
'Run this test only manually. Because the duration is very different in local CI environment.'
535+
'Run this test only manually. Because the duration is very different in local CI environment.',
536536
);
537537

538538
try {

tests/CsvWriteTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ public function testWrite()
9191
'"true","1.123"',
9292
'"1","null"',
9393
'',
94-
]
94+
],
9595
),
96-
$data
96+
$data,
9797
);
9898
}
9999

@@ -150,9 +150,9 @@ public function testWriteValidObject()
150150
'"col1","col2"' ,
151151
'"1","me string"',
152152
'',
153-
]
153+
],
154154
),
155-
$data
155+
$data,
156156
);
157157
}
158158

@@ -211,9 +211,9 @@ public function testWritePointer()
211211
[
212212
'"col1","col2"' ,
213213
'foo,bar',
214-
]
214+
],
215215
),
216-
$data
216+
$data,
217217
);
218218
}
219219

@@ -233,15 +233,15 @@ public function testInvalidPointer()
233233
$or = new LogicalOr();
234234
$or->setConstraints([
235235
new StringContains(
236-
'Cannot write to CSV file Return: 0 To write: 14 Written: 0'
236+
'Cannot write to CSV file Return: 0 To write: 14 Written: 0',
237237
),
238238
new StringContains(
239239
'Cannot write to CSV file Error: fwrite(): ' .
240-
'write of 14 bytes failed with errno=9 Bad file descriptor Return: false To write: 14 Written: 0'
240+
'write of 14 bytes failed with errno=9 Bad file descriptor Return: false To write: 14 Written: 0',
241241
),
242242
new StringContains(
243243
'Cannot write to CSV file Error: fwrite(): ' .
244-
'Write of 14 bytes failed with errno=9 Bad file descriptor Return: false To write: 14 Written: 0'
244+
'Write of 14 bytes failed with errno=9 Bad file descriptor Return: false To write: 14 Written: 0',
245245
),
246246
]);
247247
self::assertThat($e->getMessage(), $or);
@@ -258,7 +258,7 @@ public function testInvalidPointer2()
258258
$rows = [['col1', 'col2']];
259259
self::expectException(Exception::class);
260260
self::expectExceptionMessage(
261-
'a valid stream resource Return: false To write: 14 Written: '
261+
'a valid stream resource Return: false To write: 14 Written: ',
262262
);
263263
$csvFile->writeRow($rows[0]);
264264
}
@@ -278,7 +278,7 @@ public function testWriteLineBreak()
278278
$fileName,
279279
CsvOptions::DEFAULT_DELIMITER,
280280
CsvOptions::DEFAULT_ENCLOSURE,
281-
"\r\n"
281+
"\r\n",
282282
);
283283
$rows = [
284284
[
@@ -300,9 +300,9 @@ public function testWriteLineBreak()
300300
'"col1","col2"',
301301
'"val1","val2"',
302302
'',
303-
]
303+
],
304304
),
305-
$data
305+
$data,
306306
);
307307
}
308308
}

tests/LineBreaksHelperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testLineBreaksDetection($enclosure, $escapedBy, $input, $expecte
3030
// Test line breaks detection
3131
self::assertSame(
3232
json_encode($expectedLineBreak),
33-
json_encode(LineBreaksHelper::detectLineBreaks($input, $enclosure, $escapedBy))
33+
json_encode(LineBreaksHelper::detectLineBreaks($input, $enclosure, $escapedBy)),
3434
);
3535
}
3636

0 commit comments

Comments
 (0)