diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 1cc1ee2..6d69fca 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -108,7 +108,7 @@ jobs: - name: Set up PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.0 + php-version: 8.2 coverage: none tools: composer-normalize diff --git a/README.md b/README.md index 6773d22..ba3d254 100644 --- a/README.md +++ b/README.md @@ -20,5 +20,5 @@ $ php ./code-block-checker.php verify:docs /path/to/docs cache.rst controller.rs This project is considered **an internal tool** and therefore, you **shouldn't use this project in your application**. Unlike the rest of the Symfony projects, this repository doesn't provide any support and it doesn't -guarantee backward compatibility either. Any or the entire project can change, +guarantee backward compatibility. Any file or the entire project can change, or even disappear, at any moment without prior notice. diff --git a/composer.json b/composer.json index a0633cf..cc461a1 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "symfony-tools/code-block-checker", - "type": "project", "license": "proprietary", + "type": "project", "require": { "php": ">=8.0", "ext-ctype": "*", @@ -18,18 +18,35 @@ "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" }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.4.1", + "phpunit/phpunit": "^9.3.10" + }, "replace": { "symfony/polyfill-ctype": "*", "symfony/polyfill-iconv": "*" }, - "require-dev": { - "bamarni/composer-bin-plugin": "^1.4.1", - "phpunit/phpunit": "^9.3.10" + "minimum-stability": "dev", + "prefer-stable": true, + "autoload": { + "psr-4": { + "SymfonyTools\\CodeBlockChecker\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "SymfonyTools\\CodeBlockChecker\\Tests\\": "tests/" + } }, "config": { + "allow-plugins": { + "bamarni/composer-bin-plugin": true, + "symfony/flex": true + }, "optimize-autoloader": true, "preferred-install": { "*": "dist" @@ -40,17 +57,5 @@ "symfony": { "allow-contrib": false } - }, - "autoload": { - "psr-4": { - "SymfonyTools\\CodeBlockChecker\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - "SymfonyTools\\CodeBlockChecker\\Tests\\": "tests/" - } - }, - "minimum-stability": "dev", - "prefer-stable": true + } } diff --git a/src/Issue/IssueCollection.php b/src/Issue/IssueCollection.php index ffbfd89..72c0ea1 100644 --- a/src/Issue/IssueCollection.php +++ b/src/Issue/IssueCollection.php @@ -15,32 +15,32 @@ public function addIssue(Issue $issue) $this->issues[] = $issue; } - public function current() + public function current(): Issue { return $this->issues[$this->key]; } - public function next() + public function next(): void { ++$this->key; } - public function key() + public function key(): int { return $this->key; } - public function valid() + public function valid(): bool { return isset($this->issues[$this->key()]); } - public function rewind() + public function rewind(): void { $this->key = 0; } - public function count() + public function count(): int { return count($this->issues); } diff --git a/src/Service/CodeRunner/ConfigurationRunner.php b/src/Service/CodeRunner/ConfigurationRunner.php index 3bd2e1e..e2a9f84 100644 --- a/src/Service/CodeRunner/ConfigurationRunner.php +++ b/src/Service/CodeRunner/ConfigurationRunner.php @@ -13,7 +13,7 @@ * * @author Tobias Nyholm */ -class ConfigurationRunner +class ConfigurationRunner implements Runner { /** * @param list $nodes @@ -77,7 +77,7 @@ private function getFile(CodeNode $node, array $contents): string $regex = match ($node->getLanguage()) { 'php' => '|^// ?([a-z1-9A-Z_\-/]+\.php)$|', 'yaml' => '|^# ?([a-z1-9A-Z_\-/]+\.yaml)$|', - //'xml' => '|^$|', + 'xml' => '|^$|', default => null, }; diff --git a/src/Service/CodeValidator/PhpValidator.php b/src/Service/CodeValidator/PhpValidator.php index 3a7a0a1..4476edb 100644 --- a/src/Service/CodeValidator/PhpValidator.php +++ b/src/Service/CodeValidator/PhpValidator.php @@ -41,12 +41,17 @@ 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 - $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] ?? '', 'getValue()); try { - Yaml::parse($contents, Yaml::PARSE_CUSTOM_TAGS); + Yaml::parse($contents, Yaml::PARSE_CONSTANT | Yaml::PARSE_CUSTOM_TAGS); } catch (ParseException $e) { if ('Duplicate key' === substr($e->getMessage(), 0, 13)) { return; diff --git a/src/Twig/DummyExtension.php b/src/Twig/DummyExtension.php index c9e3617..004ec5b 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 @@ -61,6 +67,16 @@ public function getFunctions() new TwigFunction('impersonation_exit_url'), new TwigFunction('workflow_transition'), new TwigFunction('t'), + new TwigFunction('mercure'), + new TwigFunction('stimulus_controller'), + new TwigFunction('stimulus_action'), + new TwigFunction('stimulus_target'), + new TwigFunction('field_name'), + new TwigFunction('field_value'), + new TwigFunction('field_label'), + new TwigFunction('field_help'), + new TwigFunction('field_errors'), + new TwigFunction('field_choices'), ]; } @@ -87,6 +103,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(), ]; } } diff --git a/symfony.lock b/symfony.lock index bdf3d94..d40c692 100644 --- a/symfony.lock +++ b/symfony.lock @@ -240,6 +240,9 @@ "symfony/polyfill-php80": { "version": "v1.22.1" }, + "symfony/polyfill-php81": { + "version": "v1.23.0" + }, "symfony/process": { "version": "v5.2.4" }, @@ -263,6 +266,9 @@ "symfony/string": { "version": "v5.2.6" }, + "symfony/translation-contracts": { + "version": "v1.1.10" + }, "symfony/var-dumper": { "version": "v5.2.6" },