55use Generator ;
66use PhpParser \Node \Expr ;
77use PhpParser \Node \Scalar \Float_ ;
8+ use PhpParser \Node \Scalar \Int_ ;
9+ use PhpParser \Node \Scalar \String_ ;
810use PhpParser \Node \Stmt ;
911use PHPStan \Analyser \ExpressionContext ;
1012use PHPStan \Analyser \Generator \ExprAnalysisResult ;
1113use PHPStan \Analyser \Generator \ExprHandler ;
1214use PHPStan \Analyser \Generator \GeneratorScope ;
1315use PHPStan \Analyser \SpecifiedTypes ;
1416use PHPStan \DependencyInjection \AutowiredService ;
17+ use PHPStan \ShouldNotHappenException ;
1518use PHPStan \Type \Constant \ConstantFloatType ;
19+ use PHPStan \Type \Constant \ConstantIntegerType ;
20+ use PHPStan \Type \Constant \ConstantStringType ;
1621
1722/**
1823 * @implements ExprHandler<Float_>
1924 */
2025#[AutowiredService]
21- final class ScalarFloatHandler implements ExprHandler
26+ final class ScalarHandler implements ExprHandler
2227{
2328
2429 public function supports (Expr $ expr ): bool
2530 {
26- return $ expr instanceof Float_;
31+ return $ expr instanceof Float_
32+ || $ expr instanceof Int_
33+ || $ expr instanceof String_;
2734 }
2835
2936 public function analyseExpr (
@@ -35,7 +42,17 @@ public function analyseExpr(
3542 ): Generator
3643 {
3744 yield from [];
38- $ type = new ConstantFloatType ($ expr ->value );
45+
46+ if ($ expr instanceof Float_) {
47+ $ type = new ConstantFloatType ($ expr ->value );
48+ } elseif ($ expr instanceof Int_) {
49+ $ type = new ConstantIntegerType ($ expr ->value );
50+ } elseif ($ expr instanceof String_) {
51+ $ type = new ConstantStringType ($ expr ->value );
52+ } else {
53+ throw new ShouldNotHappenException ();
54+ }
55+
3956 return new ExprAnalysisResult (
4057 $ type ,
4158 $ type ,
0 commit comments