Skip to content

Latest commit

 

History

History
123 lines (88 loc) · 2.22 KB

rules_overview.md

File metadata and controls

123 lines (88 loc) · 2.22 KB

3 Rules Overview

NoTwigMissingVariableRule

Variable "%s" is used in template but missing in render() method

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

final class SomeController extends AbstractController
{
    public function __invoke()
    {
        return $this->render(__DIR__ . '/some_file.twig', [
            'non_existing_variable' => 'value',
        ]);
    }
}


use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

final class SomeController extends AbstractController
{
    public function __invoke()
    {
        return $this->render(__DIR__ . '/some_file.twig', [
            'existing_variable' => 'value',
        ]);
    }
}

👍


NoTwigRenderUnusedVariableRule

Passed "%s" variable is not used in the template

use Twig\Environment;

$environment = new Environment();
$environment->render(__DIR__ . '/some_file.twig', [
    'unused_variable' => 'value',
]);


use Twig\Environment;

$environment = new Environment();
$environment->render(__DIR__ . '/some_file.twig', [
    'used_variable' => 'value',
]);

👍


TwigCompleteCheckRule

Complete analysis of PHP code generated from Twig template

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

final class SomeController extends AbstractController
{
    public function __invoke()
    {
        return $this->render(__DIR__ . '/some_file.twig', [
            'some' => new SomeObject()
        ]);
    }
}

// some_file.twig
{{ some.non_existing_method }}


use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

final class SomeController extends AbstractController
{
    public function __invoke()
    {
        return $this->render(__DIR__ . '/some_file.twig', [
            'some' => new SomeObject()
        ]);
    }
}

// some_file.twig
{{ some.existing_method }}

👍