Skip to content

Commit ee565db

Browse files
committed
1 parent 5d4eefc commit ee565db

File tree

11 files changed

+209
-3
lines changed

11 files changed

+209
-3
lines changed

changelog-2.0.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ Improvements 🔧
133133
* Returning plain strings as errors no longer supported, use RuleErrorBuilder
134134
* Learn more: [Using RuleErrorBuilder to enrich reported errors in custom rules](https://phpstan.org/blog/using-rule-error-builder)
135135
* Require identifier in custom rules (https://github.com/phpstan/phpstan-src/commit/969e6fa31d5484d42dab902703cfc6820a983cfd)
136-
* New `RuleLevelHelper::accepts()` behaviour (https://github.com/phpstan/phpstan-src/commit/941fc815db49315b8783dc466cf593e0d8a85d23)
136+
* New `RuleLevelHelper::accepts()` behaviour (https://github.com/phpstan/phpstan-src/commit/941fc815db49315b8783dc466cf593e0d8a85d23), #11119, #4174
137137
* Infer explicit mixed when instantiating generic class with unknown template types (https://github.com/phpstan/phpstan-src/commit/089d4c6fb6eb709c44123548d33990113d174b86), #6398
138-
* Use explicit mixed for global array variables ([#1411](https://github.com/phpstan/phpstan-src/pull/1411)), thanks @herndlm!
139-
* Consider implicit throw points when the only explicit one is `Throw_` (https://github.com/phpstan/phpstan-src/commit/22eef6d5ab9a4afafb2305258fea273be6cc06e4)
138+
* Use explicit mixed for global array variables ([#1411](https://github.com/phpstan/phpstan-src/pull/1411)), #7082, thanks @herndlm!
139+
* Consider implicit throw points when the only explicit one is `Throw_` (https://github.com/phpstan/phpstan-src/commit/22eef6d5ab9a4afafb2305258fea273be6cc06e4), #4912
140140
* Run missing type check on `@param-out` (https://github.com/phpstan/phpstan-src/commit/56b20024386d983927c64dfa895ff026bed2798c)
141141
* Report "missing return" error closer to where the return is missing (https://github.com/phpstan/phpstan-src/commit/04f8636e6577cbcaefc944725eed74c0d7865ead)
142142

tests/PHPStan/Rules/Comparison/IfConstantConditionRuleTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,10 @@ public function testBug10561(): void
169169
$this->analyse([__DIR__ . '/data/bug-10561.php'], []);
170170
}
171171

172+
public function testBug4912(): void
173+
{
174+
$this->treatPhpDocTypesAsCertain = true;
175+
$this->analyse([__DIR__ . '/data/bug-4912.php'], []);
176+
}
177+
172178
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Bug4912;
4+
5+
function funcB(): void
6+
{
7+
throw new \RuntimeException();
8+
}
9+
10+
function funcA(): void
11+
{
12+
$a = null;
13+
14+
try {
15+
$a = rand(0, 1);
16+
17+
if (!$a) {
18+
throw new \RuntimeException();
19+
}
20+
21+
funcB();
22+
} catch (\RuntimeException $e) {
23+
if ($a) {
24+
echo $a;
25+
}
26+
}
27+
}

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,4 +1782,15 @@ public function testBug9224(): void
17821782
$this->analyse([__DIR__ . '/data/bug-9224.php'], []);
17831783
}
17841784

1785+
public function testBug7082(): void
1786+
{
1787+
$this->checkExplicitMixed = true;
1788+
$this->analyse([__DIR__ . '/data/bug-7082.php'], [
1789+
[
1790+
'Parameter #1 $val of function Bug7082\takesStr expects string, mixed given.',
1791+
11,
1792+
],
1793+
]);
1794+
}
1795+
17851796
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Bug7082;
4+
5+
function takesStr(string $val): string {
6+
return $val . 'foo';
7+
}
8+
9+
function (): void {
10+
$nullable = $_GET['x'] ?? null;
11+
echo takesStr($nullable);
12+
};

tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3375,4 +3375,18 @@ public function testBug10159(): void
33753375
$this->analyse([__DIR__ . '/data/bug-10159.php'], []);
33763376
}
33773377

3378+
public function testBug1953(): void
3379+
{
3380+
$this->checkThisOnly = false;
3381+
$this->checkNullables = true;
3382+
$this->checkUnionTypes = true;
3383+
$this->checkExplicitMixed = true;
3384+
$this->analyse([__DIR__ . '/data/bug-1953.php'], [
3385+
[
3386+
'Cannot call method bar() on string.',
3387+
12,
3388+
],
3389+
]);
3390+
}
3391+
33783392
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Bug1953;
4+
5+
function foo(string &$i) : void {
6+
$i = "goodbye";
7+
}
8+
9+
function (): void {
10+
$a = "hello";
11+
foo($a);
12+
echo $a->bar();
13+
};

tests/PHPStan/Rules/Operators/InvalidComparisonOperationRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,9 @@ public function testRuleWithNullsafeVariant(): void
168168
]);
169169
}
170170

171+
public function testBug11119(): void
172+
{
173+
$this->analyse([__DIR__ . '/data/bug-11119.php'], []);
174+
}
175+
171176
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Bug11119;
4+
5+
use DateTime;
6+
7+
function (): void {
8+
$earliest = array_reduce(
9+
[
10+
new DateTime('+1 day'),
11+
new DateTime('+2 day'),
12+
new DateTime('+3 day'),
13+
],
14+
static fn (?DateTime $carry, DateTime $time): DateTime => ($carry instanceof DateTime && $carry < $time) ? $carry : $time,
15+
null
16+
);
17+
};

tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,4 +670,10 @@ public function testBug11617(): void
670670
]);
671671
}
672672

673+
public function testBug4174(): void
674+
{
675+
$this->checkExplicitMixed = true;
676+
$this->analyse([__DIR__ . '/data/bug-4174.php'], []);
677+
}
678+
673679
}

0 commit comments

Comments
 (0)