Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8421.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/imagick-pixel.php');
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Arrays/data/bug-8467a.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8467b.php');
}

/**
Expand Down
56 changes: 56 additions & 0 deletions tests/PHPStan/Analyser/data/bug-8467b.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php declare(strict_types = 1);

namespace Bug8467b;

use function PHPStan\Testing\assertType;

class Test {
public function foo (?string $cwd, bool $initialClone = false): void {
if ($initialClone) {
$origCwd = $cwd;
$cwd = null;
}

if ($initialClone && isset($origCwd)) {
assertType('string', $origCwd);
assertType('null', $cwd);
Copy link
Contributor Author

@rajyan rajyan Dec 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this one is not covered in createConditionalExpressions yet and not working before 1.9.2 too.
I think it might be better to solve it in a different PR

}
}

/**
* @param mixed[]|null $mirrors
*
* @return list<non-empty-string>
*
* @phpstan-param list<array{url: non-empty-string, preferred: bool}>|null $mirrors
*/
protected function getUrls(?string $url, ?array $mirrors, ?string $ref, ?string $type, string $urlType): array
{
if (!$url) {
return [];
}

if ($urlType === 'dist' && false !== strpos($url, '%')) {
assertType('string|null', $type);
$url = 'test';
}
assertType('non-falsy-string', $url);

$urls = [$url];
if ($mirrors) {
foreach ($mirrors as $mirror) {
if ($urlType === 'dist') {
assertType('string|null', $type);
} elseif ($urlType === 'source' && $type === 'git') {
assertType("'git'", $type);
} elseif ($urlType === 'source' && $type === 'hg') {
assertType("'hg'", $type);
} else {
continue;
}
}
}

return $urls;
}
}