From 4f71ec8a1a598f63db3ffd41f09e6a782d02f5cd Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Mon, 21 Oct 2024 21:21:22 +0200 Subject: [PATCH] TwigStan tweaks (#99) --- composer.lock | 16 +++++++++------- src/Controller/HomeAction.php | 3 +-- src/Kernel.php | 12 ------------ .../App/Controller/ComposerAction.html.twig | 2 -- templates/App/Controller/FormAction.html.twig | 5 ----- templates/App/Controller/HomeAction.html.twig | 2 -- twig-loader.php | 4 ++-- twigstan.php | 18 ++++-------------- vendor-bin/php-cs-fixer/composer.lock | 8 ++++---- 9 files changed, 20 insertions(+), 50 deletions(-) diff --git a/composer.lock b/composer.lock index 6d86927..4284d7d 100644 --- a/composer.lock +++ b/composer.lock @@ -8789,12 +8789,12 @@ "source": { "type": "git", "url": "https://github.com/twigstan/twigstan.git", - "reference": "ce3ace2eee9480e68467284dcf78cf2aed957058" + "reference": "4eeeee4c0577ff71b4e498b27a05ff75d0f4d007" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigstan/twigstan/zipball/ce3ace2eee9480e68467284dcf78cf2aed957058", - "reference": "ce3ace2eee9480e68467284dcf78cf2aed957058", + "url": "https://api.github.com/repos/twigstan/twigstan/zipball/4eeeee4c0577ff71b4e498b27a05ff75d0f4d007", + "reference": "4eeeee4c0577ff71b4e498b27a05ff75d0f4d007", "shasum": "" }, "require": { @@ -8819,8 +8819,10 @@ "phpstan/extension-installer": "^1.4", "phpstan/phpstan-deprecation-rules": "^1.2", "phpstan/phpstan-strict-rules": "^1.6", - "phpunit/phpunit": "^10.5", + "phpstan/phpstan-symfony": "^1.4", + "phpunit/phpunit": "^11.4", "shipmonk/composer-dependency-analyser": "^1.7", + "symfony/form": "^7.1", "symfony/framework-bundle": "^7.1", "symfony/http-foundation": "^7.1", "symfony/http-kernel": "^7.1", @@ -8858,7 +8860,7 @@ "type": "github" } ], - "time": "2024-10-18T11:38:32+00:00" + "time": "2024-10-21T09:58:14+00:00" } ], "aliases": [], @@ -8878,6 +8880,6 @@ "ext-simplexml": "*", "ext-xml": "*" }, - "platform-dev": [], - "plugin-api-version": "2.3.0" + "platform-dev": {}, + "plugin-api-version": "2.6.0" } diff --git a/src/Controller/HomeAction.php b/src/Controller/HomeAction.php index 910f63e..805dc82 100644 --- a/src/Controller/HomeAction.php +++ b/src/Controller/HomeAction.php @@ -9,7 +9,6 @@ use Symfony\Component\HttpKernel\Attribute\AsController; use Symfony\Component\HttpKernel\Attribute\Cache; use Symfony\Component\Routing\Attribute\Route; -use Symfony\Component\Routing\RouterInterface; /** * @see StaticActionTest @@ -22,7 +21,7 @@ final class HomeAction extends AbstractController * Simple page with some content. */ #[Route(path: '/', name: self::class)] - public function __invoke(RouterInterface $router): Response + public function __invoke(): Response { $readme = file_get_contents(__DIR__.'/../../README.md'); diff --git a/src/Kernel.php b/src/Kernel.php index e5f03d4..4cf4eed 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -5,21 +5,9 @@ namespace App; use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; -use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Kernel as BaseKernel; final class Kernel extends BaseKernel { use MicroKernelTrait; - - protected function build(ContainerBuilder $container): void - { - $container->addCompilerPass(new class implements CompilerPassInterface { - public function process(ContainerBuilder $container): void - { - $container->getDefinition('twig')->setPublic(true); - } - }); - } } diff --git a/templates/App/Controller/ComposerAction.html.twig b/templates/App/Controller/ComposerAction.html.twig index 6bd033b..bc05f67 100644 --- a/templates/App/Controller/ComposerAction.html.twig +++ b/templates/App/Controller/ComposerAction.html.twig @@ -1,7 +1,5 @@ {% extends 'base.html.twig' %} -{% types { composer: 'string' } %} - {% block body %}

Composer ⚡

diff --git a/templates/App/Controller/FormAction.html.twig b/templates/App/Controller/FormAction.html.twig index 341e840..409a945 100644 --- a/templates/App/Controller/FormAction.html.twig +++ b/templates/App/Controller/FormAction.html.twig @@ -1,10 +1,5 @@ {% extends 'base.html.twig' %} -{% types { - dto: 'App\\Dto\\RegisterFormDto', - form: 'Symfony\\Component\\Form\\FormView' -} %} - {% set h2 = 'Form example' %} {% block title %}{{ h2 }} | {{ brand }}{% endblock %} diff --git a/templates/App/Controller/HomeAction.html.twig b/templates/App/Controller/HomeAction.html.twig index 58fef57..e53daee 100644 --- a/templates/App/Controller/HomeAction.html.twig +++ b/templates/App/Controller/HomeAction.html.twig @@ -1,7 +1,5 @@ {% extends 'base.html.twig' %} -{% types { readme: 'string' } %} - {% block body %}

This page displays the README.md file of the GitHub repository.

diff --git a/twig-loader.php b/twig-loader.php index de2d526..76e9de1 100644 --- a/twig-loader.php +++ b/twig-loader.php @@ -9,7 +9,7 @@ (new Dotenv())->bootEnv(__DIR__.'/.env'); -$kernel = new Kernel($_ENV['APP_ENV'], (bool) $_ENV['APP_DEBUG']); +$kernel = new Kernel('test', true); $kernel->boot(); -return $kernel->getContainer()->get('twig'); +return $kernel->getContainer()->get('test.service_container')->get('twig'); diff --git a/twigstan.php b/twigstan.php index 0928a4c..7c45286 100644 --- a/twigstan.php +++ b/twigstan.php @@ -2,23 +2,13 @@ declare(strict_types=1); -return TwigStan\Config\TwigStanConfig::configure(__DIR__) +use TwigStan\Config\TwigStanConfig; + +return TwigStanConfig::configure(__DIR__) ->reportUnmatchedIgnoredErrors(true) ->phpstanConfigurationFile(__DIR__.'/phpstan.neon') ->phpstanMemoryLimit(false) ->twigEnvironmentLoader(__DIR__.'/twig-loader.php') ->twigPaths(__DIR__.'/templates') - // ->twigPaths(__DIR__ . '/tests/EndToEnd/Types') - // ->twigExcludes('something.html.twig') - // ->phpPaths(__DIR__ . '/tests/Fixtures') - // ->phpExcludes('something.php') - // ->ignoreErrors( - // TwigStan\Error\IgnoreError::create('#SomeOther#', 'someIdentifier.someValue', __DIR__ . '/some/path.php'), - // TwigStan\Error\IgnoreError::message('#SomePattern#'), - // TwigStan\Error\IgnoreError::identifier('someIdentifier'), - // TwigStan\Error\IgnoreError::path(__DIR__ . '/some/path.php'), - // TwigStan\Error\IgnoreError::messageAndIdentifier('#SomePattern#', 'someIdentifier'), - // TwigStan\Error\IgnoreError::messageAndPath('#SomePattern#', __DIR__ . '/some/path.php'), - // TwigStan\Error\IgnoreError::identifierAndPath('someIdentifier', __DIR__ . '/some/path.php'), - // ) + ->phpPaths(__DIR__.'/src/Controller') ->create(); diff --git a/vendor-bin/php-cs-fixer/composer.lock b/vendor-bin/php-cs-fixer/composer.lock index c073d65..1eaf5b6 100644 --- a/vendor-bin/php-cs-fixer/composer.lock +++ b/vendor-bin/php-cs-fixer/composer.lock @@ -2541,10 +2541,10 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, - "platform": [], - "platform-dev": [], - "plugin-api-version": "2.3.0" + "platform": {}, + "platform-dev": {}, + "plugin-api-version": "2.6.0" }