1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Symplify |
5
|
|
|
* Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz). |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Symplify\MultiCodingStandard\PhpCsFixer\Configuration; |
9
|
|
|
|
10
|
|
|
use Symplify\MultiCodingStandard\Contract\PhpCsFixer\Configuration\OptionResolver\OptionResolverInterface; |
11
|
|
|
use Symplify\PHP7_CodeSniffer\Exception\Configuration\MissingOptionResolverException; |
12
|
|
|
|
13
|
|
|
final class ConfigurationResolver |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var OptionResolverInterface[] |
17
|
|
|
*/ |
18
|
|
|
private $optionResolvers; |
19
|
|
|
|
20
|
|
|
public function addOptionResolver(OptionResolverInterface $optionResolver) |
21
|
|
|
{ |
22
|
|
|
$this->optionResolvers[$optionResolver->getName()] = $optionResolver; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function resolve(string $name, array $source) : array |
26
|
|
|
{ |
27
|
|
|
$this->ensureResolverExists($name); |
28
|
|
|
return $this->optionResolvers[$name]->resolve($source); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
private function ensureResolverExists(string $name) |
32
|
|
|
{ |
33
|
|
|
if (!isset($this->optionResolvers[$name])) { |
34
|
|
|
throw new MissingOptionResolverException(sprintf( |
35
|
|
|
'Resolver for "%s" value is not registered. '. |
36
|
|
|
'Add it via $configurationResolver->addOptionResolver(...).', |
37
|
|
|
$name |
38
|
|
|
)); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
// /** |
43
|
|
|
// * @var FixerFileSystem |
44
|
|
|
// */ |
45
|
|
|
// private $fixerFileSystem; |
46
|
|
|
|
47
|
|
|
// /** |
|
|
|
|
48
|
|
|
// * @var FixerFactory |
49
|
|
|
// */ |
50
|
|
|
// private $fixerFactory; |
51
|
|
|
// |
52
|
|
|
// public function __construct(FixerFileSystem $fixerFileSystem, FixerFactory $fixerFactory) |
53
|
|
|
// { |
54
|
|
|
// $this->fixerFileSystem = $fixerFileSystem; |
55
|
|
|
// $this->fixerFactory = $fixerFactory; |
56
|
|
|
// } |
57
|
|
|
// |
58
|
|
|
// public function create() : ConfigurationResolver |
59
|
|
|
// { |
60
|
|
|
// $allFixerFiles = $this->fixerFileSystem->findAllFixers(); |
61
|
|
|
// $allFixerObjects = $this->fixerFactory->createFixersFromFiles($allFixerFiles); |
62
|
|
|
// |
63
|
|
|
// $configurationResolver = new ConfigurationResolver(); |
64
|
|
|
// $configurationResolver->setAllFixers($allFixerObjects); |
65
|
|
|
// |
66
|
|
|
// return $configurationResolver; |
67
|
|
|
// } |
68
|
|
|
} |
69
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.