Skip to content

Commit ea0ecdd

Browse files
authored
Fix PHPStan baselined errors (#91)
1 parent f37ea54 commit ea0ecdd

File tree

5 files changed

+10
-68
lines changed

5 files changed

+10
-68
lines changed

phpstan-baseline.neon

-66
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,5 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: '#^Call to function is_string\(\) with class\-string\<FileEye\\MimeMap\\Map\\MimeMapInterface\> will always evaluate to true\.$#'
5-
identifier: function.alreadyNarrowedType
6-
count: 1
7-
path: src/Command/UpdateCommand.php
8-
9-
-
10-
message: '#^Cannot access offset 0 on mixed\.$#'
11-
identifier: offsetAccess.nonOffsetAccessible
12-
count: 1
13-
path: src/Command/UpdateCommand.php
14-
15-
-
16-
message: '#^Cannot access offset 1 on mixed\.$#'
17-
identifier: offsetAccess.nonOffsetAccessible
18-
count: 1
19-
path: src/Command/UpdateCommand.php
20-
21-
-
22-
message: '#^Cannot access offset 2 on mixed\.$#'
23-
identifier: offsetAccess.nonOffsetAccessible
24-
count: 1
25-
path: src/Command/UpdateCommand.php
26-
27-
-
28-
message: '#^Parameter \#2 \$args of function call_user_func_array expects array\<int\|string, mixed\>, mixed given\.$#'
29-
identifier: argument.type
30-
count: 1
31-
path: src/Command/UpdateCommand.php
32-
33-
-
34-
message: '#^Part \$command\[0\] \(mixed\) of encapsed string cannot be cast to string\.$#'
35-
identifier: encapsedStringPart.nonString
36-
count: 1
37-
path: src/Command/UpdateCommand.php
38-
39-
-
40-
message: '#^Part \$error \(mixed\) of encapsed string cannot be cast to string\.$#'
41-
identifier: encapsedStringPart.nonString
42-
count: 1
43-
path: src/Command/UpdateCommand.php
44-
453
-
464
message: '#^Method FileEye\\MimeMap\\Map\\BaseMap\:\:getMapSubEntry\(\) should return list\<string\> but returns array\<int, string\>\.$#'
475
identifier: return.type
@@ -53,27 +11,3 @@ parameters:
5311
identifier: return.type
5412
count: 1
5513
path: src/Map/BaseMap.php
56-
57-
-
58-
message: '#^Binary operation "\." between ''\: '' and mixed results in an error\.$#'
59-
identifier: binaryOp.invalid
60-
count: 1
61-
path: src/MapUpdater.php
62-
63-
-
64-
message: '#^Parameter \#1 \$format of method FileEye\\MimeMap\\Type\:\:toString\(\) expects int, mixed given\.$#'
65-
identifier: argument.type
66-
count: 7
67-
path: src/Type.php
68-
69-
-
70-
message: '#^Parameter \#1 \$format of method FileEye\\MimeMap\\TypeInterface\:\:toString\(\) expects int, mixed given\.$#'
71-
identifier: argument.type
72-
count: 3
73-
path: src/Type.php
74-
75-
-
76-
message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''FileEye\\\\MimeMap\\\\TypeParameter'' and FileEye\\MimeMap\\TypeParameter will always evaluate to true\.$#'
77-
identifier: method.alreadyNarrowedType
78-
count: 1
79-
path: tests/src/TypeTest.php

src/Command/UpdateCommand.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7474
return (2);
7575
}
7676

77-
/** @var class-string<MimeMapInterface> $mapClass */
7877
$mapClass = $input->getOption('class');
7978
if (!is_string($mapClass)) {
8079
$io->error('Invalid value for --class option.');
@@ -99,13 +98,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9998
return (2);
10099
}
101100

101+
/** @var list<array{0: string, 1: string, 2: array<mixed>}> $commands */
102102
foreach ($commands as $command) {
103103
$output->writeln("<info>{$command[0]} ...</info>");
104104
try {
105105
$callable = [$updater, $command[1]];
106106
assert(is_callable($callable));
107107
$errors = call_user_func_array($callable, $command[2]);
108108
if (is_array($errors) && !empty($errors)) {
109+
/** @var list<string> $errors */
109110
foreach ($errors as $error) {
110111
$output->writeln("<comment>$error.</comment>");
111112
}
@@ -117,6 +118,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
117118
}
118119

119120
// Load the map to be changed.
121+
/** @var class-string<MimeMapInterface> $mapClass */
120122
MapHandler::setDefaultMapClass($mapClass);
121123
$current_map = MapHandler::map();
122124

src/MapUpdater.php

+1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public function loadMapFromFreedesktopFile(string $source_file): array
148148
}
149149
if (isset($node->acronym)) {
150150
$acronym = (string) $node->acronym;
151+
/** @var ?string $expandedAcronym */
151152
$expandedAcronym = $node->{'expanded-acronym'} ?? null;
152153
if (isset($expandedAcronym)) {
153154
$acronym .= ': ' . $expandedAcronym;

src/Type.php

+6
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,22 @@ class Type implements TypeInterface
1111
{
1212
/**
1313
* Short format [e.g. image/jpeg] for strings.
14+
*
15+
* @phpstan-var int
1416
*/
1517
const SHORT_TEXT = 0;
1618

1719
/**
1820
* Full format [e.g. image/jpeg; p="1"] for strings.
21+
*
22+
* @phpstan-var int
1923
*/
2024
const FULL_TEXT = 1;
2125

2226
/**
2327
* Full format with comments [e.g. image/jpeg; p="1" (comment)] for strings.
28+
*
29+
* @phpstan-var int
2430
*/
2531
const FULL_TEXT_WITH_COMMENTS = 2;
2632

tests/src/TypeTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,6 @@ public function testParse(string $type, array $expectedToString, array $expected
455455
}
456456
foreach ($expectedParameters as $name => $param) {
457457
$this->assertTrue(isset($mt->getParameters()[$name]));
458-
$this->assertInstanceOf(TypeParameter::class, $mt->getParameter($name));
459458
$this->assertSame($name, $mt->getParameter($name)->getName());
460459
$this->assertSame($param[0], $mt->getParameter($name)->getValue());
461460
if (isset($param[1])) {

0 commit comments

Comments
 (0)