Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assert view-string with view()->exists(). #1464

Merged
merged 1 commit into from Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);