Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TwigStan tweaks #99

Merged
merged 4 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

5 changes: 3 additions & 2 deletions src/Controller/ComposerAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Attribute\Cache;
Expand All @@ -21,9 +22,9 @@ final class ComposerAction extends AbstractController
* Displays the composer.json file.
*/
#[Route(path: '/composer', name: self::class)]
public function __invoke(): Response
public function __invoke(Filesystem $filesystem): Response
{
$composer = file_get_contents(__DIR__.'/../../composer.json');
$composer = $filesystem->readFile(__DIR__.'/../../composer.json');

return $this->render(self::class.'.html.twig', ['composer' => $composer]);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Controller/HomeAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Attribute\Cache;
Expand All @@ -22,9 +23,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(RouterInterface $router, Filesystem $filesystem): Response
{
$readme = file_get_contents(__DIR__.'/../../README.md');
$readme = $filesystem->readFile(__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.