From 6388a0642e5f2c33cdd2089e2b67ec9f0801e663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Thu, 14 Oct 2021 18:55:29 +0200 Subject: [PATCH 1/9] feat: add Mercure Twig helper (#41) --- src/Twig/DummyExtension.php | 1 + symfony.lock | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/Twig/DummyExtension.php b/src/Twig/DummyExtension.php index c9e3617..9a34106 100644 --- a/src/Twig/DummyExtension.php +++ b/src/Twig/DummyExtension.php @@ -61,6 +61,7 @@ public function getFunctions() new TwigFunction('impersonation_exit_url'), new TwigFunction('workflow_transition'), new TwigFunction('t'), + new TwigFunction('mercure'), ]; } 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" }, From 2fe211a5de8bc0e942a3131581c00e51361e80ff Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Thu, 23 Dec 2021 20:20:59 -0500 Subject: [PATCH 2/9] Adding 3 Stimulus Twig functions --- composer.json | 34 +++++++++++++++++----------------- src/Twig/DummyExtension.php | 3 +++ 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index a0633cf..0bac3b1 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": "*", @@ -21,13 +21,25 @@ "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": { "optimize-autoloader": true, @@ -40,17 +52,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/Twig/DummyExtension.php b/src/Twig/DummyExtension.php index 9a34106..0914db5 100644 --- a/src/Twig/DummyExtension.php +++ b/src/Twig/DummyExtension.php @@ -62,6 +62,9 @@ public function getFunctions() new TwigFunction('workflow_transition'), new TwigFunction('t'), new TwigFunction('mercure'), + new TwigFunction('stimulus_controller'), + new TwigFunction('stimulus_action'), + new TwigFunction('stimulus_target'), ]; } From f750edd5b419ec8e21ddc5eb302dc8c1b2565db6 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Fri, 10 Jun 2022 20:14:13 +0200 Subject: [PATCH 3/9] Fixed language in readme (#45) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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. From 7384502cc027bc50c08cabb37fa169d72012db2a Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 12 Jun 2022 19:39:04 +0200 Subject: [PATCH 4/9] Fixed PHP deprecation (#47) * Fixed PHP deprecation * Update src/Issue/IssueCollection.php Co-authored-by: Alexander M. Turek * Update src/Issue/IssueCollection.php Co-authored-by: Alexander M. Turek Co-authored-by: Alexander M. Turek --- src/Issue/IssueCollection.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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); } From b42940b301d40f07ba1846adb7a5f96362df251d Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 13 Jun 2022 12:48:01 +0200 Subject: [PATCH 5/9] Enable XML and run code examples (#46) * Enable XML and run code examples * normalize --- composer.json | 4 ++++ src/Service/CodeRunner/ConfigurationRunner.php | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 0bac3b1..b74c72d 100644 --- a/composer.json +++ b/composer.json @@ -42,6 +42,10 @@ } }, "config": { + "allow-plugins": { + "bamarni/composer-bin-plugin": true, + "symfony/flex": true + }, "optimize-autoloader": true, "preferred-install": { "*": "dist" 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, }; From 7934f6de32672a15f77a3b01a50b5008baf30af9 Mon Sep 17 00:00:00 2001 From: Jules Pietri Date: Mon, 13 Jun 2022 12:48:40 +0200 Subject: [PATCH 6/9] Bunch of fixes for PHP and Twig parsing (#44) * fix PHP class inlining * fix TwigValidator with missing tokens/filters/tests * fix replacing ellipsis --- composer.json | 1 + src/Service/CodeValidator/PhpValidator.php | 11 ++++++--- src/Twig/DummyExtension.php | 27 ++++++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index b74c72d..cc461a1 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/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] ?? '', ' Date: Fri, 14 Apr 2023 08:34:51 +0200 Subject: [PATCH 7/9] Add missing Twig Form field helpers (#48) --- src/Twig/DummyExtension.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Twig/DummyExtension.php b/src/Twig/DummyExtension.php index 18c4d5c..004ec5b 100644 --- a/src/Twig/DummyExtension.php +++ b/src/Twig/DummyExtension.php @@ -71,6 +71,12 @@ public function getFunctions() 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'), ]; } From da3c6bf407cf330ec7db46c0c84f9f0feb0c7a72 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 19 Aug 2023 07:26:20 +0200 Subject: [PATCH 8/9] use PHP 8.2 to run composer normalize (#50) --- .github/workflows/static.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From e714f03368447b1da808b696882b42cd03368516 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20P=C3=A9lisset?= Date: Sun, 20 Aug 2023 20:02:50 +0200 Subject: [PATCH 9/9] Use the same Parser flags as in Symfony (#49) --- src/Service/CodeValidator/YamlValidator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Service/CodeValidator/YamlValidator.php b/src/Service/CodeValidator/YamlValidator.php index d98183d..890e760 100644 --- a/src/Service/CodeValidator/YamlValidator.php +++ b/src/Service/CodeValidator/YamlValidator.php @@ -19,7 +19,7 @@ public function validate(CodeNode $node, IssueCollection $issues): void // Allow us to use "..." as a placeholder $contents = str_replace('...', 'null', $node->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;