Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Type/Php/ReplaceFunctionsDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ private function getPreliminarilyResolvedTypeFromFunctionCall(

if (count($functionCall->getArgs()) > $replaceArgumentPosition) {
$replaceArgumentType = $scope->getType($functionCall->getArgs()[$replaceArgumentPosition]->value);
if ($replaceArgumentType->isArray()->yes()) {
$replaceArgumentType = $replaceArgumentType->getIterableValueType();
}

$accessories = [];
if ($subjectArgumentType->isNonFalsyString()->yes() && $replaceArgumentType->isNonFalsyString()->yes()) {
Expand Down
10 changes: 10 additions & 0 deletions tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1246,4 +1246,14 @@ public function testBug4443(): void
]);
}

public function testBug12928(): void
{
$this->analyse([__DIR__ . '/data/bug-12928.php'], [
[
'Method Bug12928\FooBarBaz::render() should return non-empty-string but returns string.',
59,
],
]);
}

}
68 changes: 68 additions & 0 deletions tests/PHPStan/Rules/Methods/data/bug-12928.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace Bug12928;

class Foo {
/**
* @param non-empty-string $phptFile
* @param non-empty-string $code
*
* @return non-empty-string
*/
public function render(string $phptFile, string $code): string
{
return str_replace(
[
'__DIR__',
'__FILE__',
],
[
"'" . dirname($phptFile) . "'",
"'" . $phptFile . "'",
],
$code,
);
}
}

class FooBar {
/**
* @param non-empty-string $phptFile
* @param non-falsy-string $code
* @param array<non-falsy-string> $replace
*
* @return non-falsy-string
*/
public function render(string $code, array $replace): string
{
return str_replace(
[
'__DIR__',
'__FILE__',
],
$replace,
$code,
);
}
}


class FooBarBaz {
/**
* @param non-empty-string $phptFile
* @param non-empty-string $code
*
* @return non-empty-string
*/
public function render(string $code, array $replace): string
{
return str_replace(
[
'__DIR__',
'__FILE__',
],
$replace,
$code,
);
}
}
Loading