PHP code example of friendsoftwig / twigcs

1. Go to this page and download the library: Download friendsoftwig/twigcs library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

friendsoftwig / twigcs example snippets


// ~/.twig_cs.dist.php


declare(strict_types=1);

use FriendsOfTwig\Twigcs;

return Twigcs\Config\Config::create()
    ->setName('my-config')
    ->setSeverity('warning')
    ->setReporter('json')
    ->setRuleSet(Twigcs\Ruleset\Official::class)
    ->setSpecificRuleSets([ // Every file matching the pattern will use a different ruleset.
        '*/template.html.twig' => Acme\Project\CustomRuleset::class,
    ])
;

// ~/.twig_cs.dist.php


declare(strict_types=1);

use FriendsOfTwig\Twigcs;

$finderA = Twigcs\Finder\TemplateFinder::create()->in(__DIR__.'/dirA');
$finderB = Twigcs\Finder\TemplateFinder::create()->in(__DIR__.'/dirB');

return Twigcs\Config\Config::create()
    // ...
    ->addFinder($finderA)
    ->addFinder($finderB)
    ->setName('my-config')
;



declare(strict_types=1);

use FriendsOfTwig\Twigcs;

return Twigcs\Config\Config::create()
    // ...
    ->setTemplateResolver(new Twigcs\TemplateResolver\FileResolver(__DIR__))
    ->setRuleSet(FriendsOfTwig\Twigcs\Ruleset\Official::class)
;



declare(strict_types=1);

use FriendsOfTwig\Twigcs;

return Twigcs\Config\Config::create()
    ->setFinder($finder)
    ->setTemplateResolver(new Twigcs\TemplateResolver\ChainResolver([
        new Twigcs\TemplateResolver\FileResolver(__DIR__ . '/templates'),
        new Twigcs\TemplateResolver\NamespacedResolver([
            'acme' =>  new Twigcs\TemplateResolver\FileResolver(__DIR__ . '/vendor/Acme/AcmeLib/templates')
        ]),
    ]))
;