Skip to content
This repository was archived by the owner on Mar 1, 2023. It is now read-only.

Commit d485b97

Browse files
authored
Merge pull request #8 from PrisisForks/feature/fix-getArgs-call
fix get args call
2 parents c2889d4 + 97cb8b8 commit d485b97

File tree

11 files changed

+100
-184
lines changed

11 files changed

+100
-184
lines changed

.build/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"license": "proprietary",
55
"require": {
66
"php": "^7.3",
7-
"narrowspark/coding-standard": "^5.0.0",
8-
"nikic/php-parser": "~4.3.0",
7+
"narrowspark/coding-standard": "^5.1.0",
8+
"nikic/php-parser": "dev-master",
99
"wikimedia/composer-merge-plugin": "^1.4.1"
1010
},
1111
"extra": {

.build/phpstan-baseline.neon

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
parameters:
22
ignoreErrors:
33
-
4-
message: "#^Method Narrowspark\\\\ExceptionInspector\\\\Frame\\:\\:getRawFrame\\(\\) should return array\\('file' \\=\\> string, 'line' \\=\\> int, 'class' \\=\\> string, 'args' \\=\\> array\\('array\\-key' \\=\\> mixed\\), 'function' \\=\\> string\\) but returns array\\('file' \\=\\> string\\|null, 'line' \\=\\> int, 'class' \\=\\> string, 'args' \\=\\> array\\('array\\-key' \\=\\> mixed\\), 'function' \\=\\> string\\)\\.$#"
4+
message: "#^Variable \\$matches in PHPDoc tag @var does not exist\\.$#"
55
count: 1
66
path: ../src/Frame.php
77

88
-
9-
message: "#^Parameter \\#1 \\$frame of class Narrowspark\\\\ExceptionInspector\\\\Frame constructor expects array\\('file' \\=\\> string\\|null, 'line' \\=\\> int, 'class' \\=\\> string, 'args' \\=\\> array\\('array\\-key' \\=\\> mixed\\), 'function' \\=\\> string\\), array given\\.$#"
9+
message: "#^Parameter \\#1 \\$frame of class Narrowspark\\\\ExceptionInspector\\\\Frame constructor expects array\\('file' \\=\\> string, 'line' \\=\\> int, 'class' \\=\\> string, \\?'args' \\=\\> array\\('array\\-key' \\=\\> mixed\\), \\?'function' \\=\\> string\\), array given\\.$#"
1010
count: 1
1111
path: ../src/FrameCollection.php
1212

@@ -16,7 +16,7 @@ parameters:
1616
path: ../src/FrameCollection.php
1717

1818
-
19-
message: "#^Parameter \\#1 \\$frames of class Narrowspark\\\\ExceptionInspector\\\\FrameCollection constructor expects array\\<int, array\\<string, array\\<string, mixed\\>\\|int\\|string\\|null\\>\\>, array\\<int, array\\<string, array\\<string\\>\\|int\\|string\\>\\> given\\.$#"
19+
message: "#^Parameter \\#1 \\$frames of class Narrowspark\\\\ExceptionInspector\\\\FrameCollection constructor expects array\\<int, array\\<string, array\\<string, mixed\\>\\|int\\|string\\>\\>, array given\\.$#"
2020
count: 1
2121
path: ../src/Inspector.php
2222

@@ -26,7 +26,7 @@ parameters:
2626
path: ../src/Inspector.php
2727

2828
-
29-
message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'Narrowspark' and Narrowspark\\\\ExceptionInspector\\\\Frame will always evaluate to true\\.$#"
29+
message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'Narrowspark\\\\\\\\ExceptionInspector\\\\\\\\Frame' and Narrowspark\\\\ExceptionInspector\\\\Frame will always evaluate to true\\.$#"
3030
count: 1
3131
path: ../tests/Unit/FrameCollectionTest.php
3232

@@ -41,37 +41,47 @@ parameters:
4141
path: ../tests/Unit/FrameCollectionTest.php
4242

4343
-
44-
message: "#^Parameter \\#1 \\$frames of class Narrowspark\\\\ExceptionInspector\\\\FrameCollection constructor expects array\\<int, array\\<string, array\\<string, mixed\\>\\|int\\|string\\|null\\>\\>, array\\<int\\|string, mixed\\> given\\.$#"
45-
count: 2
44+
message: "#^Parameter \\#1 \\$frame of class Narrowspark\\\\ExceptionInspector\\\\Frame constructor expects array\\('file' \\=\\> string, 'line' \\=\\> int, 'class' \\=\\> string, \\?'args' \\=\\> array\\('array\\-key' \\=\\> mixed\\), \\?'function' \\=\\> string\\), array\\('file' \\=\\> 'foo', 'line' \\=\\> 1, 'function' \\=\\> 'test\\-1', 'class' \\=\\> 'MyClass', 'args' \\=\\> array\\(true, 'hello'\\)\\) given\\.$#"
45+
count: 1
46+
path: ../tests/Unit/FrameCollectionTest.php
47+
48+
-
49+
message: "#^Parameter \\#1 \\$frame of class Narrowspark\\\\ExceptionInspector\\\\Frame constructor expects array\\('file' \\=\\> string, 'line' \\=\\> int, 'class' \\=\\> string, \\?'args' \\=\\> array\\('array\\-key' \\=\\> mixed\\), \\?'function' \\=\\> string\\), array\\('file' \\=\\> string, 'line' \\=\\> 1, 'function' \\=\\> 'test\\-1', 'class' \\=\\> 'MyClass', 'args' \\=\\> array\\(true, 'hello'\\)\\) given\\.$#"
50+
count: 1
4651
path: ../tests/Unit/FrameCollectionTest.php
4752

4853
-
49-
message: "#^Parameter \\#1 \\$frame of class Narrowspark\\\\ExceptionInspector\\\\Frame constructor expects array\\('file' \\=\\> string\\|null, 'line' \\=\\> int, 'class' \\=\\> string, 'args' \\=\\> array\\('array\\-key' \\=\\> mixed\\), 'function' \\=\\> string\\), array\\('file' \\=\\> 'foo', 'line' \\=\\> 1, 'function' \\=\\> 'test\\-1', 'class' \\=\\> 'MyClass', 'args' \\=\\> array\\(true, 'hello'\\)\\) given\\.$#"
54+
message: "#^You should use assertCount\\(\\$expectedCount, \\$variable\\) instead of assertSame\\(\\$expectedCount, \\$variable\\-\\>count\\(\\)\\)\\.$#"
5055
count: 1
5156
path: ../tests/Unit/FrameCollectionTest.php
5257

5358
-
54-
message: "#^Parameter \\#1 \\$frame of class Narrowspark\\\\ExceptionInspector\\\\Frame constructor expects array\\('file' \\=\\> string\\|null, 'line' \\=\\> int, 'class' \\=\\> string, 'args' \\=\\> array\\('array\\-key' \\=\\> mixed\\), 'function' \\=\\> string\\), array\\('file' \\=\\> string, 'line' \\=\\> 1, 'function' \\=\\> 'test\\-1', 'class' \\=\\> 'MyClass', 'args' \\=\\> array\\(true, 'hello'\\)\\) given\\.$#"
59+
message: "#^Method Narrowspark\\\\ExceptionInspector\\\\Tests\\\\Unit\\\\FrameCollectionTest\\:\\:getFrameDataList\\(\\) should return array\\<int, array\\<string, array\\<string, mixed\\>\\|int\\|string\\>\\> but returns array\\<int, array\\>\\.$#"
5560
count: 1
5661
path: ../tests/Unit/FrameCollectionTest.php
5762

5863
-
59-
message: "#^Parameter \\#1 \\$frames of class Narrowspark\\\\ExceptionInspector\\\\FrameCollection constructor expects array\\<int, array\\<string, array\\<string, mixed\\>\\|int\\|string\\|null\\>\\>, array given\\.$#"
64+
message: "#^Method Narrowspark\\\\ExceptionInspector\\\\Tests\\\\Unit\\\\FrameCollectionTest\\:\\:getFrameData\\(\\) never returns array\\<string, array\\<string, mixed\\>\\|int\\|string\\> so it can be removed from the return typehint\\.$#"
65+
count: 2
66+
path: ../tests/Unit/FrameCollectionTest.php
67+
68+
-
69+
message: "#^Method Narrowspark\\\\ExceptionInspector\\\\Tests\\\\Unit\\\\FrameCollectionTest\\:\\:getFrameData\\(\\) should return array\\('args' \\=\\> array\\('array\\-key' \\=\\> mixed\\), 'class' \\=\\> string, 'file' \\=\\> string, 'line' \\=\\> int, \\?'function' \\=\\> string\\) but returns array\\('file' \\=\\> string, 'line' \\=\\> int, 'function' \\=\\> string, 'class' \\=\\> 'MyClass', 'args' \\=\\> array\\(true, 'hello'\\)\\)\\.$#"
6070
count: 1
6171
path: ../tests/Unit/FrameCollectionTest.php
6272

6373
-
64-
message: "#^Cannot cast array\\|int\\|string to string\\.$#"
74+
message: "#^Parameter \\#1 \\$frames of class Narrowspark\\\\ExceptionInspector\\\\FrameCollection constructor expects array\\<int, array\\<string, array\\<string, mixed\\>\\|int\\|string\\>\\>, array\\<int, array\\> given\\.$#"
6575
count: 1
66-
path: ../tests/Unit/FrameTest.php
76+
path: ../tests/Unit/FrameCollectionTest.php
6777

6878
-
69-
message: "#^Parameter \\#1 \\$frame of class Narrowspark\\\\ExceptionInspector\\\\Frame constructor expects array\\('file' \\=\\> string\\|null, 'line' \\=\\> int, 'class' \\=\\> string, 'args' \\=\\> array\\('array\\-key' \\=\\> mixed\\), 'function' \\=\\> string\\), array\\<string, array\\|int\\|string\\> given\\.$#"
79+
message: "#^Parameter \\#1 \\$frame of class Narrowspark\\\\ExceptionInspector\\\\Frame constructor expects array\\('file' \\=\\> string, 'line' \\=\\> int, 'class' \\=\\> string, \\?'args' \\=\\> array\\('array\\-key' \\=\\> mixed\\), \\?'function' \\=\\> string\\), array\\<string, array\\|int\\|string\\> given\\.$#"
7080
count: 1
7181
path: ../tests/Unit/FrameTest.php
7282

7383
-
74-
message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'Narrowspark' and iterable\\<Narrowspark\\\\ExceptionInspector\\\\Frame\\>&Narrowspark\\\\ExceptionInspector\\\\FrameCollection will always evaluate to true\\.$#"
84+
message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'Narrowspark\\\\\\\\ExceptionInspector\\\\\\\\FrameCollection' and iterable\\<Narrowspark\\\\ExceptionInspector\\\\Frame\\>&Narrowspark\\\\ExceptionInspector\\\\FrameCollection will always evaluate to true\\.$#"
7585
count: 1
7686
path: ../tests/Unit/InspectorTest.php
7787

.build/psalm-baseline.xml

Lines changed: 14 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,34 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="3.10.1@eeed5ecccc10131397f0eb7ee6da810c0be3a7fc">
3-
<file src="src/Frame.php">
4-
<LessSpecificReturnStatement occurrences="1">
5-
<code>$this-&gt;frame</code>
6-
</LessSpecificReturnStatement>
7-
<MixedAssignment occurrences="1">
8-
<code>$file</code>
9-
</MixedAssignment>
10-
<MixedInferredReturnType occurrences="1">
11-
<code>?string</code>
12-
</MixedInferredReturnType>
13-
<MixedReturnStatement occurrences="1">
14-
<code>$file</code>
15-
</MixedReturnStatement>
16-
<MoreSpecificReturnType occurrences="1">
17-
<code>array{file: string, line: int, class: string, args: array{array-key: mixed}, function: string}</code>
18-
</MoreSpecificReturnType>
19-
<PossiblyNullArrayAccess occurrences="2">
20-
<code>$matches[1]</code>
21-
<code>$matches[2]</code>
22-
</PossiblyNullArrayAccess>
23-
<PropertyTypeCoercion occurrences="2">
24-
<code>$this-&gt;frame</code>
25-
<code>$this-&gt;frame</code>
26-
</PropertyTypeCoercion>
27-
</file>
28-
<file src="src/FrameCollection.php">
29-
<ArgumentTypeCoercion occurrences="1">
30-
<code>$frame</code>
31-
</ArgumentTypeCoercion>
32-
<InvalidOperand occurrences="1">
33-
<code>$offset</code>
34-
</InvalidOperand>
35-
<InvalidPropertyAssignmentValue occurrences="1"/>
36-
<MixedArgumentTypeCoercion occurrences="1">
37-
<code>$callable</code>
38-
</MixedArgumentTypeCoercion>
39-
<MixedAssignment occurrences="1">
40-
<code>$frame</code>
41-
</MixedAssignment>
42-
<MixedReturnTypeCoercion occurrences="2">
43-
<code>new ArrayIterator($this-&gt;getArray())</code>
44-
<code>\ArrayIterator&lt;int, \Narrowspark\ExceptionInspector\Frame&gt;</code>
45-
</MixedReturnTypeCoercion>
46-
<TooManyTemplateParams occurrences="1">
47-
<code>\Narrowspark\ExceptionInspector\FrameCollection&lt;\Narrowspark\ExceptionInspector\Frame&gt;</code>
48-
</TooManyTemplateParams>
2+
<files psalm-version="3.11.2@d470903722cfcbc1cd04744c5491d3e6d13ec3d9">
3+
<file src="src/Contract/Exception/UnexpectedValueException.php">
4+
<UnusedClass occurrences="1">
5+
<code>UnexpectedValueException</code>
6+
</UnusedClass>
497
</file>
508
<file src="src/Inspector.php">
51-
<ArgumentTypeCoercion occurrences="2">
52-
<code>$nextFrame</code>
9+
<InvalidArgument occurrences="1">
5310
<code>$frames</code>
54-
</ArgumentTypeCoercion>
55-
<DocblockTypeContradiction occurrences="1">
56-
<code>$this-&gt;previousExceptions === null</code>
57-
</DocblockTypeContradiction>
58-
<InvalidReturnStatement occurrences="1"/>
59-
<InvalidReturnType occurrences="1">
60-
<code>int[]</code>
61-
</InvalidReturnType>
62-
<LessSpecificReturnStatement occurrences="1">
63-
<code>$docref</code>
64-
</LessSpecificReturnStatement>
65-
<MixedAssignment occurrences="5">
66-
<code>$file</code>
67-
<code>$line</code>
68-
<code>$frames[$k]['file']</code>
69-
<code>$frames[$k]['line']</code>
70-
<code>$docref['url']</code>
71-
</MixedAssignment>
72-
<MixedPropertyTypeCoercion occurrences="1">
73-
<code>new FrameCollection($frames)</code>
74-
</MixedPropertyTypeCoercion>
75-
<MixedReturnTypeCoercion occurrences="4">
76-
<code>$this-&gt;frames</code>
77-
<code>\Narrowspark\ExceptionInspector\FrameCollection&lt;\Narrowspark\ExceptionInspector\Frame&gt;</code>
78-
<code>array_diff_key($stack, $trace)</code>
79-
<code>list&lt;array&lt;string, mixed&gt;&gt;</code>
80-
</MixedReturnTypeCoercion>
81-
<MoreSpecificReturnType occurrences="1">
82-
<code>array{message: string, url: null|string}</code>
83-
</MoreSpecificReturnType>
84-
<PossiblyNullArrayAccess occurrences="1">
85-
<code>$matches[1]</code>
86-
</PossiblyNullArrayAccess>
87-
<TooManyTemplateParams occurrences="2">
88-
<code>null|\Narrowspark\ExceptionInspector\FrameCollection&lt;\Narrowspark\ExceptionInspector\Frame&gt;</code>
89-
<code>\Narrowspark\ExceptionInspector\FrameCollection&lt;\Narrowspark\ExceptionInspector\Frame&gt;</code>
90-
</TooManyTemplateParams>
11+
</InvalidArgument>
9112
</file>
9213
<file src="tests/Unit/FrameCollectionTest.php">
93-
<ArgumentTypeCoercion occurrences="3">
94-
<code>$frames</code>
95-
</ArgumentTypeCoercion>
96-
<InvalidArgument occurrences="3">
14+
<InvalidArgument occurrences="4">
9715
<code>'foo'</code>
9816
</InvalidArgument>
17+
<InvalidReturnStatement occurrences="1"/>
18+
<InvalidReturnType occurrences="1">
19+
<code>array{args: array{array-key: mixed}, class: string, file: string, function?: string, line: int}</code>
20+
</InvalidReturnType>
9921
<MixedArgumentTypeCoercion occurrences="1">
100-
<code>$frameCollection2</code>
22+
<code>$frames</code>
10123
</MixedArgumentTypeCoercion>
102-
<MixedReturnTypeCoercion occurrences="2">
103-
<code>new FrameCollection($frames)</code>
104-
<code>\Narrowspark\ExceptionInspector\FrameCollection&lt;int, \Narrowspark\ExceptionInspector\Frame&gt;</code>
105-
</MixedReturnTypeCoercion>
106-
<RedundantCondition occurrences="2">
107-
<code>assertInstanceOf</code>
24+
<RedundantCondition occurrences="1">
10825
<code>assertNotSame</code>
10926
</RedundantCondition>
11027
<TooManyArguments occurrences="1"/>
111-
<TooManyTemplateParams occurrences="1">
112-
<code>\Narrowspark\ExceptionInspector\FrameCollection&lt;int, \Narrowspark\ExceptionInspector\Frame&gt;</code>
113-
</TooManyTemplateParams>
11428
</file>
11529
<file src="tests/Unit/FrameTest.php">
11630
<ArgumentTypeCoercion occurrences="1">
11731
<code>$data</code>
11832
</ArgumentTypeCoercion>
119-
<InvalidDocblock occurrences="1">
120-
<code>public static function provideGetFileContentsWhenFrameIsNotRelatedToSpecificFileCases(): iterable</code>
121-
</InvalidDocblock>
122-
<MixedInferredReturnType occurrences="1">
123-
<code>iterable&lt;array-key, array&lt;array-key, string&gt;</code>
124-
</MixedInferredReturnType>
125-
<PossiblyInvalidCast occurrences="1">
126-
<code>$data['file']</code>
127-
</PossiblyInvalidCast>
12833
</file>
12934
</files>

.build/rector-tests.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
parameters:
22
php_version_features: '7.3'
33

4+
exclude_paths:
5+
- '*/tests/Unit/Fixture/*'
6+
47
sets:
58
- 'celebrity'
69
- 'phpstan'

.github/workflows/mutation.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ jobs:
2424

2525
env:
2626
key: "mutation-v1" # change key (version) to clear cache
27-
min-covered-msi: 75
28-
min-msi: 63
27+
min-covered-msi: 73
28+
min-msi: 61
2929
extensions: "mbstring"
3030
ini-values: "date.timezone=Europe/Berlin, opcache.enable_cli=1, pcov.directory=api"
3131
tools: "composer, composer-prefetcher, cs2pr"

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
},
2424
"require-dev": {
2525
"ext-json": "*",
26-
"phpunit/phpunit": "^9.1.1"
26+
"phpunit/phpunit": "^9.1.2"
2727
},
2828
"config": {
2929
"preferred-install": "dist",
@@ -35,7 +35,7 @@
3535
},
3636
"prefetcher": {
3737
"require": {
38-
"phpunit/phpunit": "^8.0 || ^9.0"
38+
"phpunit/phpunit": "^9.0"
3939
}
4040
}
4141
},
@@ -64,7 +64,7 @@
6464
],
6565
"cs": "composer --working-dir=./.build cs -- -v",
6666
"cs:check": "composer --working-dir=./.build cs:check -- -v",
67-
"infection": "composer --working-dir=./.build infection -- --min-covered-msi=75 --min-msi=63",
67+
"infection": "composer --working-dir=./.build infection -- --min-covered-msi=73 --min-msi=61",
6868
"phpstan": "composer --working-dir=./.build phpstan -- --memory-limit=-1",
6969
"phpstan:baseline": "composer --working-dir=./.build phpstan:baseline -- --memory-limit=-1",
7070
"psalm": "composer --working-dir=./.build psalm",

