@@ -31,14 +31,14 @@ public function __construct(int $startingLine = 1)
3131 public function preLexComponents (string $ input ): string
3232 {
3333 $ this ->input = $ input ;
34- $ this ->length = strlen ($ input );
34+ $ this ->length = \ strlen ($ input );
3535 $ output = '' ;
3636
3737 while ($ this ->position < $ this ->length ) {
3838 if ($ this ->consume ('<t: ' )) {
3939 $ componentName = $ this ->consumeComponentName ();
4040
41- if ($ componentName === ' block ' ) {
41+ if (' block ' === $ componentName ) {
4242 $ output .= $ this ->consumeBlock ();
4343
4444 continue ;
@@ -51,7 +51,7 @@ public function preLexComponents(string $input): string
5151 $ this ->currentComponents [] = $ componentName ;
5252 }
5353
54- $ output .= "{% component {$ componentName }" . ($ attributes ? " with { {$ attributes } } " : '' ) . " %} " ;
54+ $ output .= "{% component {$ componentName }" . ($ attributes ? " with { {$ attributes } } " : '' ). ' %} ' ;
5555 if ($ isSelfClosing ) {
5656 $ output .= '{% endcomponent %} ' ;
5757 }
@@ -70,14 +70,14 @@ public function preLexComponents(string $input): string
7070 throw new \RuntimeException ("Expected closing tag '</t: {$ lastComponent }>' but found '</t: {$ closingComponentName }>' at line {$ this ->line }" );
7171 }
7272
73- $ output .= " {% endcomponent %} " ;
73+ $ output .= ' {% endcomponent %} ' ;
7474
7575 continue ;
7676 }
7777
7878 $ char = $ this ->consumeChar ();
79- if ($ char === "\n" ) {
80- $ this ->line ++ ;
79+ if ("\n" === $ char ) {
80+ ++ $ this ->line ;
8181 }
8282 $ output .= $ char ;
8383 }
@@ -89,7 +89,7 @@ private function consumeComponentName(): string
8989 {
9090 $ start = $ this ->position ;
9191 while ($ this ->position < $ this ->length && preg_match ('/[A-Za-z0-9_]/ ' , $ this ->input [$ this ->position ])) {
92- $ this ->position ++ ;
92+ ++ $ this ->position ;
9393 }
9494 $ componentName = substr ($ this ->input , $ start , $ this ->position - $ start );
9595
@@ -122,7 +122,7 @@ private function consumeAttributes(): string
122122
123123 // <t:component someProp> -> someProp: true
124124 if (!$ this ->check ('= ' )) {
125- $ attributes [] = sprintf (" %s: true " , $ key );
125+ $ attributes [] = sprintf (' %s: true ' , $ key );
126126 $ this ->consumeWhitespace ();
127127 continue ;
128128 }
@@ -144,7 +144,7 @@ private function consumeAttributes(): string
144144 $ this ->expectAndConsumeChar ($ quote );
145145
146146 if ($ isAttributeDynamic ) {
147- $ attributes [] = sprintf (" %s: %s " , $ key , $ attributeValue );
147+ $ attributes [] = sprintf (' %s: %s ' , $ key , $ attributeValue );
148148 } else {
149149 $ attributes [] = sprintf ("%s: '%s' " , $ key , str_replace ("' " , "\' " , $ attributeValue ));
150150 }
@@ -157,8 +157,9 @@ private function consumeAttributes(): string
157157
158158 private function consume (string $ string ): bool
159159 {
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+
162163 return true ;
163164 }
164165
@@ -168,34 +169,34 @@ private function consume(string $string): bool
168169 private function consumeChar ($ validChars = null ): string
169170 {
170171 if ($ this ->position >= $ this ->length ) {
171- throw new \RuntimeException (" Unexpected end of input " );
172+ throw new \RuntimeException (' Unexpected end of input ' );
172173 }
173174
174175 $ char = $ this ->input [$ this ->position ];
175176
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 }" );
178179 }
179180
180- $ this ->position ++ ;
181+ ++ $ this ->position ;
181182
182183 return $ char ;
183184 }
184185
185186 private function consumeUntil (string $ endString ): string
186187 {
187188 $ start = $ this ->position ;
188- $ endCharLength = strlen ($ endString );
189+ $ endCharLength = \ strlen ($ endString );
189190
190191 while ($ this ->position < $ this ->length ) {
191192 if (substr ($ this ->input , $ this ->position , $ endCharLength ) === $ endString ) {
192193 break ;
193194 }
194195
195- if ($ this ->input [$ this ->position ] === "\n" ) {
196- $ this ->line ++ ;
196+ if ("\n" === $ this ->input [$ this ->position ]) {
197+ ++ $ this ->line ;
197198 }
198- $ this ->position ++ ;
199+ ++ $ this ->position ;
199200 }
200201
201202 return substr ($ this ->input , $ start , $ this ->position - $ start );
@@ -204,10 +205,10 @@ private function consumeUntil(string $endString): string
204205 private function consumeWhitespace (): void
205206 {
206207 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 ;
209210 }
210- $ this ->position ++ ;
211+ ++ $ this ->position ;
211212 }
212213 }
213214
@@ -216,24 +217,24 @@ private function consumeWhitespace(): void
216217 */
217218 private function expectAndConsumeChar (string $ char ): void
218219 {
219- if (strlen ( $ char ) !== 1 ) {
220+ if (1 !== \strlen ( $ char ) ) {
220221 throw new \InvalidArgumentException ('Expected a single character ' );
221222 }
222223
223224 if ($ this ->position >= $ this ->length || $ this ->input [$ this ->position ] !== $ char ) {
224225 throw new \RuntimeException ("Expected ' {$ char }' but found ' {$ this ->input [$ this ->position ]}' at line {$ this ->line }" );
225226 }
226- $ this ->position ++ ;
227+ ++ $ this ->position ;
227228 }
228229
229230 private function check (string $ chars ): bool
230231 {
231- $ charsLength = strlen ($ chars );
232+ $ charsLength = \ strlen ($ chars );
232233 if ($ this ->position + $ charsLength > $ this ->length ) {
233234 return false ;
234235 }
235236
236- for ($ i = 0 ; $ i < $ charsLength ; $ i ++ ) {
237+ for ($ i = 0 ; $ i < $ charsLength ; ++ $ i ) {
237238 if ($ this ->input [$ this ->position + $ i ] !== $ chars [$ i ]) {
238239 return false ;
239240 }
@@ -249,8 +250,8 @@ private function consumeBlock(): string
249250
250251 $ blockName = '' ;
251252 foreach (explode (', ' , $ attributes ) as $ attr ) {
252- list ( $ key , $ value) = explode (': ' , $ attr );
253- if ($ key === ' name ' ) {
253+ [ $ key , $ value] = explode (': ' , $ attr );
254+ if (' name ' === $ key ) {
254255 $ blockName = trim ($ value , "' " );
255256 break ;
256257 }
@@ -262,7 +263,7 @@ private function consumeBlock(): string
262263
263264 $ output = "{% block {$ blockName } %} " ;
264265
265- $ closingTag = " </t:block> " ;
266+ $ closingTag = ' </t:block> ' ;
266267 if (!$ this ->doesStringEventuallyExist ($ closingTag )) {
267268 throw new \RuntimeException ("Expected closing tag ' {$ closingTag }' for block ' {$ blockName }' at line {$ this ->line }" );
268269 }
@@ -272,7 +273,7 @@ private function consumeBlock(): string
272273 $ output .= $ subLexer ->preLexComponents ($ blockContents );
273274
274275 $ this ->consume ($ closingTag );
275- $ output .= " {% endblock %} " ;
276+ $ output .= ' {% endblock %} ' ;
276277
277278 return $ output ;
278279 }
@@ -284,4 +285,3 @@ private function doesStringEventuallyExist(string $needle): bool
284285 return str_contains ($ remainingString , $ needle );
285286 }
286287}
287-
0 commit comments