Skip to content

Commit

Permalink
Add non regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored and ondrejmirtes committed Feb 14, 2023
1 parent 943e7af commit f3b9c18
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8752.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/trait-instance-of.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/list-shapes.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7607.php');
}

/**
Expand Down
59 changes: 59 additions & 0 deletions tests/PHPStan/Analyser/data/bug-7607.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php declare(strict_types = 1);

namespace Bug7607;

use function PHPStan\Testing\assertType;

class HelloWorld
{
/**
* Determine if the given value is "blank".
*
* @param mixed $value
* @return bool
*
* @phpstan-assert-if-false !(null|''|array{}) $value
*/
public function blank($value)
{
if (is_null($value)) {
return true;
}

if (is_string($value)) {
return trim($value) === '';
}

if (is_numeric($value) || is_bool($value)) {
return false;
}

if ($value instanceof Countable) {
return count($value) === 0;
}

return empty($value);
}

public function getValue(): string|null
{
return 'value';
}

public function getUrlForCurrentRequest(): string|null
{
return rand(0,1) === 1 ? 'string' : null;
}

public function isUrl(string|null $url): bool
{
if ($this->blank($url = $url ?? $this->getUrlForCurrentRequest())) {
return false;
}

assertType('non-empty-string', $url);
$parsed = parse_url($url);

return is_array($parsed);
}
}

0 comments on commit f3b9c18

Please sign in to comment.