File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ parameters:
2929 - stubs/Utils/Html.stub
3030 - stubs/Utils/Paginator.stub
3131 - stubs/Utils/Random.stub
32+ - stubs/Utils/Strings.stub
3233 universalObjectCratesClasses :
3334 - Nette\Application\UI\ITemplate
3435 - Nette\Application\UI\Template
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Nette\Utils;
4+
5+ use Nette;
6+
7+
8+ /**
9+ * String tools library.
10+ */
11+ class Strings
12+ {
13+ use Nette\StaticClass;
14+
15+ /** @phpstan-assert-if-true non-empty-string $s */
16+ public static function length(string $s): int
17+ {}
18+
19+ }
Original file line number Diff line number Diff line change 88use function class_exists ;
99use function version_compare ;
1010
11- class MultiplierTest extends TypeInferenceTestCase
11+ class TypeInferenceTest extends TypeInferenceTestCase
1212{
1313
1414 public function dataFileAsserts (): iterable
@@ -26,6 +26,9 @@ public function dataFileAsserts(): iterable
2626 } else {
2727 yield from self ::gatherAssertTypes (__DIR__ . '/data/multiplier.php ' );
2828 }
29+
30+ yield from $ this ->gatherAssertTypes (__DIR__ . '/data/multiplier.php ' );
31+ yield from $ this ->gatherAssertTypes (__DIR__ . '/data/strings.php ' );
2932 }
3033
3134 /**
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace StringsTypesNarrowing ;
4+
5+ use Nette \Utils \Strings ;
6+ use function PHPStan \Testing \assertType ;
7+
8+ function doFoo (string $ string ) {
9+ assertType ('string ' , $ string );
10+ if (Strings::length ($ string )) {
11+ assertType ('non-empty-string ' , $ string );
12+ } else {
13+ assertType ('string ' , $ string );
14+ }
15+ assertType ('string ' , $ string );
16+
17+ if (Strings::length ($ string ) === 0 ) {
18+ assertType ('string ' , $ string );
19+ }
20+ assertType ('string ' , $ string );
21+ }
You can’t perform that action at this time.
0 commit comments