From c4aee4bf61f9d3e9984d7098ddbf186d286b0c4f Mon Sep 17 00:00:00 2001 From: Jules Pietri Date: Thu, 9 Jun 2022 22:22:43 +0200 Subject: [PATCH 1/3] fix PHP class inlining --- src/Service/CodeValidator/PhpValidator.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Service/CodeValidator/PhpValidator.php b/src/Service/CodeValidator/PhpValidator.php index 3a7a0a1..0217a55 100644 --- a/src/Service/CodeValidator/PhpValidator.php +++ b/src/Service/CodeValidator/PhpValidator.php @@ -41,8 +41,13 @@ private function getParser(): Parser private function getContents(CodeNode $node, &$linesPrepended = null): string { $contents = $node->getValue(); - if (!preg_match('#(class|interface) [a-zA-Z]+#s', $contents) && preg_match('#(public|protected|private)( static)? (\$[a-z]+|function)#s', $contents)) { - $contents = 'class Foobar {'.$contents.'}'; + if ( + !preg_match('#(class|interface) [a-zA-Z]+#s', $contents) + && !preg_match('#= new class#s', $contents) + && preg_match('#(public|protected|private)( static)? (\$[a-z]+|function).*#s', $contents, $matches) + ) { + // keep "uses" and other code before the class definition + $contents = substr($contents, 0, strpos($contents, $matches[1])).PHP_EOL.'class Foobar {'.$matches[0].'}'; } // Allow us to use "..." as a placeholder From 2c7e9c935f4b4894a61395cc84adc5fff53db0d2 Mon Sep 17 00:00:00 2001 From: Jules Pietri Date: Thu, 9 Jun 2022 22:33:06 +0200 Subject: [PATCH 2/3] fix TwigValidator with missing tokens/filters/tests --- composer.json | 1 + src/Twig/DummyExtension.php | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/composer.json b/composer.json index 0bac3b1..8e9dd91 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,7 @@ "symfony/flex": "^1.3.1", "symfony/framework-bundle": "^5.2", "symfony/process": "^5.2", + "symfony/twig-bridge": "^5.4", "symfony/yaml": "^5.2", "twig/twig": "^3.3" }, diff --git a/src/Twig/DummyExtension.php b/src/Twig/DummyExtension.php index 0914db5..18c4d5c 100644 --- a/src/Twig/DummyExtension.php +++ b/src/Twig/DummyExtension.php @@ -2,9 +2,15 @@ namespace SymfonyTools\CodeBlockChecker\Twig; +use Symfony\Bridge\Twig\TokenParser\DumpTokenParser; +use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser; +use Symfony\Bridge\Twig\TokenParser\StopwatchTokenParser; +use Symfony\Bridge\Twig\TokenParser\TransDefaultDomainTokenParser; +use Symfony\Bridge\Twig\TokenParser\TransTokenParser; use Twig\Extension\AbstractExtension; use Twig\TwigFilter; use Twig\TwigFunction; +use Twig\TwigTest; /** * This extension will contain filters and functions that exists in Symfony. This @@ -91,6 +97,27 @@ public function getFilters() new TwigFilter('markdown_to_html'), new TwigFilter('inky_to_html'), new TwigFilter('serialize'), + new TwigFilter('price'), + new TwigFilter('greet'), + ]; + } + + public function getTests() + { + return [ + new TwigTest('rootform'), + new TwigTest('selectedchoice'), + ]; + } + + public function getTokenParsers() + { + return [ + new DumpTokenParser(), + new FormThemeTokenParser(), + new StopwatchTokenParser(false), + new TransTokenParser(), + new TransDefaultDomainTokenParser(), ]; } } From 2f591b465cb7b9e25c7a07681e11382b2995cef4 Mon Sep 17 00:00:00 2001 From: Jules Pietri Date: Sat, 11 Jun 2022 10:40:36 +0200 Subject: [PATCH 3/3] fix replacing ellipsis --- src/Service/CodeValidator/PhpValidator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Service/CodeValidator/PhpValidator.php b/src/Service/CodeValidator/PhpValidator.php index 0217a55..4476edb 100644 --- a/src/Service/CodeValidator/PhpValidator.php +++ b/src/Service/CodeValidator/PhpValidator.php @@ -51,7 +51,7 @@ private function getContents(CodeNode $node, &$linesPrepended = null): string } // Allow us to use "..." as a placeholder - $contents = str_replace(['...,', '...)', '...;', '...]'], ['null,', 'null)', 'null;', 'null]'], $contents); + $contents = str_replace(['...,', '...)', '...;', '...]', '... }'], ['null,', 'null)', 'null;', 'null]', '$a = null; }'], $contents); $lines = explode("\n", $contents); if (!str_contains($lines[0] ?? '', '