Skip to content

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Feb 4, 2022

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

Comment on lines -38 to -51
$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();
Copy link
Contributor Author

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

{

protected function foo(string $message): void
protected function foo(string $message, string $x): void
Copy link
Contributor Author

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.

}

public function sayHello(): void
public function sayHello(int $i): void
Copy link
Contributor Author

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.

@staabm staabm marked this pull request as ready for review February 4, 2022 09:49
@ondrejmirtes ondrejmirtes merged commit 5348490 into phpstan:master Feb 6, 2022
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the constant-implode branch February 6, 2022 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants