-
Notifications
You must be signed in to change notification settings - Fork 433
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
943e7af
commit f3b9c18
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |