diff --git a/CHANGELOG.md b/CHANGELOG.md index 28ab918db..cbb2c7cb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +- feat: assert `view-string` when using `view()->exists()` by @mad-briller - feat: freed `joinSub` to allow models to join other models by @harmenjanssen in https://github.com/nunomaduro/larastan/pull/1352 - feat: updated return type of the Request::header method by @mad-briller - feat: Added stub for `optional()` helper and class by @mad-briller in https://github.com/nunomaduro/larastan/pull/1344 diff --git a/stubs/Contracts/View.stub b/stubs/Contracts/View.stub index c501422a1..781414d4d 100644 --- a/stubs/Contracts/View.stub +++ b/stubs/Contracts/View.stub @@ -3,7 +3,17 @@ namespace Illuminate\Contracts\View; interface Factory -{} +{ + /** + * Determine if a given view exists. + * + * @param string $view + * @return bool + * + * @phpstan-assert-if-true view-string $view + */ + public function exists($view); +} interface View {} diff --git a/tests/Type/GeneralTypeTest.php b/tests/Type/GeneralTypeTest.php index 7b22d5288..271e5d6d0 100644 --- a/tests/Type/GeneralTypeTest.php +++ b/tests/Type/GeneralTypeTest.php @@ -34,6 +34,7 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__.'/data/form-request.php'); yield from $this->gatherAssertTypes(__DIR__.'/data/database-transaction.php'); yield from $this->gatherAssertTypes(__DIR__.'/data/container-array-access.php'); + yield from $this->gatherAssertTypes(__DIR__.'/data/view-exists.php'); } /** diff --git a/tests/Type/data/view-exists.php b/tests/Type/data/view-exists.php new file mode 100644 index 000000000..1ef65cf4b --- /dev/null +++ b/tests/Type/data/view-exists.php @@ -0,0 +1,12 @@ +exists($view)) { + assertType('view-string', $view); +} + +assertType('string', $view);