Skip to content

Commit

Permalink
Test @var in and out of function
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed May 19, 2023
1 parent 4fc202a commit 4e19347
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Arrays/data/bug-7469.php');
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Variables/data/bug-3391.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-6901.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/var-in-and-out-of-function.php');

if (PHP_VERSION_ID >= 70400) {
yield from $this->gatherAssertTypes(__DIR__ . '/data/arrow-function-argument-type.php');
Expand Down
25 changes: 25 additions & 0 deletions tests/PHPStan/Analyser/data/var-in-and-out-of-function.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace VarInAndOutOfFunction;

use PHPStan\TrinaryLogic;
use function PHPStan\Testing\assertVariableCertainty;

assertVariableCertainty(TrinaryLogic::createMaybe(), $foo);

/** @var int $foo */

assertVariableCertainty(TrinaryLogic::createYes(), $foo);

function doFoo(): void
{
if (rand(0, 1)) {
$foo = 1;
}

assertVariableCertainty(TrinaryLogic::createMaybe(), $foo);

/** @var int $foo */

assertVariableCertainty(TrinaryLogic::createMaybe(), $foo);
}

0 comments on commit 4e19347

Please sign in to comment.