1313use PHPStan \Rules \Rule ;
1414use PHPStan \Rules \RuleError ;
1515use PHPStan \Rules \RuleErrorBuilder ;
16+ use PHPStan \Type \MixedType ;
1617use PHPStan \Type \ObjectType ;
1718use staabm \PHPStanDba \QueryReflection \PlaceholderValidation ;
1819use staabm \PHPStanDba \QueryReflection \QueryReflection ;
@@ -95,9 +96,13 @@ private function checkErrors(CallLike $callLike, Scope $scope): array
9596 }
9697
9798 $ queryExpr = $ args [0 ]->value ;
98- $ parameterTypes = $ scope ->getType ($ args [1 ]->value );
99+
100+ if ($ scope ->getType ($ queryExpr ) instanceof MixedType) {
101+ return [];
102+ }
99103
100104 $ queryReflection = new QueryReflection ();
105+ $ parameterTypes = $ scope ->getType ($ args [1 ]->value );
101106 try {
102107 $ parameters = $ queryReflection ->resolveParameters ($ parameterTypes ) ?? [];
103108 } catch (UnresolvableQueryException $ exception ) {
@@ -108,25 +113,31 @@ private function checkErrors(CallLike $callLike, Scope $scope): array
108113
109114 $ errors = [];
110115 $ placeholderReflection = new PlaceholderValidation ();
111- foreach ($ queryReflection ->resolvePreparedQueryStrings ($ queryExpr , $ parameterTypes , $ scope ) as $ queryString ) {
112- $ queryError = $ queryReflection ->validateQueryString ($ queryString );
113- if (null !== $ queryError ) {
114- $ error = $ queryError ->asRuleMessage ();
115- $ errors [$ error ] = $ error ;
116+ try {
117+ foreach ($ queryReflection ->resolvePreparedQueryStrings ($ queryExpr , $ parameterTypes , $ scope ) as $ queryString ) {
118+ $ queryError = $ queryReflection ->validateQueryString ($ queryString );
119+ if (null !== $ queryError ) {
120+ $ error = $ queryError ->asRuleMessage ();
121+ $ errors [$ error ] = $ error ;
122+ }
116123 }
117- }
118124
119- foreach ($ queryReflection ->resolveQueryStrings ($ queryExpr , $ scope ) as $ queryString ) {
120- foreach ($ placeholderReflection ->checkErrors ($ queryString , $ parameters ) as $ error ) {
121- $ errors [$ error ] = $ error ;
125+ foreach ($ queryReflection ->resolveQueryStrings ($ queryExpr , $ scope ) as $ queryString ) {
126+ foreach ($ placeholderReflection ->checkErrors ($ queryString , $ parameters ) as $ error ) {
127+ $ errors [$ error ] = $ error ;
128+ }
122129 }
123- }
124130
125- $ ruleErrors = [];
126- foreach ($ errors as $ error ) {
127- $ ruleErrors [] = RuleErrorBuilder::message ($ error )->line ($ callLike ->getLine ())->build ();
128- }
131+ $ ruleErrors = [];
132+ foreach ($ errors as $ error ) {
133+ $ ruleErrors [] = RuleErrorBuilder::message ($ error )->line ($ callLike ->getLine ())->build ();
134+ }
129135
130- return $ ruleErrors ;
136+ return $ ruleErrors ;
137+ } catch (UnresolvableQueryException $ exception ) {
138+ return [
139+ RuleErrorBuilder::message ($ exception ->asRuleMessage ())->tip (UnresolvableQueryException::RULE_TIP )->line ($ callLike ->getLine ())->build (),
140+ ];
141+ }
131142 }
132143}
0 commit comments