@@ -15,9 +15,13 @@ class TypeParser
15
15
/** @var ConstExprParser|null */
16
16
private $ constExprParser ;
17
17
18
- public function __construct (?ConstExprParser $ constExprParser = null )
18
+ /** @var bool */
19
+ private $ quoteAwareConstExprString ;
20
+
21
+ public function __construct (?ConstExprParser $ constExprParser = null , bool $ quoteAwareConstExprString = false )
19
22
{
20
23
$ this ->constExprParser = $ constExprParser ;
24
+ $ this ->quoteAwareConstExprString = $ quoteAwareConstExprString ;
21
25
}
22
26
23
27
/** @phpstan-impure */
@@ -562,7 +566,7 @@ private function parseArrayShapeItem(TokenIterator $tokens): Ast\Type\ArrayShape
562
566
563
567
/**
564
568
* @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
566
570
*/
567
571
private function parseArrayShapeKey (TokenIterator $ tokens )
568
572
{
@@ -571,11 +575,20 @@ private function parseArrayShapeKey(TokenIterator $tokens)
571
575
$ tokens ->next ();
572
576
573
577
} 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
+ }
575
583
$ tokens ->next ();
576
584
577
585
} 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
+
579
592
$ tokens ->next ();
580
593
581
594
} else {
@@ -626,16 +639,24 @@ private function parseObjectShapeItem(TokenIterator $tokens): Ast\Type\ObjectSha
626
639
627
640
/**
628
641
* @phpstan-impure
629
- * @return Ast\ConstExpr\ConstExprStringNode|Ast\Type\IdentifierTypeNode
642
+ * @return Ast\ConstExpr\QuoteAwareConstExprStringNode|Ast\ConstExpr\ ConstExprStringNode|Ast\Type\IdentifierTypeNode
630
643
*/
631
644
private function parseObjectShapeKey (TokenIterator $ tokens )
632
645
{
633
646
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
+ }
635
652
$ tokens ->next ();
636
653
637
654
} 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
+ }
639
660
$ tokens ->next ();
640
661
641
662
} else {
0 commit comments