Skip to content

Commit

Permalink
Assert view-string with view()->exists().
Browse files Browse the repository at this point in the history
  • Loading branch information
mad-briller committed Nov 30, 2022
1 parent 0c9c70f commit 3628989
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion stubs/Contracts/View.stub
Expand Up @@ -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
{}
1 change: 1 addition & 0 deletions tests/Type/GeneralTypeTest.php
Expand Up @@ -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');
}

/**
Expand Down
12 changes: 12 additions & 0 deletions tests/Type/data/view-exists.php
@@ -0,0 +1,12 @@
<?php

namespace IlluminateView;

use function PHPStan\Testing\assertType;

/** @var string $view */
if (view()->exists($view)) {
assertType('view-string', $view);
}

assertType('string', $view);

0 comments on commit 3628989

Please sign in to comment.