File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed
Internal/Analyzer/Statements/Expression/BinaryOp Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -466,7 +466,7 @@ private static function analyzeOperand(
466
466
467
467
if (!$ operand_type_match
468
468
&& (!$ comparison_result ->scalar_type_match_found
469
- || (!$ operand_type ->isInt () && $ config ->strict_binary_operands )
469
+ || (!$ operand_type ->isConcatSafe () && $ config ->strict_binary_operands )
470
470
)
471
471
) {
472
472
if ($ has_valid_operand ) {
Original file line number Diff line number Diff line change 18
18
use Psalm \StatementsSource ;
19
19
use Psalm \Storage \FileStorage ;
20
20
use Psalm \Type \Atomic \TArray ;
21
+ use Psalm \Type \Atomic \TArrayKey ;
21
22
use Psalm \Type \Atomic \TCallable ;
22
23
use Psalm \Type \Atomic \TClassString ;
23
24
use Psalm \Type \Atomic \TClassStringMap ;
@@ -766,7 +767,7 @@ public function hasTemplate(): bool
766
767
if ($ t instanceof TTemplateParam) {
767
768
return true ;
768
769
}
769
-
770
+
770
771
if ($ t instanceof TNamedObject) {
771
772
foreach ($ t ->extra_types as $ sub ) {
772
773
if ($ sub instanceof TTemplateParam) {
@@ -1117,6 +1118,23 @@ public function isSingleStringLiteral(): bool
1117
1118
return count ($ this ->types ) === 1 && count ($ this ->literal_string_types ) === 1 ;
1118
1119
}
1119
1120
1121
+
1122
+ /**
1123
+ * @psalm-mutation-free
1124
+ * @return bool true if this type is a safe operand for string concatenation (int|string|array-key)
1125
+ */
1126
+ public function isConcatSafe (): bool
1127
+ {
1128
+ foreach ($ this ->types as $ type ) {
1129
+ if (!($ type instanceof TInt)
1130
+ && !($ type instanceof TString)
1131
+ && !($ type instanceof TArrayKey)) {
1132
+ return false ;
1133
+ }
1134
+ }
1135
+ return true ;
1136
+ }
1137
+
1120
1138
/**
1121
1139
* @throws InvalidArgumentException if isSingleStringLiteral is false
1122
1140
* @psalm-mutation-free
You can’t perform that action at this time.
0 commit comments