@@ -15,9 +15,13 @@ class TypeParser
1515 /** @var ConstExprParser|null */
1616 private $ constExprParser ;
1717
18- public function __construct (?ConstExprParser $ constExprParser = null )
18+ /** @var bool */
19+ private $ quoteAwareConstExprString ;
20+
21+ public function __construct (?ConstExprParser $ constExprParser = null , bool $ quoteAwareConstExprString = false )
1922 {
2023 $ this ->constExprParser = $ constExprParser ;
24+ $ this ->quoteAwareConstExprString = $ quoteAwareConstExprString ;
2125 }
2226
2327 /** @phpstan-impure */
@@ -562,7 +566,7 @@ private function parseArrayShapeItem(TokenIterator $tokens): Ast\Type\ArrayShape
562566
563567 /**
564568 * @phpstan-impure
565- * @return Ast\ConstExpr\ConstExprIntegerNode|Ast\ConstExpr\ConstExprStringNode|Ast\Type\IdentifierTypeNode
569+ * @return Ast\ConstExpr\ConstExprIntegerNode|Ast\ConstExpr\QuoteAwareConstExprStringNode|Ast\ConstExpr\ ConstExprStringNode|Ast\Type\IdentifierTypeNode
566570 */
567571 private function parseArrayShapeKey (TokenIterator $ tokens )
568572 {
@@ -571,11 +575,20 @@ private function parseArrayShapeKey(TokenIterator $tokens)
571575 $ tokens ->next ();
572576
573577 } elseif ($ tokens ->isCurrentTokenType (Lexer::TOKEN_SINGLE_QUOTED_STRING )) {
574- $ key = new Ast \ConstExpr \ConstExprStringNode (trim ($ tokens ->currentTokenValue (), "' " ));
578+ if ($ this ->quoteAwareConstExprString ) {
579+ $ key = new Ast \ConstExpr \QuoteAwareConstExprStringNode (trim ($ tokens ->currentTokenValue (), "' " ), Ast \ConstExpr \QuoteAwareConstExprStringNode::SINGLE_QUOTED );
580+ } else {
581+ $ key = new Ast \ConstExpr \ConstExprStringNode (trim ($ tokens ->currentTokenValue (), "' " ));
582+ }
575583 $ tokens ->next ();
576584
577585 } elseif ($ tokens ->isCurrentTokenType (Lexer::TOKEN_DOUBLE_QUOTED_STRING )) {
578- $ key = new Ast \ConstExpr \ConstExprStringNode (trim ($ tokens ->currentTokenValue (), '" ' ));
586+ if ($ this ->quoteAwareConstExprString ) {
587+ $ key = new Ast \ConstExpr \QuoteAwareConstExprStringNode (trim ($ tokens ->currentTokenValue (), '" ' ), Ast \ConstExpr \QuoteAwareConstExprStringNode::DOUBLE_QUOTED );
588+ } else {
589+ $ key = new Ast \ConstExpr \ConstExprStringNode (trim ($ tokens ->currentTokenValue (), '" ' ));
590+ }
591+
579592 $ tokens ->next ();
580593
581594 } else {
@@ -626,16 +639,24 @@ private function parseObjectShapeItem(TokenIterator $tokens): Ast\Type\ObjectSha
626639
627640 /**
628641 * @phpstan-impure
629- * @return Ast\ConstExpr\ConstExprStringNode|Ast\Type\IdentifierTypeNode
642+ * @return Ast\ConstExpr\QuoteAwareConstExprStringNode|Ast\ConstExpr\ ConstExprStringNode|Ast\Type\IdentifierTypeNode
630643 */
631644 private function parseObjectShapeKey (TokenIterator $ tokens )
632645 {
633646 if ($ tokens ->isCurrentTokenType (Lexer::TOKEN_SINGLE_QUOTED_STRING )) {
634- $ key = new Ast \ConstExpr \ConstExprStringNode (trim ($ tokens ->currentTokenValue (), "' " ));
647+ if ($ this ->quoteAwareConstExprString ) {
648+ $ key = new Ast \ConstExpr \QuoteAwareConstExprStringNode (trim ($ tokens ->currentTokenValue (), "' " ), Ast \ConstExpr \QuoteAwareConstExprStringNode::SINGLE_QUOTED );
649+ } else {
650+ $ key = new Ast \ConstExpr \ConstExprStringNode (trim ($ tokens ->currentTokenValue (), "' " ));
651+ }
635652 $ tokens ->next ();
636653
637654 } elseif ($ tokens ->isCurrentTokenType (Lexer::TOKEN_DOUBLE_QUOTED_STRING )) {
638- $ key = new Ast \ConstExpr \ConstExprStringNode (trim ($ tokens ->currentTokenValue (), '" ' ));
655+ if ($ this ->quoteAwareConstExprString ) {
656+ $ key = new Ast \ConstExpr \QuoteAwareConstExprStringNode (trim ($ tokens ->currentTokenValue (), '" ' ), Ast \ConstExpr \QuoteAwareConstExprStringNode::DOUBLE_QUOTED );
657+ } else {
658+ $ key = new Ast \ConstExpr \ConstExprStringNode (trim ($ tokens ->currentTokenValue (), '" ' ));
659+ }
639660 $ tokens ->next ();
640661
641662 } else {
0 commit comments