Skip to content

Commit 69f1804

Browse files
committed
Fix Psalm, Phpstan and unit tests.
1 parent e491551 commit 69f1804

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

src/Tools/ContextGenerator.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use function basename;
1414
use function count;
1515
use function dirname;
16-
use function file;
16+
use function end;
1717
use function file_put_contents;
1818
use function implode;
1919
use function ksort;
@@ -169,14 +169,8 @@ public static function sortWords(array &$arr)
169169
*/
170170
public static function readWords(array $files)
171171
{
172-
$wordsByFile = array_map(
173-
static function (string $file): array {
174-
return file($file);
175-
},
176-
$files
177-
);
178172
/** @psalm-var list<string> $words */
179-
$words = array_merge(...$wordsByFile);
173+
$words = array_merge(...array_map('\\file', $files));
180174

181175
/** @var array<string, int> $types */
182176
$types = [];
@@ -290,7 +284,7 @@ public static function formatName($name)
290284
{
291285
/* Split name and version */
292286
$parts = [];
293-
if (preg_match('/([^[0-9]*)([0-9]*)/', $name, $parts) === false) {
287+
if (preg_match('/^(\D+)(\d+)$/', $name, $parts) === 0) {
294288
return $name;
295289
}
296290

@@ -311,10 +305,10 @@ public static function formatName($name)
311305
$versionString = '0' . $versionString;
312306
}
313307

314-
$version = array_map('intval', str_split($versionString, 2));
308+
$version = array_map('\\intval', str_split($versionString, 2));
315309
/* Remove trailing zero */
316-
if ($version[count($version) - 1] === 0) {
317-
$version = array_slice($version, 0, count($version) - 1);
310+
if (end($version) === 0) {
311+
$version = array_slice($version, 0, -1);
318312
}
319313

320314
/* Create name */

tests/Tools/ContextGeneratorTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class ContextGeneratorTest extends TestCase
1515
{
1616
public function testFormatName(): void
1717
{
18+
$name = ContextGenerator::formatName('00InvalidFormat00');
19+
$this->assertEquals('00InvalidFormat00', $name);
20+
1821
$name = ContextGenerator::formatName('MySql80000');
1922
$this->assertEquals('MySQL 8.0', $name);
2023

@@ -23,6 +26,9 @@ public function testFormatName(): void
2326

2427
$name = ContextGenerator::formatName('MariaDb100000');
2528
$this->assertEquals('MariaDB 10.0', $name);
29+
30+
$name = ContextGenerator::formatName('FutureDBMS45784012500');
31+
$this->assertEquals('FutureDBMS 4.57.84.1.25', $name);
2632
}
2733

2834
public function testSortWords(): void

tests/Tools/contexts/testContext.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
RESERVED (R)
2-
RESERVED2 (R)
3-
RESERVED3 (R)
4-
RESERVED4 (R)
5-
RESERVED5 (R)
2+
RESERVED2 (R)
3+
RESERVED3 (R)
4+
RESERVED4 (R)
5+
reserved5 (R)
66

77
FUNCTION (F)
88
DATATYPE (D)
99
KEYWORD (K)
1010

11+
12+
1113
NO_FLAG
1214
COMPOSED KEYWORD
1315

14-
FUNCTION
16+
FUNCTION

0 commit comments

Comments
 (0)