Skip to content

Commit fe9837d

Browse files
📦 Remove not used functionnality
1 parent 584335e commit fe9837d

17 files changed

+79
-635
lines changed

TwigCS/Command/TwigCSCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8181
'workingDirectory' => $currentDir,
8282
]);
8383

84-
$twig = new StubbedEnvironment(new ArrayLoader(), ['stub_tags' => $config->get('stub')]);
84+
$twig = new StubbedEnvironment(new ArrayLoader());
8585
$linter = new Linter($twig, new Tokenizer($twig));
8686
$factory = new RulesetFactory();
8787
$reporter = new TextFormatter($input, $output);

TwigCS/Environment/StubbedEnvironment.php

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
use Twig\TwigFilter;
1515
use Twig\TwigFunction;
1616
use Twig\TwigTest;
17-
use TwigCS\Extension\SniffsExtension;
18-
use TwigCS\Token\TokenParser;
1917

2018
/**
2119
* Provide stubs for all filters, functions, tests and tags that are not defined in twig's core.
@@ -56,28 +54,6 @@ public function __construct(LoaderInterface $loader = null, $options = [])
5654
$this->addTokenParser(new TransChoiceTokenParser());
5755
$this->addTokenParser(new TransDefaultDomainTokenParser());
5856
$this->addTokenParser(new TransTokenParser());
59-
60-
$this->stubCallable = function () {
61-
/* This will be used as stub filter, function or test */
62-
};
63-
64-
$this->stubFilters = [];
65-
$this->stubFunctions = [];
66-
67-
if (isset($options['stub_tags'])) {
68-
foreach ($options['stub_tags'] as $tag) {
69-
$this->addTokenParser(new TokenParser($tag));
70-
}
71-
}
72-
73-
$this->stubTests = [];
74-
if (isset($options['stub_tests'])) {
75-
foreach ($options['stub_tests'] as $test) {
76-
$this->stubTests[$test] = new TwigTest('stub', $this->stubCallable);
77-
}
78-
}
79-
80-
$this->addExtension(new SniffsExtension());
8157
}
8258

8359
/**
@@ -111,19 +87,14 @@ public function getFunction($name)
11187
/**
11288
* @param string $name
11389
*
114-
* @return false|TwigTest
90+
* @return TwigTest
11591
*/
11692
public function getTest($name)
11793
{
118-
$test = parent::getTest($name);
119-
if ($test) {
120-
return $test;
121-
}
122-
123-
if (isset($this->stubTests[$name])) {
124-
return $this->stubTests[$name];
94+
if (!isset($this->stubTests[$name])) {
95+
$this->stubTests[$name] = new TwigTest('stub', $this->stubCallable);
12596
}
12697

127-
return false;
98+
return $this->stubTests[$name];
12899
}
129100
}

TwigCS/Extension/SniffsExtension.php

Lines changed: 0 additions & 64 deletions
This file was deleted.

TwigCS/Extension/SniffsNodeVisitor.php

Lines changed: 0 additions & 139 deletions
This file was deleted.

TwigCS/Linter.php

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@
77
use Twig\Environment;
88
use Twig\Error\Error;
99
use Twig\Source;
10-
use TwigCS\Extension\SniffsExtension;
1110
use TwigCS\Report\Report;
1211
use TwigCS\Report\SniffViolation;
1312
use TwigCS\Ruleset\Ruleset;
14-
use TwigCS\Sniff\PostParserSniffInterface;
15-
use TwigCS\Sniff\PreParserSniffInterface;
1613
use TwigCS\Sniff\SniffInterface;
1714
use TwigCS\Token\Tokenizer;
1815

@@ -26,11 +23,6 @@ class Linter
2623
*/
2724
protected $env;
2825

29-
/**
30-
* @var SniffsExtension
31-
*/
32-
protected $sniffsExtension;
33-
3426
/**
3527
* @var Tokenizer
3628
*/
@@ -44,7 +36,6 @@ public function __construct(Environment $env, Tokenizer $tokenizer)
4436
{
4537
$this->env = $env;
4638

47-
$this->sniffsExtension = $this->env->getExtension('TwigCS\Extension\SniffsExtension');
4839
$this->tokenizer = $tokenizer;
4940
}
5041

@@ -68,13 +59,8 @@ public function run($files, Ruleset $ruleset)
6859
throw new Exception('No files to process, provide at least one file to be linted');
6960
}
7061

71-
// setUp
7262
$report = new Report();
7363
foreach ($ruleset->getSniffs() as $sniff) {
74-
if ($sniff instanceof PostParserSniffInterface) {
75-
$this->sniffsExtension->addSniff($sniff);
76-
}
77-
7864
$sniff->enable($report);
7965
}
8066

@@ -90,10 +76,6 @@ public function run($files, Ruleset $ruleset)
9076

9177
// tearDown
9278
foreach ($ruleset->getSniffs() as $sniff) {
93-
if ($sniff instanceof PostParserSniffInterface) {
94-
$this->sniffsExtension->removeSniff($sniff);
95-
}
96-
9779
$sniff->disable();
9880
}
9981

@@ -144,8 +126,8 @@ public function processTemplate($file, $ruleset, $report)
144126
return false;
145127
}
146128

147-
/** @var PreParserSniffInterface[] $sniffs */
148-
$sniffs = $ruleset->getSniffs(SniffInterface::TYPE_PRE_PARSER);
129+
/** @var SniffInterface[] $sniffs */
130+
$sniffs = $ruleset->getSniffs();
149131
foreach ($sniffs as $sniff) {
150132
foreach ($stream as $index => $token) {
151133
$sniff->process($token, $index, $stream);

0 commit comments

Comments
 (0)