Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e95f537

Browse files
Merge branch '1.10.x' into 1.11.x
2 parents f8a15e4 + 828b269 commit e95f537

File tree

11 files changed

+100
-13
lines changed

11 files changed

+100
-13
lines changed

‎composer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"nikic/php-parser": "^4.16",
2525
"ondram/ci-detector": "^3.4.0",
2626
"ondrejmirtes/better-reflection": "6.11.0.1",
27-
"phpstan/php-8-stubs": "0.3.60",
27+
"phpstan/php-8-stubs": "0.3.61",
2828
"phpstan/phpdoc-parser": "1.22.0",
2929
"react/async": "^3",
3030
"react/child-process": "^0.6.4",

‎composer.lock‎

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎conf/config.neon‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ parameters:
165165
- ../stubs/arrayFunctions.stub
166166
- ../stubs/core.stub
167167
- ../stubs/typeCheckingFunctions.stub
168+
- ../stubs/json.stub
168169
earlyTerminatingMethodCalls: []
169170
earlyTerminatingFunctionCalls: []
170171
memoryLimitFile: %tmpDir%/.memory_limit

‎src/Rules/DeadCode/UnusedPrivateMethodRule.php‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function processNode(Node $node, Scope $scope): array
5656
if (strtolower($methodName) === '__clone') {
5757
continue;
5858
}
59-
$methods[$methodName] = $method;
59+
$methods[strtolower($methodName)] = $method;
6060
}
6161

6262
$arrayCalls = [];
@@ -105,7 +105,7 @@ public function processNode(Node $node, Scope $scope): array
105105
if ($inMethod->getName() === $methodName) {
106106
continue;
107107
}
108-
unset($methods[$methodName]);
108+
unset($methods[strtolower($methodName)]);
109109
}
110110
}
111111

@@ -144,19 +144,20 @@ public function processNode(Node $node, Scope $scope): array
144144
if ($inMethod->getName() === $typeAndMethod->getMethod()) {
145145
continue;
146146
}
147-
unset($methods[$typeAndMethod->getMethod()]);
147+
unset($methods[strtolower($typeAndMethod->getMethod())]);
148148
}
149149
}
150150
}
151151
}
152152

153153
$errors = [];
154-
foreach ($methods as $methodName => $method) {
154+
foreach ($methods as $method) {
155+
$originalMethodName = $method->getNode()->name->toString();
155156
$methodType = 'Method';
156157
if ($method->getNode()->isStatic()) {
157158
$methodType = 'Static method';
158159
}
159-
$errors[] = RuleErrorBuilder::message(sprintf('%s %s::%s() is unused.', $methodType, $classReflection->getDisplayName(), $methodName))
160+
$errors[] = RuleErrorBuilder::message(sprintf('%s %s::%s() is unused.', $methodType, $classReflection->getDisplayName(), $originalMethodName))
160161
->line($method->getNode()->getLine())
161162
->identifier('method.unused')
162163
->build();

‎stubs/json.stub‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
/**
4+
* @param positive-int $depth
5+
* @param int-mask<JSON_INVALID_UTF8_IGNORE> $flags
6+
* @phpstan-assert-if-true =non-empty-string $json
7+
*/
8+
function json_validate(string $json, int $depth = 512, int $flags = 0): bool
9+
{
10+
}

‎tests/PHPStan/Analyser/NodeScopeResolverTest.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,10 @@ public function dataFileAsserts(): iterable
946946
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7096.php');
947947
}
948948

949+
if (PHP_VERSION_ID >= 80300) {
950+
yield from $this->gatherAssertTypes(__DIR__ . '/data/json-validate.php');
951+
}
952+
949953
if (PHP_VERSION_ID >= 80100) {
950954
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7167.php');
951955
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-6864.php');
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace JsonValidate;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class Foo
8+
{
9+
10+
public function doFoo(string $s): void
11+
{
12+
if (json_validate($s)) {
13+
assertType('non-empty-string', $s);
14+
} else {
15+
assertType('string', $s);
16+
}
17+
}
18+
19+
}

‎tests/PHPStan/Rules/DeadCode/UnusedPrivateMethodRuleTest.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ public function testBug7389(): void
9090
]);
9191
}
9292

93+
public function testBug8346(): void
94+
{
95+
$this->analyse([__DIR__ . '/data/bug-8346.php'], []);
96+
}
97+
9398
public function testFalsePositiveWithTraitUse(): void
9499
{
95100
if (PHP_VERSION_ID < 80100) {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Bug8346;
4+
5+
class HelloWorld
6+
{
7+
public function speak(): string
8+
{
9+
return $this->sayhello('world');
10+
}
11+
12+
private function sayHello(string $name): string
13+
{
14+
return 'Hello ' . $name;
15+
}
16+
}

‎tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,4 +1388,22 @@ public function testFlockParams(): void
13881388
]);
13891389
}
13901390

1391+
public function testJsonValidate(): void
1392+
{
1393+
if (PHP_VERSION_ID < 80300) {
1394+
$this->markTestSkipped('Test requires PHP 8.3');
1395+
}
1396+
1397+
$this->analyse([__DIR__ . '/data/json_validate.php'], [
1398+
[
1399+
'Parameter #2 $depth of function json_validate expects int<1, max>, 0 given.',
1400+
6,
1401+
],
1402+
[
1403+
'Parameter #3 $flags of function json_validate expects 0|1048576, 2 given.',
1404+
7,
1405+
],
1406+
]);
1407+
}
1408+
13911409
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /