Skip to content

Commit f3b9c18

Browse files
VincentLangletondrejmirtes
authored andcommitted
Add non regression test
1 parent 943e7af commit f3b9c18

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,7 @@ public function dataFileAsserts(): iterable
11811181
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8752.php');
11821182
yield from $this->gatherAssertTypes(__DIR__ . '/data/trait-instance-of.php');
11831183
yield from $this->gatherAssertTypes(__DIR__ . '/data/list-shapes.php');
1184+
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7607.php');
11841185
}
11851186

11861187
/**
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug7607;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class HelloWorld
8+
{
9+
/**
10+
* Determine if the given value is "blank".
11+
*
12+
* @param mixed $value
13+
* @return bool
14+
*
15+
* @phpstan-assert-if-false !(null|''|array{}) $value
16+
*/
17+
public function blank($value)
18+
{
19+
if (is_null($value)) {
20+
return true;
21+
}
22+
23+
if (is_string($value)) {
24+
return trim($value) === '';
25+
}
26+
27+
if (is_numeric($value) || is_bool($value)) {
28+
return false;
29+
}
30+
31+
if ($value instanceof Countable) {
32+
return count($value) === 0;
33+
}
34+
35+
return empty($value);
36+
}
37+
38+
public function getValue(): string|null
39+
{
40+
return 'value';
41+
}
42+
43+
public function getUrlForCurrentRequest(): string|null
44+
{
45+
return rand(0,1) === 1 ? 'string' : null;
46+
}
47+
48+
public function isUrl(string|null $url): bool
49+
{
50+
if ($this->blank($url = $url ?? $this->getUrlForCurrentRequest())) {
51+
return false;
52+
}
53+
54+
assertType('non-empty-string', $url);
55+
$parsed = parse_url($url);
56+
57+
return is_array($parsed);
58+
}
59+
}

0 commit comments

Comments
 (0)