1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Consolidation\SiteAlias\Cli; |
4
|
|
|
|
5
|
|
|
use Consolidation\SiteAlias\SiteAliasFileLoader; |
6
|
|
|
use Consolidation\SiteAlias\SiteAliasManager; |
7
|
|
|
use Consolidation\SiteAlias\Util\YamlDataFileLoader; |
8
|
|
|
use Consolidation\SiteAlias\SiteSpecParser; |
9
|
|
|
use Consolidation\SiteAlias\SiteAliasName; |
10
|
|
|
|
11
|
|
|
class SiteAliasCommands extends \Robo\Tasks |
12
|
|
|
{ |
13
|
|
|
protected $aliasLoader; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* List available site aliases. |
17
|
|
|
* |
18
|
|
|
* @command site:list |
19
|
|
|
* @format yaml |
20
|
|
|
* @return array |
21
|
|
|
*/ |
22
|
|
|
public function siteList(array $varArgs) |
23
|
|
|
{ |
24
|
|
|
$this->aliasLoader = new SiteAliasFileLoader(); |
25
|
|
|
$ymlLoader = new YamlDataFileLoader(); |
26
|
|
|
$this->aliasLoader->addLoader('yml', $ymlLoader); |
27
|
|
|
$aliasName = $this->getLocationsAndAliasName($varArgs, $this->aliasLoader); |
|
|
|
|
28
|
|
|
|
29
|
|
|
$this->manager = new SiteAliasManager($this->aliasLoader); |
|
|
|
|
30
|
|
|
|
31
|
|
|
return $this->renderAliases($this->manager->getMultiple($aliasName)); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Load available site aliases. |
36
|
|
|
* |
37
|
|
|
* @command site:load |
38
|
|
|
* @format yaml |
39
|
|
|
* @return array |
40
|
|
|
*/ |
41
|
|
|
public function siteLoad(array $dirs) |
42
|
|
|
{ |
43
|
|
|
$this->aliasLoader = new SiteAliasFileLoader(); |
44
|
|
|
$ymlLoader = new YamlDataFileLoader(); |
45
|
|
|
$this->aliasLoader->addLoader('yml', $ymlLoader); |
46
|
|
|
|
47
|
|
|
foreach ($dirs as $dir) { |
48
|
|
|
$this->io()->note("Add search location: $dir"); |
49
|
|
|
$this->aliasLoader->addSearchLocation($dir); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$all = $this->aliasLoader->loadAll(); |
53
|
|
|
|
54
|
|
|
return $this->renderAliases($all); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
protected function getLocationsAndAliasName($varArgs) |
58
|
|
|
{ |
59
|
|
|
$aliasName = ''; |
60
|
|
|
foreach ($varArgs as $arg) { |
61
|
|
|
if (SiteAliasName::isAliasName($arg)) { |
|
|
|
|
62
|
|
|
$this->io()->note("Alias parameter: '$arg'"); |
63
|
|
|
$aliasName = $arg; |
64
|
|
|
} else { |
65
|
|
|
$this->io()->note("Add search location: $arg"); |
66
|
|
|
$this->aliasLoader->addSearchLocation($arg); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
return $aliasName; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
protected function renderAliases($all) |
73
|
|
|
{ |
74
|
|
|
if (empty($all)) { |
75
|
|
|
throw new \Exception("No aliases found"); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$result = []; |
79
|
|
|
foreach ($all as $name => $alias) { |
80
|
|
|
$result[$name] = $alias->export(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $result; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* List available site aliases. |
88
|
|
|
* |
89
|
|
|
* @command site:get |
90
|
|
|
* @format yaml |
91
|
|
|
* @return array |
92
|
|
|
*/ |
93
|
|
|
public function siteGet(array $varArgs) |
94
|
|
|
{ |
95
|
|
|
$this->aliasLoader = new SiteAliasFileLoader(); |
96
|
|
|
$ymlLoader = new YamlDataFileLoader(); |
97
|
|
|
$this->aliasLoader->addLoader('yml', $ymlLoader); |
98
|
|
|
$aliasName = $this->getLocationsAndAliasName($varArgs, $this->aliasLoader); |
|
|
|
|
99
|
|
|
|
100
|
|
|
$manager = new SiteAliasManager($this->aliasLoader); |
101
|
|
|
$result = $manager->get($aliasName); |
102
|
|
|
if (!$result) { |
103
|
|
|
throw new \Exception("No alias found"); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return $result->export(); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Parse a site specification. |
111
|
|
|
* |
112
|
|
|
* @command site-spec:parse |
113
|
|
|
* @format yaml |
114
|
|
|
* @return array |
115
|
|
|
*/ |
116
|
|
|
public function parse($spec, $options = ['root' => '']) |
117
|
|
|
{ |
118
|
|
|
$parser = new SiteSpecParser(); |
119
|
|
|
return $parser->parse($spec, $options['root']); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.