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
implemented constant-type inference in ImplodeFunctionReturnTypeExtension #991
Conversation
$accessoryTypes = []; | ||
if ($argType->isIterableAtLeastOnce()->yes() && $argType->getIterableValueType()->isNonEmptyString()->yes()) { | ||
$accessoryTypes[] = new AccessoryNonEmptyStringType(); | ||
} | ||
if ($argType->getIterableValueType()->isLiteralString()->yes()) { | ||
$accessoryTypes[] = new AccessoryLiteralStringType(); | ||
} | ||
|
||
if (count($accessoryTypes) > 0) { | ||
$accessoryTypes[] = new StringType(); | ||
return new IntersectionType($accessoryTypes); | ||
} | ||
|
||
return new StringType(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this code was duplicated in the extension. de-duplicated the existing logic with the first commit with 180b2af
@@ -7,9 +7,9 @@ | |||
class HelloWorld | |||
{ | |||
|
|||
protected function foo(string $message): void | |||
protected function foo(string $message, string $x): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adjusted the existing test, so it still leads to the same result as before this PR.
@@ -206,10 +206,10 @@ public function doFoo4(string $s, array $nonEmptyArrayWithNonEmptyStrings): void | |||
assertType('non-empty-string', implode($nonEmptyArrayWithNonEmptyStrings)); | |||
} | |||
|
|||
public function sayHello(): void | |||
public function sayHello(int $i): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adjusted the existing test, so it still leads to the same result as before this PR.
Thank you! |
to allow phpstan-dba to check syntax errors in queries which use
implode
like$query = 'SELECT * FROM abc WHERE id IN ('. implode(',', [A::ONE, B::TWO, 3]) .')';
I am aware that such queries are not optimal use and should better be expressed with a prepared statement and separated values, but I think there is a lot of code out their constructed like this .. would be great phpstan-dba could cover such existing but non-optimal query-code