Skip to content

Commit

Permalink
TwigStan tweaks (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruudk authored and COil committed Oct 21, 2024
1 parent d7211df commit dfcce5d
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 52 deletions.
16 changes: 9 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Controller/ComposerAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class ComposerAction extends AbstractController
#[Route(path: '/composer', name: self::class)]
public function __invoke(): Response
{
$composer = file_get_contents(__DIR__.'/../../composer.json');
$composer = (string) file_get_contents(__DIR__.'/../../composer.json');

return $this->render(self::class.'.html.twig', ['composer' => $composer]);
}
Expand Down
5 changes: 2 additions & 3 deletions src/Controller/HomeAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,9 +21,9 @@ 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');
$readme = (string) file_get_contents(__DIR__.'/../../README.md');

return $this->render(self::class.'.html.twig', ['readme' => $readme]);
}
Expand Down
12 changes: 0 additions & 12 deletions src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}
}
2 changes: 0 additions & 2 deletions templates/App/Controller/ComposerAction.html.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{% extends 'base.html.twig' %}

{% types { composer: 'string' } %}

{% block body %}
<div class="sub-heading">
<h2>Composer ⚡</h2>
Expand Down
5 changes: 0 additions & 5 deletions templates/App/Controller/FormAction.html.twig
Original file line number Diff line number Diff line change
@@ -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 %}
Expand Down
2 changes: 0 additions & 2 deletions templates/App/Controller/HomeAction.html.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{% extends 'base.html.twig' %}

{% types { readme: 'string' } %}

{% block body %}
<p>This page displays the <a att="" target="_blank" href="https://github.com/strangebuzz/MicroSymfony/blob/main/README.md">
README.md</a> file of the GitHub repository.</p>
Expand Down
4 changes: 2 additions & 2 deletions twig-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
18 changes: 4 additions & 14 deletions twigstan.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
8 changes: 4 additions & 4 deletions vendor-bin/php-cs-fixer/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dfcce5d

Please sign in to comment.