Skip to content

Commit 13be7ac

Browse files
committed
fix PHP class inlining
1 parent 99e66e2 commit 13be7ac

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

log.txt

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ Deprecated: Return type of SymfonyTools\CodeBlockChecker\Issue\IssueCollection::
4141
[PHP syntax] Syntax error, unexpected EOF, expecting '{' in file contributing/code/conventions.rst at 188
4242
[PHP syntax] Syntax error, unexpected '}', expecting ';' or '{' in file http_client.rst at 1312
4343
[Twig] Unknown "price" filter. in file templating/twig_extension.rst at 23
44-
[PHP syntax] Syntax error, unexpected T_NAMESPACE in file controller/upload_file.rst at 330
4544
[PHP syntax] Syntax error, unexpected ':' in file components/serializer.rst at 471
46-
[PHP syntax] Syntax error, unexpected T_VARIABLE in file components/serializer.rst at 1116
47-
[PHP syntax] Syntax error, unexpected '}', expecting EOF in file components/serializer.rst at 1124
4845
[PHP syntax] Syntax error, unexpected T_VARIABLE, expecting ')' in file components/cache/adapters/doctrine_adapter.rst at 26
4946
[PHP syntax] Syntax error, unexpected ',' in file components/cache/adapters/doctrine_adapter.rst at 29
5047
[PHP syntax] Syntax error, unexpected ')' in file components/cache/adapters/doctrine_adapter.rst at 35
@@ -68,7 +65,7 @@ Deprecated: Return type of SymfonyTools\CodeBlockChecker\Issue\IssueCollection::
6865
[PHP syntax] Syntax error, unexpected T_DOUBLE_ARROW, expecting ',' or ']' or ')' in file components/config/definition.rst at 302
6966
[PHP syntax] Syntax error, unexpected T_DOUBLE_ARROW, expecting ',' or ']' or ')' in file components/config/definition.rst at 377
7067
[PHP syntax] Syntax error, unexpected T_DOUBLE_ARROW, expecting ',' or ']' or ')' in file components/config/definition.rst at 382
71-
[PHP syntax] Syntax error, unexpected '}', expecting ';' or '{' in file components/filesystem.rst at 218
68+
[PHP syntax] Syntax error, unexpected '}', expecting ';' or '{' in file components/filesystem.rst at 219
7269
[Yaml syntax] Unable to parse at line 1 (near "|"). in file components/yaml/yaml_format.rst at 86
7370
[Yaml syntax] Unable to parse at line 1 (near ">"). in file components/yaml/yaml_format.rst at 95
7471
[PHP syntax] Syntax error, unexpected EOF in file components/dependency_injection/compilation.rst at 155
@@ -111,7 +108,7 @@ Deprecated: Return type of SymfonyTools\CodeBlockChecker\Issue\IssueCollection::
111108
[PHP syntax] Syntax error, unexpected T_DOUBLE_ARROW in file reference/forms/types/dateinterval.rst at 299
112109
[PHP syntax] Syntax error, unexpected ',' in file reference/forms/types/dateinterval.rst at 299
113110
[PHP syntax] Syntax error, unexpected ',' in file reference/forms/types/dateinterval.rst at 302
114-
[PHP syntax] Syntax error, unexpected T_ELLIPSIS in file reference/forms/types/file.rst at 40
111+
[PHP syntax] Syntax error, unexpected T_ELLIPSIS in file reference/forms/types/file.rst at 41
115112
[PHP syntax] Syntax error, unexpected T_DOUBLE_ARROW in file reference/forms/types/birthday.rst at 1
116113
[PHP syntax] Syntax error, unexpected EOF in file reference/forms/types/birthday.rst at 3
117114
[PHP syntax] Syntax error, unexpected T_DOUBLE_ARROW in file reference/forms/types/choice.rst at 1
@@ -135,16 +132,15 @@ Deprecated: Return type of SymfonyTools\CodeBlockChecker\Issue\IssueCollection::
135132
[Twig] Unknown "transchoice" tag. in file reference/twig_reference.rst at 578
136133
[Twig] Unknown "trans_default_domain" tag. in file reference/twig_reference.rst at 597
137134
[Twig] Unknown "stopwatch" tag. in file reference/twig_reference.rst at 611
138-
[PHP syntax] Syntax error, unexpected T_AS, expecting ';' or '{' in file validation/raw_values.rst at 12
139135
[PHP syntax] Syntax error, unexpected EOF in file bundles/configuration.rst at 142
140136
[PHP syntax] Syntax error, unexpected EOF in file bundles/configuration.rst at 164
141137
[PHP syntax] Syntax error, unexpected T_PUBLIC in file bundles/extension.rst at 122
142-
[PHP syntax] Syntax error, unexpected T_PUBLIC, expecting ';' or '{' in file create_framework/http_kernel_controller_resolver.rst at 109
143-
[PHP syntax] Syntax error, unexpected '}', expecting ';' or '{' in file create_framework/http_kernel_controller_resolver.rst at 110
144-
[PHP syntax] Syntax error, unexpected '}', expecting ';' or '{' in file create_framework/http_kernel_controller_resolver.rst at 116
145-
[PHP syntax] Syntax error, unexpected T_PUBLIC, expecting ';' or '{' in file create_framework/http_kernel_controller_resolver.rst at 123
146-
[PHP syntax] Syntax error, unexpected '}', expecting ';' or '{' in file create_framework/http_kernel_controller_resolver.rst at 124
147-
[PHP syntax] Syntax error, unexpected '}', expecting ';' or '{' in file create_framework/http_kernel_controller_resolver.rst at 129
138+
[PHP syntax] Syntax error, unexpected T_PUBLIC, expecting ';' or '{' in file create_framework/http_kernel_controller_resolver.rst at 110
139+
[PHP syntax] Syntax error, unexpected '}', expecting ';' or '{' in file create_framework/http_kernel_controller_resolver.rst at 111
140+
[PHP syntax] Syntax error, unexpected '}', expecting ';' or '{' in file create_framework/http_kernel_controller_resolver.rst at 117
141+
[PHP syntax] Syntax error, unexpected T_PUBLIC, expecting ';' or '{' in file create_framework/http_kernel_controller_resolver.rst at 124
142+
[PHP syntax] Syntax error, unexpected '}', expecting ';' or '{' in file create_framework/http_kernel_controller_resolver.rst at 125
143+
[PHP syntax] Syntax error, unexpected '}', expecting ';' or '{' in file create_framework/http_kernel_controller_resolver.rst at 130
148144

149-
[ERROR] Build completed with 134 errors
145+
[ERROR] Build completed with 130 errors
150146

src/Service/CodeValidator/PhpValidator.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@ private function getParser(): Parser
4141
private function getContents(CodeNode $node, &$linesPrepended = null): string
4242
{
4343
$contents = $node->getValue();
44-
if (!preg_match('#(class|interface) [a-zA-Z]+#s', $contents) && preg_match('#(public|protected|private)( static)? (\$[a-z]+|function)#s', $contents)) {
45-
$contents = 'class Foobar {'.$contents.'}';
44+
if (
45+
!preg_match('#(class|interface) [a-zA-Z]+#s', $contents)
46+
&& !preg_match('#= new class#s', $contents)
47+
&& preg_match('#(public|protected|private)( static)? (\$[a-z]+|function).*#s', $contents, $matches)
48+
) {
49+
// keep "uses" and other code before the class definition
50+
$contents = substr($contents, 0, strpos($contents, $matches[1])).PHP_EOL.'class Foobar {'.$matches[0].'}';
4651
}
4752

4853
// Allow us to use "..." as a placeholder

0 commit comments

Comments
 (0)