22
33namespace TwigCS ;
44
5+ use \Exception ;
6+ use \Traversable ;
57use Twig \Environment ;
68use Twig \Error \Error ;
79use Twig \Source ;
1214use TwigCS \Sniff \PostParserSniffInterface ;
1315use TwigCS \Sniff \PreParserSniffInterface ;
1416use TwigCS \Sniff \SniffInterface ;
15- use TwigCS \Token \TokenizerInterface ;
17+ use TwigCS \Token \Tokenizer ;
1618
1719/**
1820 * Linter is the main class and will process twig files against a set of rules.
@@ -30,17 +32,18 @@ class Linter
3032 protected $ sniffsExtension ;
3133
3234 /**
33- * @var TokenizerInterface
35+ * @var Tokenizer
3436 */
3537 protected $ tokenizer ;
3638
3739 /**
38- * @param Environment $env
39- * @param TokenizerInterface $tokenizer
40+ * @param Environment $env
41+ * @param Tokenizer $tokenizer
4042 */
41- public function __construct (Environment $ env , TokenizerInterface $ tokenizer )
43+ public function __construct (Environment $ env , Tokenizer $ tokenizer )
4244 {
4345 $ this ->env = $ env ;
46+
4447 $ this ->sniffsExtension = $ this ->env ->getExtension ('TwigCS\Extension\SniffsExtension ' );
4548 $ this ->tokenizer = $ tokenizer ;
4649 }
@@ -52,15 +55,17 @@ public function __construct(Environment $env, TokenizerInterface $tokenizer)
5255 * @param Ruleset $ruleset Set of rules to check.
5356 *
5457 * @return Report an object with all violations and stats.
58+ *
59+ * @throws Exception
5560 */
5661 public function run ($ files , Ruleset $ ruleset )
5762 {
58- if (!is_array ($ files ) && !$ files instanceof \ Traversable) {
63+ if (!is_array ($ files ) && !$ files instanceof Traversable) {
5964 $ files = [$ files ];
6065 }
6166
6267 if (empty ($ files )) {
63- throw new \ Exception ('No files to process, provide at least one file to be linted ' );
68+ throw new Exception ('No files to process, provide at least one file to be linted ' );
6469 }
6570
6671 // setUp
@@ -70,8 +75,8 @@ public function run($files, Ruleset $ruleset)
7075 $ sniffViolation = new SniffViolation (
7176 SniffInterface::MESSAGE_TYPE_NOTICE ,
7277 $ msg ,
73- '' ,
74- ''
78+ null ,
79+ null
7580 );
7681
7782 $ report ->addMessage ($ sniffViolation );
@@ -139,11 +144,11 @@ public function processTemplate($file, $ruleset, $report)
139144 // Tokenizer.
140145 try {
141146 $ stream = $ this ->tokenizer ->tokenize ($ twigSource );
142- } catch (\ Exception $ e ) {
147+ } catch (Exception $ e ) {
143148 $ sniffViolation = new SniffViolation (
144149 SniffInterface::MESSAGE_TYPE_ERROR ,
145- sprintf ('Unable to tokenize file "%s" ' , ( string ) $ file ),
146- '' ,
150+ sprintf ('Unable to tokenize file ' ),
151+ null ,
147152 (string ) $ file
148153 );
149154
0 commit comments