@@ -31,14 +31,14 @@ public function __construct(int $startingLine = 1)
31
31
public function preLexComponents (string $ input ): string
32
32
{
33
33
$ this ->input = $ input ;
34
- $ this ->length = strlen ($ input );
34
+ $ this ->length = \ strlen ($ input );
35
35
$ output = '' ;
36
36
37
37
while ($ this ->position < $ this ->length ) {
38
38
if ($ this ->consume ('<t: ' )) {
39
39
$ componentName = $ this ->consumeComponentName ();
40
40
41
- if ($ componentName === ' block ' ) {
41
+ if (' block ' === $ componentName ) {
42
42
$ output .= $ this ->consumeBlock ();
43
43
44
44
continue ;
@@ -51,7 +51,7 @@ public function preLexComponents(string $input): string
51
51
$ this ->currentComponents [] = $ componentName ;
52
52
}
53
53
54
- $ output .= "{% component {$ componentName }" . ($ attributes ? " with { {$ attributes } } " : '' ) . " %} " ;
54
+ $ output .= "{% component {$ componentName }" . ($ attributes ? " with { {$ attributes } } " : '' ). ' %} ' ;
55
55
if ($ isSelfClosing ) {
56
56
$ output .= '{% endcomponent %} ' ;
57
57
}
@@ -70,14 +70,14 @@ public function preLexComponents(string $input): string
70
70
throw new \RuntimeException ("Expected closing tag '</t: {$ lastComponent }>' but found '</t: {$ closingComponentName }>' at line {$ this ->line }" );
71
71
}
72
72
73
- $ output .= " {% endcomponent %} " ;
73
+ $ output .= ' {% endcomponent %} ' ;
74
74
75
75
continue ;
76
76
}
77
77
78
78
$ char = $ this ->consumeChar ();
79
- if ($ char === "\n" ) {
80
- $ this ->line ++ ;
79
+ if ("\n" === $ char ) {
80
+ ++ $ this ->line ;
81
81
}
82
82
$ output .= $ char ;
83
83
}
@@ -89,7 +89,7 @@ private function consumeComponentName(): string
89
89
{
90
90
$ start = $ this ->position ;
91
91
while ($ this ->position < $ this ->length && preg_match ('/[A-Za-z0-9_]/ ' , $ this ->input [$ this ->position ])) {
92
- $ this ->position ++ ;
92
+ ++ $ this ->position ;
93
93
}
94
94
$ componentName = substr ($ this ->input , $ start , $ this ->position - $ start );
95
95
@@ -122,7 +122,7 @@ private function consumeAttributes(): string
122
122
123
123
// <t:component someProp> -> someProp: true
124
124
if (!$ this ->check ('= ' )) {
125
- $ attributes [] = sprintf (" %s: true " , $ key );
125
+ $ attributes [] = sprintf (' %s: true ' , $ key );
126
126
$ this ->consumeWhitespace ();
127
127
continue ;
128
128
}
@@ -144,7 +144,7 @@ private function consumeAttributes(): string
144
144
$ this ->expectAndConsumeChar ($ quote );
145
145
146
146
if ($ isAttributeDynamic ) {
147
- $ attributes [] = sprintf (" %s: %s " , $ key , $ attributeValue );
147
+ $ attributes [] = sprintf (' %s: %s ' , $ key , $ attributeValue );
148
148
} else {
149
149
$ attributes [] = sprintf ("%s: '%s' " , $ key , str_replace ("' " , "\' " , $ attributeValue ));
150
150
}
@@ -157,8 +157,9 @@ private function consumeAttributes(): string
157
157
158
158
private function consume (string $ string ): bool
159
159
{
160
- if (substr ($ this ->input , $ this ->position , strlen ($ string )) === $ string ) {
161
- $ this ->position += strlen ($ string );
160
+ if (substr ($ this ->input , $ this ->position , \strlen ($ string )) === $ string ) {
161
+ $ this ->position += \strlen ($ string );
162
+
162
163
return true ;
163
164
}
164
165
@@ -168,34 +169,34 @@ private function consume(string $string): bool
168
169
private function consumeChar ($ validChars = null ): string
169
170
{
170
171
if ($ this ->position >= $ this ->length ) {
171
- throw new \RuntimeException (" Unexpected end of input " );
172
+ throw new \RuntimeException (' Unexpected end of input ' );
172
173
}
173
174
174
175
$ char = $ this ->input [$ this ->position ];
175
176
176
- if ($ validChars !== null && !in_array ($ char , (array )$ validChars , true )) {
177
- throw new \RuntimeException (" Expected one of [ " . implode ('' , (array )$ validChars ) . "] but found ' {$ char }' at line {$ this ->line }" );
177
+ if (null !== $ validChars && !\ in_array ($ char , (array ) $ validChars , true )) {
178
+ throw new \RuntimeException (' Expected one of [ ' . implode ('' , (array ) $ validChars ). "] but found ' {$ char }' at line {$ this ->line }" );
178
179
}
179
180
180
- $ this ->position ++ ;
181
+ ++ $ this ->position ;
181
182
182
183
return $ char ;
183
184
}
184
185
185
186
private function consumeUntil (string $ endString ): string
186
187
{
187
188
$ start = $ this ->position ;
188
- $ endCharLength = strlen ($ endString );
189
+ $ endCharLength = \ strlen ($ endString );
189
190
190
191
while ($ this ->position < $ this ->length ) {
191
192
if (substr ($ this ->input , $ this ->position , $ endCharLength ) === $ endString ) {
192
193
break ;
193
194
}
194
195
195
- if ($ this ->input [$ this ->position ] === "\n" ) {
196
- $ this ->line ++ ;
196
+ if ("\n" === $ this ->input [$ this ->position ]) {
197
+ ++ $ this ->line ;
197
198
}
198
- $ this ->position ++ ;
199
+ ++ $ this ->position ;
199
200
}
200
201
201
202
return substr ($ this ->input , $ start , $ this ->position - $ start );
@@ -204,10 +205,10 @@ private function consumeUntil(string $endString): string
204
205
private function consumeWhitespace (): void
205
206
{
206
207
while ($ this ->position < $ this ->length && preg_match ('/\s/ ' , $ this ->input [$ this ->position ])) {
207
- if ($ this ->input [$ this ->position ] === "\n" ) {
208
- $ this ->line ++ ;
208
+ if ("\n" === $ this ->input [$ this ->position ]) {
209
+ ++ $ this ->line ;
209
210
}
210
- $ this ->position ++ ;
211
+ ++ $ this ->position ;
211
212
}
212
213
}
213
214
@@ -216,24 +217,24 @@ private function consumeWhitespace(): void
216
217
*/
217
218
private function expectAndConsumeChar (string $ char ): void
218
219
{
219
- if (strlen ( $ char ) !== 1 ) {
220
+ if (1 !== \strlen ( $ char ) ) {
220
221
throw new \InvalidArgumentException ('Expected a single character ' );
221
222
}
222
223
223
224
if ($ this ->position >= $ this ->length || $ this ->input [$ this ->position ] !== $ char ) {
224
225
throw new \RuntimeException ("Expected ' {$ char }' but found ' {$ this ->input [$ this ->position ]}' at line {$ this ->line }" );
225
226
}
226
- $ this ->position ++ ;
227
+ ++ $ this ->position ;
227
228
}
228
229
229
230
private function check (string $ chars ): bool
230
231
{
231
- $ charsLength = strlen ($ chars );
232
+ $ charsLength = \ strlen ($ chars );
232
233
if ($ this ->position + $ charsLength > $ this ->length ) {
233
234
return false ;
234
235
}
235
236
236
- for ($ i = 0 ; $ i < $ charsLength ; $ i ++ ) {
237
+ for ($ i = 0 ; $ i < $ charsLength ; ++ $ i ) {
237
238
if ($ this ->input [$ this ->position + $ i ] !== $ chars [$ i ]) {
238
239
return false ;
239
240
}
@@ -249,8 +250,8 @@ private function consumeBlock(): string
249
250
250
251
$ blockName = '' ;
251
252
foreach (explode (', ' , $ attributes ) as $ attr ) {
252
- list ( $ key , $ value) = explode (': ' , $ attr );
253
- if ($ key === ' name ' ) {
253
+ [ $ key , $ value] = explode (': ' , $ attr );
254
+ if (' name ' === $ key ) {
254
255
$ blockName = trim ($ value , "' " );
255
256
break ;
256
257
}
@@ -262,7 +263,7 @@ private function consumeBlock(): string
262
263
263
264
$ output = "{% block {$ blockName } %} " ;
264
265
265
- $ closingTag = " </t:block> " ;
266
+ $ closingTag = ' </t:block> ' ;
266
267
if (!$ this ->doesStringEventuallyExist ($ closingTag )) {
267
268
throw new \RuntimeException ("Expected closing tag ' {$ closingTag }' for block ' {$ blockName }' at line {$ this ->line }" );
268
269
}
@@ -272,7 +273,7 @@ private function consumeBlock(): string
272
273
$ output .= $ subLexer ->preLexComponents ($ blockContents );
273
274
274
275
$ this ->consume ($ closingTag );
275
- $ output .= " {% endblock %} " ;
276
+ $ output .= ' {% endblock %} ' ;
276
277
277
278
return $ output ;
278
279
}
@@ -284,4 +285,3 @@ private function doesStringEventuallyExist(string $needle): bool
284
285
return str_contains ($ remainingString , $ needle );
285
286
}
286
287
}
287
-
0 commit comments