@@ -6,72 +6,72 @@ |
||
6 | 6 | |
7 | 7 | class DNumber extends Scalar |
8 | 8 | { |
9 | - /** @var float Number value */ |
|
10 | - public $value; |
|
9 | + /** @var float Number value */ |
|
10 | + public $value; |
|
11 | 11 | |
12 | - /** |
|
13 | - * Constructs a float number scalar node. |
|
14 | - * |
|
15 | - * @param float $value Value of the number |
|
16 | - * @param array $attributes Additional attributes |
|
17 | - */ |
|
18 | - public function __construct(float $value, array $attributes = []) { |
|
19 | - $this->attributes = $attributes; |
|
20 | - $this->value = $value; |
|
21 | - } |
|
12 | + /** |
|
13 | + * Constructs a float number scalar node. |
|
14 | + * |
|
15 | + * @param float $value Value of the number |
|
16 | + * @param array $attributes Additional attributes |
|
17 | + */ |
|
18 | + public function __construct(float $value, array $attributes = []) { |
|
19 | + $this->attributes = $attributes; |
|
20 | + $this->value = $value; |
|
21 | + } |
|
22 | 22 | |
23 | - public function getSubNodeNames() : array { |
|
24 | - return ['value']; |
|
25 | - } |
|
23 | + public function getSubNodeNames() : array { |
|
24 | + return ['value']; |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * @param mixed[] $attributes |
|
29 | - */ |
|
30 | - public static function fromString(string $str, array $attributes = []): DNumber |
|
31 | - { |
|
32 | - $attributes['rawValue'] = $str; |
|
33 | - $float = self::parse($str); |
|
27 | + /** |
|
28 | + * @param mixed[] $attributes |
|
29 | + */ |
|
30 | + public static function fromString(string $str, array $attributes = []): DNumber |
|
31 | + { |
|
32 | + $attributes['rawValue'] = $str; |
|
33 | + $float = self::parse($str); |
|
34 | 34 | |
35 | - return new DNumber($float, $attributes); |
|
36 | - } |
|
35 | + return new DNumber($float, $attributes); |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @internal |
|
40 | - * |
|
41 | - * Parses a DNUMBER token like PHP would. |
|
42 | - * |
|
43 | - * @param string $str A string number |
|
44 | - * |
|
45 | - * @return float The parsed number |
|
46 | - */ |
|
47 | - public static function parse(string $str) : float { |
|
48 | - $str = str_replace('_', '', $str); |
|
38 | + /** |
|
39 | + * @internal |
|
40 | + * |
|
41 | + * Parses a DNUMBER token like PHP would. |
|
42 | + * |
|
43 | + * @param string $str A string number |
|
44 | + * |
|
45 | + * @return float The parsed number |
|
46 | + */ |
|
47 | + public static function parse(string $str) : float { |
|
48 | + $str = str_replace('_', '', $str); |
|
49 | 49 | |
50 | - // Check whether this is one of the special integer notations. |
|
51 | - if ('0' === $str[0]) { |
|
52 | - // hex |
|
53 | - if ('x' === $str[1] || 'X' === $str[1]) { |
|
54 | - return hexdec($str); |
|
55 | - } |
|
50 | + // Check whether this is one of the special integer notations. |
|
51 | + if ('0' === $str[0]) { |
|
52 | + // hex |
|
53 | + if ('x' === $str[1] || 'X' === $str[1]) { |
|
54 | + return hexdec($str); |
|
55 | + } |
|
56 | 56 | |
57 | - // bin |
|
58 | - if ('b' === $str[1] || 'B' === $str[1]) { |
|
59 | - return bindec($str); |
|
60 | - } |
|
57 | + // bin |
|
58 | + if ('b' === $str[1] || 'B' === $str[1]) { |
|
59 | + return bindec($str); |
|
60 | + } |
|
61 | 61 | |
62 | - // oct, but only if the string does not contain any of '.eE'. |
|
63 | - if (false === strpbrk($str, '.eE')) { |
|
64 | - // substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit |
|
65 | - // (8 or 9) so that only the digits before that are used. |
|
66 | - return octdec(substr($str, 0, strcspn($str, '89'))); |
|
67 | - } |
|
68 | - } |
|
62 | + // oct, but only if the string does not contain any of '.eE'. |
|
63 | + if (false === strpbrk($str, '.eE')) { |
|
64 | + // substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit |
|
65 | + // (8 or 9) so that only the digits before that are used. |
|
66 | + return octdec(substr($str, 0, strcspn($str, '89'))); |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | - // dec |
|
71 | - return (float) $str; |
|
72 | - } |
|
70 | + // dec |
|
71 | + return (float) $str; |
|
72 | + } |
|
73 | 73 | |
74 | - public function getType() : string { |
|
75 | - return 'Scalar_DNumber'; |
|
76 | - } |
|
74 | + public function getType() : string { |
|
75 | + return 'Scalar_DNumber'; |
|
76 | + } |
|
77 | 77 | } |
@@ -68,7 +68,7 @@ |
||
68 | 68 | } |
69 | 69 | |
70 | 70 | // dec |
71 | - return (float) $str; |
|
71 | + return (float)$str; |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | public function getType() : string { |
@@ -4,8 +4,7 @@ |
||
4 | 4 | |
5 | 5 | use PhpParser\Node\Scalar; |
6 | 6 | |
7 | -class DNumber extends Scalar |
|
8 | -{ |
|
7 | +class DNumber extends Scalar { |
|
9 | 8 | /** @var float Number value */ |
10 | 9 | public $value; |
11 | 10 |
@@ -7,151 +7,151 @@ |
||
7 | 7 | |
8 | 8 | class String_ extends Scalar |
9 | 9 | { |
10 | - /* For use in "kind" attribute */ |
|
11 | - const KIND_SINGLE_QUOTED = 1; |
|
12 | - const KIND_DOUBLE_QUOTED = 2; |
|
13 | - const KIND_HEREDOC = 3; |
|
14 | - const KIND_NOWDOC = 4; |
|
15 | - |
|
16 | - /** @var string String value */ |
|
17 | - public $value; |
|
18 | - |
|
19 | - protected static $replacements = [ |
|
20 | - '\\' => '\\', |
|
21 | - '$' => '$', |
|
22 | - 'n' => "\n", |
|
23 | - 'r' => "\r", |
|
24 | - 't' => "\t", |
|
25 | - 'f' => "\f", |
|
26 | - 'v' => "\v", |
|
27 | - 'e' => "\x1B", |
|
28 | - ]; |
|
29 | - |
|
30 | - /** |
|
31 | - * Constructs a string scalar node. |
|
32 | - * |
|
33 | - * @param string $value Value of the string |
|
34 | - * @param array $attributes Additional attributes |
|
35 | - */ |
|
36 | - public function __construct(string $value, array $attributes = []) { |
|
37 | - $this->attributes = $attributes; |
|
38 | - $this->value = $value; |
|
39 | - } |
|
40 | - |
|
41 | - public function getSubNodeNames() : array { |
|
42 | - return ['value']; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes |
|
47 | - */ |
|
48 | - public static function fromString(string $str, array $attributes = [], bool $parseUnicodeEscape = true): self |
|
49 | - { |
|
50 | - $attributes['kind'] = ($str[0] === "'" || ($str[1] === "'" && ($str[0] === 'b' || $str[0] === 'B'))) |
|
51 | - ? Scalar\String_::KIND_SINGLE_QUOTED |
|
52 | - : Scalar\String_::KIND_DOUBLE_QUOTED; |
|
53 | - |
|
54 | - $attributes['rawValue'] = $str; |
|
55 | - |
|
56 | - $string = self::parse($str, $parseUnicodeEscape); |
|
57 | - |
|
58 | - return new self($string, $attributes); |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * @internal |
|
63 | - * |
|
64 | - * Parses a string token. |
|
65 | - * |
|
66 | - * @param string $str String token content |
|
67 | - * @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes |
|
68 | - * |
|
69 | - * @return string The parsed string |
|
70 | - */ |
|
71 | - public static function parse(string $str, bool $parseUnicodeEscape = true) : string { |
|
72 | - $bLength = 0; |
|
73 | - if ('b' === $str[0] || 'B' === $str[0]) { |
|
74 | - $bLength = 1; |
|
75 | - } |
|
76 | - |
|
77 | - if ('\'' === $str[$bLength]) { |
|
78 | - return str_replace( |
|
79 | - ['\\\\', '\\\''], |
|
80 | - ['\\', '\''], |
|
81 | - substr($str, $bLength + 1, -1) |
|
82 | - ); |
|
83 | - } else { |
|
84 | - return self::parseEscapeSequences( |
|
85 | - substr($str, $bLength + 1, -1), '"', $parseUnicodeEscape |
|
86 | - ); |
|
87 | - } |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * @internal |
|
92 | - * |
|
93 | - * Parses escape sequences in strings (all string types apart from single quoted). |
|
94 | - * |
|
95 | - * @param string $str String without quotes |
|
96 | - * @param null|string $quote Quote type |
|
97 | - * @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes |
|
98 | - * |
|
99 | - * @return string String with escape sequences parsed |
|
100 | - */ |
|
101 | - public static function parseEscapeSequences(string $str, $quote, bool $parseUnicodeEscape = true) : string { |
|
102 | - if (null !== $quote) { |
|
103 | - $str = str_replace('\\' . $quote, $quote, $str); |
|
104 | - } |
|
105 | - |
|
106 | - $extra = ''; |
|
107 | - if ($parseUnicodeEscape) { |
|
108 | - $extra = '|u\{([0-9a-fA-F]+)\}'; |
|
109 | - } |
|
110 | - |
|
111 | - return preg_replace_callback( |
|
112 | - '~\\\\([\\\\$nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3}' . $extra . ')~', |
|
113 | - function($matches) { |
|
114 | - $str = $matches[1]; |
|
115 | - |
|
116 | - if (isset(self::$replacements[$str])) { |
|
117 | - return self::$replacements[$str]; |
|
118 | - } elseif ('x' === $str[0] || 'X' === $str[0]) { |
|
119 | - return chr(hexdec(substr($str, 1))); |
|
120 | - } elseif ('u' === $str[0]) { |
|
121 | - return self::codePointToUtf8(hexdec($matches[2])); |
|
122 | - } else { |
|
123 | - return chr(octdec($str)); |
|
124 | - } |
|
125 | - }, |
|
126 | - $str |
|
127 | - ); |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Converts a Unicode code point to its UTF-8 encoded representation. |
|
132 | - * |
|
133 | - * @param int $num Code point |
|
134 | - * |
|
135 | - * @return string UTF-8 representation of code point |
|
136 | - */ |
|
137 | - private static function codePointToUtf8(int $num) : string { |
|
138 | - if ($num <= 0x7F) { |
|
139 | - return chr($num); |
|
140 | - } |
|
141 | - if ($num <= 0x7FF) { |
|
142 | - return chr(($num>>6) + 0xC0) . chr(($num&0x3F) + 0x80); |
|
143 | - } |
|
144 | - if ($num <= 0xFFFF) { |
|
145 | - return chr(($num>>12) + 0xE0) . chr((($num>>6)&0x3F) + 0x80) . chr(($num&0x3F) + 0x80); |
|
146 | - } |
|
147 | - if ($num <= 0x1FFFFF) { |
|
148 | - return chr(($num>>18) + 0xF0) . chr((($num>>12)&0x3F) + 0x80) |
|
149 | - . chr((($num>>6)&0x3F) + 0x80) . chr(($num&0x3F) + 0x80); |
|
150 | - } |
|
151 | - throw new Error('Invalid UTF-8 codepoint escape sequence: Codepoint too large'); |
|
152 | - } |
|
153 | - |
|
154 | - public function getType() : string { |
|
155 | - return 'Scalar_String'; |
|
156 | - } |
|
10 | + /* For use in "kind" attribute */ |
|
11 | + const KIND_SINGLE_QUOTED = 1; |
|
12 | + const KIND_DOUBLE_QUOTED = 2; |
|
13 | + const KIND_HEREDOC = 3; |
|
14 | + const KIND_NOWDOC = 4; |
|
15 | + |
|
16 | + /** @var string String value */ |
|
17 | + public $value; |
|
18 | + |
|
19 | + protected static $replacements = [ |
|
20 | + '\\' => '\\', |
|
21 | + '$' => '$', |
|
22 | + 'n' => "\n", |
|
23 | + 'r' => "\r", |
|
24 | + 't' => "\t", |
|
25 | + 'f' => "\f", |
|
26 | + 'v' => "\v", |
|
27 | + 'e' => "\x1B", |
|
28 | + ]; |
|
29 | + |
|
30 | + /** |
|
31 | + * Constructs a string scalar node. |
|
32 | + * |
|
33 | + * @param string $value Value of the string |
|
34 | + * @param array $attributes Additional attributes |
|
35 | + */ |
|
36 | + public function __construct(string $value, array $attributes = []) { |
|
37 | + $this->attributes = $attributes; |
|
38 | + $this->value = $value; |
|
39 | + } |
|
40 | + |
|
41 | + public function getSubNodeNames() : array { |
|
42 | + return ['value']; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes |
|
47 | + */ |
|
48 | + public static function fromString(string $str, array $attributes = [], bool $parseUnicodeEscape = true): self |
|
49 | + { |
|
50 | + $attributes['kind'] = ($str[0] === "'" || ($str[1] === "'" && ($str[0] === 'b' || $str[0] === 'B'))) |
|
51 | + ? Scalar\String_::KIND_SINGLE_QUOTED |
|
52 | + : Scalar\String_::KIND_DOUBLE_QUOTED; |
|
53 | + |
|
54 | + $attributes['rawValue'] = $str; |
|
55 | + |
|
56 | + $string = self::parse($str, $parseUnicodeEscape); |
|
57 | + |
|
58 | + return new self($string, $attributes); |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * @internal |
|
63 | + * |
|
64 | + * Parses a string token. |
|
65 | + * |
|
66 | + * @param string $str String token content |
|
67 | + * @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes |
|
68 | + * |
|
69 | + * @return string The parsed string |
|
70 | + */ |
|
71 | + public static function parse(string $str, bool $parseUnicodeEscape = true) : string { |
|
72 | + $bLength = 0; |
|
73 | + if ('b' === $str[0] || 'B' === $str[0]) { |
|
74 | + $bLength = 1; |
|
75 | + } |
|
76 | + |
|
77 | + if ('\'' === $str[$bLength]) { |
|
78 | + return str_replace( |
|
79 | + ['\\\\', '\\\''], |
|
80 | + ['\\', '\''], |
|
81 | + substr($str, $bLength + 1, -1) |
|
82 | + ); |
|
83 | + } else { |
|
84 | + return self::parseEscapeSequences( |
|
85 | + substr($str, $bLength + 1, -1), '"', $parseUnicodeEscape |
|
86 | + ); |
|
87 | + } |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * @internal |
|
92 | + * |
|
93 | + * Parses escape sequences in strings (all string types apart from single quoted). |
|
94 | + * |
|
95 | + * @param string $str String without quotes |
|
96 | + * @param null|string $quote Quote type |
|
97 | + * @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes |
|
98 | + * |
|
99 | + * @return string String with escape sequences parsed |
|
100 | + */ |
|
101 | + public static function parseEscapeSequences(string $str, $quote, bool $parseUnicodeEscape = true) : string { |
|
102 | + if (null !== $quote) { |
|
103 | + $str = str_replace('\\' . $quote, $quote, $str); |
|
104 | + } |
|
105 | + |
|
106 | + $extra = ''; |
|
107 | + if ($parseUnicodeEscape) { |
|
108 | + $extra = '|u\{([0-9a-fA-F]+)\}'; |
|
109 | + } |
|
110 | + |
|
111 | + return preg_replace_callback( |
|
112 | + '~\\\\([\\\\$nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3}' . $extra . ')~', |
|
113 | + function($matches) { |
|
114 | + $str = $matches[1]; |
|
115 | + |
|
116 | + if (isset(self::$replacements[$str])) { |
|
117 | + return self::$replacements[$str]; |
|
118 | + } elseif ('x' === $str[0] || 'X' === $str[0]) { |
|
119 | + return chr(hexdec(substr($str, 1))); |
|
120 | + } elseif ('u' === $str[0]) { |
|
121 | + return self::codePointToUtf8(hexdec($matches[2])); |
|
122 | + } else { |
|
123 | + return chr(octdec($str)); |
|
124 | + } |
|
125 | + }, |
|
126 | + $str |
|
127 | + ); |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Converts a Unicode code point to its UTF-8 encoded representation. |
|
132 | + * |
|
133 | + * @param int $num Code point |
|
134 | + * |
|
135 | + * @return string UTF-8 representation of code point |
|
136 | + */ |
|
137 | + private static function codePointToUtf8(int $num) : string { |
|
138 | + if ($num <= 0x7F) { |
|
139 | + return chr($num); |
|
140 | + } |
|
141 | + if ($num <= 0x7FF) { |
|
142 | + return chr(($num>>6) + 0xC0) . chr(($num&0x3F) + 0x80); |
|
143 | + } |
|
144 | + if ($num <= 0xFFFF) { |
|
145 | + return chr(($num>>12) + 0xE0) . chr((($num>>6)&0x3F) + 0x80) . chr(($num&0x3F) + 0x80); |
|
146 | + } |
|
147 | + if ($num <= 0x1FFFFF) { |
|
148 | + return chr(($num>>18) + 0xF0) . chr((($num>>12)&0x3F) + 0x80) |
|
149 | + . chr((($num>>6)&0x3F) + 0x80) . chr(($num&0x3F) + 0x80); |
|
150 | + } |
|
151 | + throw new Error('Invalid UTF-8 codepoint escape sequence: Codepoint too large'); |
|
152 | + } |
|
153 | + |
|
154 | + public function getType() : string { |
|
155 | + return 'Scalar_String'; |
|
156 | + } |
|
157 | 157 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public static function parseEscapeSequences(string $str, $quote, bool $parseUnicodeEscape = true) : string { |
102 | 102 | if (null !== $quote) { |
103 | - $str = str_replace('\\' . $quote, $quote, $str); |
|
103 | + $str = str_replace('\\'.$quote, $quote, $str); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | $extra = ''; |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | } |
110 | 110 | |
111 | 111 | return preg_replace_callback( |
112 | - '~\\\\([\\\\$nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3}' . $extra . ')~', |
|
112 | + '~\\\\([\\\\$nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3}'.$extra.')~', |
|
113 | 113 | function($matches) { |
114 | 114 | $str = $matches[1]; |
115 | 115 | |
@@ -139,14 +139,14 @@ discard block |
||
139 | 139 | return chr($num); |
140 | 140 | } |
141 | 141 | if ($num <= 0x7FF) { |
142 | - return chr(($num>>6) + 0xC0) . chr(($num&0x3F) + 0x80); |
|
142 | + return chr(($num >> 6) + 0xC0).chr(($num&0x3F) + 0x80); |
|
143 | 143 | } |
144 | 144 | if ($num <= 0xFFFF) { |
145 | - return chr(($num>>12) + 0xE0) . chr((($num>>6)&0x3F) + 0x80) . chr(($num&0x3F) + 0x80); |
|
145 | + return chr(($num >> 12) + 0xE0).chr((($num >> 6)&0x3F) + 0x80).chr(($num&0x3F) + 0x80); |
|
146 | 146 | } |
147 | 147 | if ($num <= 0x1FFFFF) { |
148 | - return chr(($num>>18) + 0xF0) . chr((($num>>12)&0x3F) + 0x80) |
|
149 | - . chr((($num>>6)&0x3F) + 0x80) . chr(($num&0x3F) + 0x80); |
|
148 | + return chr(($num >> 18) + 0xF0).chr((($num >> 12)&0x3F) + 0x80) |
|
149 | + . chr((($num >> 6)&0x3F) + 0x80).chr(($num&0x3F) + 0x80); |
|
150 | 150 | } |
151 | 151 | throw new Error('Invalid UTF-8 codepoint escape sequence: Codepoint too large'); |
152 | 152 | } |
@@ -5,8 +5,7 @@ |
||
5 | 5 | use PhpParser\Error; |
6 | 6 | use PhpParser\Node\Scalar; |
7 | 7 | |
8 | -class String_ extends Scalar |
|
9 | -{ |
|
8 | +class String_ extends Scalar { |
|
10 | 9 | /* For use in "kind" attribute */ |
11 | 10 | const KIND_SINGLE_QUOTED = 1; |
12 | 11 | const KIND_DOUBLE_QUOTED = 2; |
@@ -6,23 +6,23 @@ |
||
6 | 6 | |
7 | 7 | abstract class MagicConst extends Scalar |
8 | 8 | { |
9 | - /** |
|
10 | - * Constructs a magic constant node. |
|
11 | - * |
|
12 | - * @param array $attributes Additional attributes |
|
13 | - */ |
|
14 | - public function __construct(array $attributes = []) { |
|
15 | - $this->attributes = $attributes; |
|
16 | - } |
|
9 | + /** |
|
10 | + * Constructs a magic constant node. |
|
11 | + * |
|
12 | + * @param array $attributes Additional attributes |
|
13 | + */ |
|
14 | + public function __construct(array $attributes = []) { |
|
15 | + $this->attributes = $attributes; |
|
16 | + } |
|
17 | 17 | |
18 | - public function getSubNodeNames() : array { |
|
19 | - return []; |
|
20 | - } |
|
18 | + public function getSubNodeNames() : array { |
|
19 | + return []; |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * Get name of magic constant. |
|
24 | - * |
|
25 | - * @return string Name of magic constant |
|
26 | - */ |
|
27 | - abstract public function getName() : string; |
|
22 | + /** |
|
23 | + * Get name of magic constant. |
|
24 | + * |
|
25 | + * @return string Name of magic constant |
|
26 | + */ |
|
27 | + abstract public function getName() : string; |
|
28 | 28 | } |
@@ -4,8 +4,7 @@ |
||
4 | 4 | |
5 | 5 | use PhpParser\Node\Scalar; |
6 | 6 | |
7 | -abstract class MagicConst extends Scalar |
|
8 | -{ |
|
7 | +abstract class MagicConst extends Scalar { |
|
9 | 8 | /** |
10 | 9 | * Constructs a magic constant node. |
11 | 10 | * |
@@ -7,25 +7,25 @@ |
||
7 | 7 | |
8 | 8 | class Encapsed extends Scalar |
9 | 9 | { |
10 | - /** @var Expr[] list of string parts */ |
|
11 | - public $parts; |
|
10 | + /** @var Expr[] list of string parts */ |
|
11 | + public $parts; |
|
12 | 12 | |
13 | - /** |
|
14 | - * Constructs an encapsed string node. |
|
15 | - * |
|
16 | - * @param Expr[] $parts Encaps list |
|
17 | - * @param array $attributes Additional attributes |
|
18 | - */ |
|
19 | - public function __construct(array $parts, array $attributes = []) { |
|
20 | - $this->attributes = $attributes; |
|
21 | - $this->parts = $parts; |
|
22 | - } |
|
13 | + /** |
|
14 | + * Constructs an encapsed string node. |
|
15 | + * |
|
16 | + * @param Expr[] $parts Encaps list |
|
17 | + * @param array $attributes Additional attributes |
|
18 | + */ |
|
19 | + public function __construct(array $parts, array $attributes = []) { |
|
20 | + $this->attributes = $attributes; |
|
21 | + $this->parts = $parts; |
|
22 | + } |
|
23 | 23 | |
24 | - public function getSubNodeNames() : array { |
|
25 | - return ['parts']; |
|
26 | - } |
|
24 | + public function getSubNodeNames() : array { |
|
25 | + return ['parts']; |
|
26 | + } |
|
27 | 27 | |
28 | - public function getType() : string { |
|
29 | - return 'Scalar_Encapsed'; |
|
30 | - } |
|
28 | + public function getType() : string { |
|
29 | + return 'Scalar_Encapsed'; |
|
30 | + } |
|
31 | 31 | } |
@@ -5,8 +5,7 @@ |
||
5 | 5 | use PhpParser\Node\Expr; |
6 | 6 | use PhpParser\Node\Scalar; |
7 | 7 | |
8 | -class Encapsed extends Scalar |
|
9 | -{ |
|
8 | +class Encapsed extends Scalar { |
|
10 | 9 | /** @var Expr[] list of string parts */ |
11 | 10 | public $parts; |
12 | 11 |
@@ -6,25 +6,25 @@ |
||
6 | 6 | |
7 | 7 | class EncapsedStringPart extends Scalar |
8 | 8 | { |
9 | - /** @var string String value */ |
|
10 | - public $value; |
|
9 | + /** @var string String value */ |
|
10 | + public $value; |
|
11 | 11 | |
12 | - /** |
|
13 | - * Constructs a node representing a string part of an encapsed string. |
|
14 | - * |
|
15 | - * @param string $value String value |
|
16 | - * @param array $attributes Additional attributes |
|
17 | - */ |
|
18 | - public function __construct(string $value, array $attributes = []) { |
|
19 | - $this->attributes = $attributes; |
|
20 | - $this->value = $value; |
|
21 | - } |
|
12 | + /** |
|
13 | + * Constructs a node representing a string part of an encapsed string. |
|
14 | + * |
|
15 | + * @param string $value String value |
|
16 | + * @param array $attributes Additional attributes |
|
17 | + */ |
|
18 | + public function __construct(string $value, array $attributes = []) { |
|
19 | + $this->attributes = $attributes; |
|
20 | + $this->value = $value; |
|
21 | + } |
|
22 | 22 | |
23 | - public function getSubNodeNames() : array { |
|
24 | - return ['value']; |
|
25 | - } |
|
23 | + public function getSubNodeNames() : array { |
|
24 | + return ['value']; |
|
25 | + } |
|
26 | 26 | |
27 | - public function getType() : string { |
|
28 | - return 'Scalar_EncapsedStringPart'; |
|
29 | - } |
|
27 | + public function getType() : string { |
|
28 | + return 'Scalar_EncapsedStringPart'; |
|
29 | + } |
|
30 | 30 | } |
@@ -4,8 +4,7 @@ |
||
4 | 4 | |
5 | 5 | use PhpParser\Node\Scalar; |
6 | 6 | |
7 | -class EncapsedStringPart extends Scalar |
|
8 | -{ |
|
7 | +class EncapsedStringPart extends Scalar { |
|
9 | 8 | /** @var string String value */ |
10 | 9 | public $value; |
11 | 10 |
@@ -7,74 +7,74 @@ |
||
7 | 7 | |
8 | 8 | class LNumber extends Scalar |
9 | 9 | { |
10 | - /* For use in "kind" attribute */ |
|
11 | - const KIND_BIN = 2; |
|
12 | - const KIND_OCT = 8; |
|
13 | - const KIND_DEC = 10; |
|
14 | - const KIND_HEX = 16; |
|
10 | + /* For use in "kind" attribute */ |
|
11 | + const KIND_BIN = 2; |
|
12 | + const KIND_OCT = 8; |
|
13 | + const KIND_DEC = 10; |
|
14 | + const KIND_HEX = 16; |
|
15 | 15 | |
16 | - /** @var int Number value */ |
|
17 | - public $value; |
|
16 | + /** @var int Number value */ |
|
17 | + public $value; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Constructs an integer number scalar node. |
|
21 | - * |
|
22 | - * @param int $value Value of the number |
|
23 | - * @param array $attributes Additional attributes |
|
24 | - */ |
|
25 | - public function __construct(int $value, array $attributes = []) { |
|
26 | - $this->attributes = $attributes; |
|
27 | - $this->value = $value; |
|
28 | - } |
|
19 | + /** |
|
20 | + * Constructs an integer number scalar node. |
|
21 | + * |
|
22 | + * @param int $value Value of the number |
|
23 | + * @param array $attributes Additional attributes |
|
24 | + */ |
|
25 | + public function __construct(int $value, array $attributes = []) { |
|
26 | + $this->attributes = $attributes; |
|
27 | + $this->value = $value; |
|
28 | + } |
|
29 | 29 | |
30 | - public function getSubNodeNames() : array { |
|
31 | - return ['value']; |
|
32 | - } |
|
30 | + public function getSubNodeNames() : array { |
|
31 | + return ['value']; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Constructs an LNumber node from a string number literal. |
|
36 | - * |
|
37 | - * @param string $str String number literal (decimal, octal, hex or binary) |
|
38 | - * @param array $attributes Additional attributes |
|
39 | - * @param bool $allowInvalidOctal Whether to allow invalid octal numbers (PHP 5) |
|
40 | - * |
|
41 | - * @return LNumber The constructed LNumber, including kind attribute |
|
42 | - */ |
|
43 | - public static function fromString(string $str, array $attributes = [], bool $allowInvalidOctal = false) : LNumber { |
|
44 | - $attributes['rawValue'] = $str; |
|
34 | + /** |
|
35 | + * Constructs an LNumber node from a string number literal. |
|
36 | + * |
|
37 | + * @param string $str String number literal (decimal, octal, hex or binary) |
|
38 | + * @param array $attributes Additional attributes |
|
39 | + * @param bool $allowInvalidOctal Whether to allow invalid octal numbers (PHP 5) |
|
40 | + * |
|
41 | + * @return LNumber The constructed LNumber, including kind attribute |
|
42 | + */ |
|
43 | + public static function fromString(string $str, array $attributes = [], bool $allowInvalidOctal = false) : LNumber { |
|
44 | + $attributes['rawValue'] = $str; |
|
45 | 45 | |
46 | - $str = str_replace('_', '', $str); |
|
46 | + $str = str_replace('_', '', $str); |
|
47 | 47 | |
48 | - if ('0' !== $str[0] || '0' === $str) { |
|
49 | - $attributes['kind'] = LNumber::KIND_DEC; |
|
50 | - return new LNumber((int) $str, $attributes); |
|
51 | - } |
|
48 | + if ('0' !== $str[0] || '0' === $str) { |
|
49 | + $attributes['kind'] = LNumber::KIND_DEC; |
|
50 | + return new LNumber((int) $str, $attributes); |
|
51 | + } |
|
52 | 52 | |
53 | - if ('x' === $str[1] || 'X' === $str[1]) { |
|
54 | - $attributes['kind'] = LNumber::KIND_HEX; |
|
55 | - return new LNumber(hexdec($str), $attributes); |
|
56 | - } |
|
53 | + if ('x' === $str[1] || 'X' === $str[1]) { |
|
54 | + $attributes['kind'] = LNumber::KIND_HEX; |
|
55 | + return new LNumber(hexdec($str), $attributes); |
|
56 | + } |
|
57 | 57 | |
58 | - if ('b' === $str[1] || 'B' === $str[1]) { |
|
59 | - $attributes['kind'] = LNumber::KIND_BIN; |
|
60 | - return new LNumber(bindec($str), $attributes); |
|
61 | - } |
|
58 | + if ('b' === $str[1] || 'B' === $str[1]) { |
|
59 | + $attributes['kind'] = LNumber::KIND_BIN; |
|
60 | + return new LNumber(bindec($str), $attributes); |
|
61 | + } |
|
62 | 62 | |
63 | - if (!$allowInvalidOctal && strpbrk($str, '89')) { |
|
64 | - throw new Error('Invalid numeric literal', $attributes); |
|
65 | - } |
|
63 | + if (!$allowInvalidOctal && strpbrk($str, '89')) { |
|
64 | + throw new Error('Invalid numeric literal', $attributes); |
|
65 | + } |
|
66 | 66 | |
67 | - // Strip optional explicit octal prefix. |
|
68 | - if ('o' === $str[1] || 'O' === $str[1]) { |
|
69 | - $str = substr($str, 2); |
|
70 | - } |
|
67 | + // Strip optional explicit octal prefix. |
|
68 | + if ('o' === $str[1] || 'O' === $str[1]) { |
|
69 | + $str = substr($str, 2); |
|
70 | + } |
|
71 | 71 | |
72 | - // use intval instead of octdec to get proper cutting behavior with malformed numbers |
|
73 | - $attributes['kind'] = LNumber::KIND_OCT; |
|
74 | - return new LNumber(intval($str, 8), $attributes); |
|
75 | - } |
|
72 | + // use intval instead of octdec to get proper cutting behavior with malformed numbers |
|
73 | + $attributes['kind'] = LNumber::KIND_OCT; |
|
74 | + return new LNumber(intval($str, 8), $attributes); |
|
75 | + } |
|
76 | 76 | |
77 | - public function getType() : string { |
|
78 | - return 'Scalar_LNumber'; |
|
79 | - } |
|
77 | + public function getType() : string { |
|
78 | + return 'Scalar_LNumber'; |
|
79 | + } |
|
80 | 80 | } |
@@ -47,7 +47,7 @@ |
||
47 | 47 | |
48 | 48 | if ('0' !== $str[0] || '0' === $str) { |
49 | 49 | $attributes['kind'] = LNumber::KIND_DEC; |
50 | - return new LNumber((int) $str, $attributes); |
|
50 | + return new LNumber((int)$str, $attributes); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | if ('x' === $str[1] || 'X' === $str[1]) { |
@@ -5,8 +5,7 @@ |
||
5 | 5 | use PhpParser\Error; |
6 | 6 | use PhpParser\Node\Scalar; |
7 | 7 | |
8 | -class LNumber extends Scalar |
|
9 | -{ |
|
8 | +class LNumber extends Scalar { |
|
10 | 9 | /* For use in "kind" attribute */ |
11 | 10 | const KIND_BIN = 2; |
12 | 11 | const KIND_OCT = 8; |
@@ -6,11 +6,11 @@ |
||
6 | 6 | |
7 | 7 | class Function_ extends MagicConst |
8 | 8 | { |
9 | - public function getName() : string { |
|
10 | - return '__FUNCTION__'; |
|
11 | - } |
|
9 | + public function getName() : string { |
|
10 | + return '__FUNCTION__'; |
|
11 | + } |
|
12 | 12 | |
13 | - public function getType() : string { |
|
14 | - return 'Scalar_MagicConst_Function'; |
|
15 | - } |
|
13 | + public function getType() : string { |
|
14 | + return 'Scalar_MagicConst_Function'; |
|
15 | + } |
|
16 | 16 | } |
@@ -4,8 +4,7 @@ |
||
4 | 4 | |
5 | 5 | use PhpParser\Node\Scalar\MagicConst; |
6 | 6 | |
7 | -class Function_ extends MagicConst |
|
8 | -{ |
|
7 | +class Function_ extends MagicConst { |
|
9 | 8 | public function getName() : string { |
10 | 9 | return '__FUNCTION__'; |
11 | 10 | } |
@@ -6,11 +6,11 @@ |
||
6 | 6 | |
7 | 7 | class File extends MagicConst |
8 | 8 | { |
9 | - public function getName() : string { |
|
10 | - return '__FILE__'; |
|
11 | - } |
|
9 | + public function getName() : string { |
|
10 | + return '__FILE__'; |
|
11 | + } |
|
12 | 12 | |
13 | - public function getType() : string { |
|
14 | - return 'Scalar_MagicConst_File'; |
|
15 | - } |
|
13 | + public function getType() : string { |
|
14 | + return 'Scalar_MagicConst_File'; |
|
15 | + } |
|
16 | 16 | } |
@@ -4,8 +4,7 @@ |
||
4 | 4 | |
5 | 5 | use PhpParser\Node\Scalar\MagicConst; |
6 | 6 | |
7 | -class File extends MagicConst |
|
8 | -{ |
|
7 | +class File extends MagicConst { |
|
9 | 8 | public function getName() : string { |
10 | 9 | return '__FILE__'; |
11 | 10 | } |
@@ -6,11 +6,11 @@ |
||
6 | 6 | |
7 | 7 | class Class_ extends MagicConst |
8 | 8 | { |
9 | - public function getName() : string { |
|
10 | - return '__CLASS__'; |
|
11 | - } |
|
9 | + public function getName() : string { |
|
10 | + return '__CLASS__'; |
|
11 | + } |
|
12 | 12 | |
13 | - public function getType() : string { |
|
14 | - return 'Scalar_MagicConst_Class'; |
|
15 | - } |
|
13 | + public function getType() : string { |
|
14 | + return 'Scalar_MagicConst_Class'; |
|
15 | + } |
|
16 | 16 | } |
@@ -4,8 +4,7 @@ |
||
4 | 4 | |
5 | 5 | use PhpParser\Node\Scalar\MagicConst; |
6 | 6 | |
7 | -class Class_ extends MagicConst |
|
8 | -{ |
|
7 | +class Class_ extends MagicConst { |
|
9 | 8 | public function getName() : string { |
10 | 9 | return '__CLASS__'; |
11 | 10 | } |