src/Frame.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
final class Frame
2323
{
2424
/**
25-
* @psalm-var array{file: ?string, line: int, class: string, args: array{array-key: mixed}, function: string}
25+
* @psalm-var array{file: string, line: int, class: string, args?: array{array-key: mixed}, function?: string}
2626
*
2727
* @var array<string, null|array<int, mixed>|int|string>
2828
*/
@@ -42,7 +42,7 @@ final class Frame
4242
private $application = false;
4343

4444
/**
45-
* @psalm-param array{file: ?string, line: int, class: string, args: array{array-key: mixed}, function: string} $frame
45+
* @psalm-param array{file: string, line: int, class: string, args?: array{array-key: mixed}, function?: string} $frame
4646
*
4747
* @param int[]|mixed[][]|string[] $frame
4848
*/
@@ -111,7 +111,7 @@ public function addComment(string $comment, string $context = 'global'): void
111111

112112
public function getFile(): ?string
113113
{
114-
if (! isset($this->frame['file']) || $this->frame['file'] === '') {
114+
if ($this->frame['file'] === '') {
115115
return null;
116116
}
117117

@@ -121,8 +121,9 @@ public function getFile(): ?string
121121
// @todo: This can be made more reliable by checking if we've entered
122122
// eval() in a previous trace, but will need some more work on the upper
123123
// trace collector(s).
124-
if (\Safe\preg_match('/^(.*)\((\d+)\) : (?:eval\(\)\'d|assert) code$/', $file, $matches) !== 0) {
125-
$file = $this->frame['file'] = $matches[1];
124+
/** @psalm-var array{0: string, 1: string} $matches @var array<int, string> $matches */
125+
if (\Safe\preg_match('/^(.*)\((\d+)\) : (?:eval\(\)\'d|assert) code$/', $file, $matches) !== 0 && \is_array($matches)) {
126+
$file = $this->frame['file'] = (string) $matches[1];
126127
$this->frame['line'] = (int) $matches[2];
127128
}
128129

@@ -145,7 +146,7 @@ public function getClass(): ?string
145146

146147
public function getFunction(): ?string
147148
{
148-
if ($this->frame['function'] === '') {
149+
if (! isset($this->frame['function']) || $this->frame['function'] === '') {
149150
return null;
150151
}
151152

@@ -157,7 +158,7 @@ public function getFunction(): ?string
157158
*/
158159
public function getArgs(): array
159160
{
160-
return $this->frame['args'];
161+
return $this->frame['args'] ?? [];
161162
}
162163

163164
/**
@@ -189,9 +190,11 @@ public function getFileContents(): ?string
189190
* Returns the array containing the raw frame data from which
190191
* this Frame object was built.
191192
*
192-
* @psalm-return array{file: string, line: int, class: string, args: array{array-key: mixed}, function: string}
193+
* @noRector \Rector\TypeDeclaration\Rector\ClassMethod\AddArrayReturnDocTypeRector
193194
*
194-
* @return int[][]|mixed[][]|string[][]
195+
* @psalm-return array{file: string, line: int, class: string, args?: array{array-key: mixed}, function?: string}
196+
*
197+
* @return int[]|int[]|mixed[][]|string[]|string[]
195198
*/
196199
public function getRawFrame(): array
197200
{

0 commit comments

Comments
 (0)