1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SugaredRim\PHP\CodeSniffer; |
4
|
|
|
|
5
|
|
|
use Schnittstabil\ComposerExtra\ComposerExtra; |
6
|
|
|
use Schnittstabil\FinderByConfig\FinderByConfig; |
7
|
|
|
|
8
|
|
|
class Config extends \PHP_CodeSniffer\Config |
9
|
|
|
{ |
10
|
|
|
protected $sugaredRimNamespace = 'sugared-rim/php_codesniffer'; |
11
|
|
|
protected $sugaredRimfinderByConfig; |
12
|
|
|
protected $sugaredRimDefaultConfig; |
13
|
|
|
protected $sugaredRimConfig; |
14
|
|
|
|
15
|
|
|
public function __construct(array $cliArgs = [], $dieOnUnknownArg = true, callable $finderByConfig = null) |
16
|
|
|
{ |
17
|
|
|
if ($finderByConfig === null) { |
18
|
|
|
$finderByConfig = new FinderByConfig(); |
19
|
|
|
} |
20
|
|
|
$this->sugaredRimfinderByConfig = $finderByConfig; |
21
|
|
|
|
22
|
|
|
$this->sugaredRimDefaultConfig = new \stdClass(); |
23
|
|
|
$this->sugaredRimDefaultConfig->presets = [ |
24
|
|
|
'SugaredRim\\PHP\\CodeSniffer\\DefaultPreset::get', |
25
|
|
|
]; |
26
|
|
|
|
27
|
|
|
parent::__construct($cliArgs, $dieOnUnknownArg); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
View Code Duplication |
protected function sugaredRimGetConfig($path = null, $default = null) |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
if ($this->sugaredRimConfig === null) { |
33
|
|
|
$this->sugaredRimConfig = new ComposerExtra( |
34
|
|
|
$this->sugaredRimNamespace, |
35
|
|
|
$this->sugaredRimDefaultConfig, |
36
|
|
|
'presets' |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
if ($path === null) { |
41
|
|
|
$path = array(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return $this->sugaredRimConfig->get($path, $default); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function processLongArgument($arg, $pos) |
48
|
|
|
{ |
49
|
|
|
if (substr($arg, 0, 10) === 'namespace=') { |
50
|
|
|
$this->sugaredRimNamespace = substr($arg, 10); |
51
|
|
|
|
52
|
|
|
return; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
parent::processLongArgument($arg, $pos); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
View Code Duplication |
public function setCommandLineValues($args) |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
parent::setCommandLineValues($args); |
61
|
|
|
|
62
|
|
|
if (!empty($this->files)) { |
|
|
|
|
63
|
|
|
return; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$files = $this->sugaredRimGetConfig('files', []); |
67
|
|
|
|
68
|
|
|
foreach (call_user_func($this->sugaredRimfinderByConfig, $files) as $file) { |
69
|
|
|
$this->processUnknownArgument($file->getPathname(), -1); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
75
|
|
|
*/ |
76
|
|
View Code Duplication |
protected function sugaredRimProcessConfig() |
|
|
|
|
77
|
|
|
{ |
78
|
|
|
foreach ($this->sugaredRimGetConfig() as $key => $value) { |
79
|
|
|
switch ($key) { |
80
|
|
|
case 'presets': |
81
|
|
|
case 'files': |
82
|
|
|
continue 2; |
83
|
|
|
case 'default_standard': |
84
|
|
|
if (is_array($value)) { |
85
|
|
|
$value = implode(',', $value); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$this->setConfigData($key, $value, true); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.