Skip to content

Commit 28fd38b

Browse files
author
matheo
committed
fix php-cs-fixer
1 parent c658586 commit 28fd38b

File tree

3 files changed

+38
-38
lines changed

3 files changed

+38
-38
lines changed

src/TwigComponent/src/Twig/ComponentLexer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ComponentLexer extends Lexer
3434
public const BLOCK_TAGS_CLOSE = '/<\s*\/\s*t:block\s*>/';
3535
public const ATTRIBUTE_BAG_REGEX = '/(?:^|\s+)\{\{\s*(attributes(?:.+?(?<!\s))?)\s*\}\}/x';
3636
public const ATTRIBUTE_KEY_VALUE_REGEX = '/(?<attribute>[\w\-:.@]+)(=(?<value>(\"[^\"]+\"|\\\'[^\\\']+\\\'|[^\s>]+)))?/x';
37-
37+
3838
public function tokenize(Source $source): TokenStream
3939
{
4040
$preLexer = new TwigPreLexer();

src/TwigComponent/src/Twig/TwigPreLexer.php

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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-

src/TwigComponent/tests/Unit/TwigPreLexerTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function getLexTests(): iterable
2929
{
3030
yield 'simple_component' => [
3131
'<t:foo />',
32-
"{% component foo %}{% endcomponent %}",
32+
'{% component foo %}{% endcomponent %}',
3333
];
3434

3535
yield 'component_with_attributes' => [
@@ -39,27 +39,27 @@ public function getLexTests(): iterable
3939

4040
yield 'component_with_dynamic_attributes' => [
4141
'<t:foo dynamic="{{ dynamicVar }}" :otherDynamic="anotherVar" />',
42-
"{% component foo with { dynamic: dynamicVar, otherDynamic: anotherVar } %}{% endcomponent %}",
42+
'{% component foo with { dynamic: dynamicVar, otherDynamic: anotherVar } %}{% endcomponent %}',
4343
];
4444

4545
yield 'component_with_closing_tag' => [
4646
'<t:foo></t:foo>',
47-
"{% component foo %}{% endcomponent %}",
47+
'{% component foo %}{% endcomponent %}',
4848
];
4949

5050
yield 'component_with_block' => [
5151
'<t:foo><t:block name="foo_block">Foo</t:block></t:foo>',
52-
"{% component foo %}{% block foo_block %}Foo{% endblock %}{% endcomponent %}",
52+
'{% component foo %}{% block foo_block %}Foo{% endblock %}{% endcomponent %}',
5353
];
5454

5555
yield 'component_with_embedded_component_inside_block' => [
5656
'<t:foo><t:block name="foo_block"><t:bar /></t:block></t:foo>',
57-
"{% component foo %}{% block foo_block %}{% component bar %}{% endcomponent %}{% endblock %}{% endcomponent %}",
57+
'{% component foo %}{% block foo_block %}{% component bar %}{% endcomponent %}{% endblock %}{% endcomponent %}',
5858
];
5959

6060
yield 'attribute_with_no_value' => [
6161
'<t:foo bar />',
62-
"{% component foo with { bar: true } %}{% endcomponent %}",
62+
'{% component foo with { bar: true } %}{% endcomponent %}',
6363
];
6464
}
6565
}

0 commit comments

Comments
 (0)