1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the puli/manager package. |
5
|
|
|
* |
6
|
|
|
* (c) Bernhard Schussek <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Puli\Manager\Conflict; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* A conflict between two modules claiming the same token. |
16
|
|
|
* |
17
|
|
|
* @since 1.0 |
18
|
|
|
* |
19
|
|
|
* @author Bernhard Schussek <[email protected]> |
20
|
|
|
* |
21
|
|
|
* @see ModuleConflictDetector |
22
|
|
|
*/ |
23
|
|
|
class ModuleConflict |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
private $conflictingToken; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string[] |
32
|
|
|
*/ |
33
|
|
|
private $moduleNames; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Creates the conflict. |
37
|
|
|
* |
38
|
|
|
* @param string $conflictingToken The token that caused the conflict. |
39
|
|
|
* @param string[] $moduleNames The names of the modules claiming the |
40
|
|
|
* token. |
41
|
|
|
*/ |
42
|
28 |
|
public function __construct($conflictingToken, array $moduleNames) |
43
|
|
|
{ |
44
|
28 |
|
sort($moduleNames); |
45
|
|
|
|
46
|
28 |
|
$this->conflictingToken = $conflictingToken; |
47
|
28 |
|
$this->moduleNames = array(); |
48
|
|
|
|
49
|
28 |
|
foreach ($moduleNames as $moduleName) { |
50
|
28 |
|
$this->moduleNames[$moduleName] = true; |
51
|
|
|
} |
52
|
28 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Returns the conflicting repository path. |
56
|
|
|
* |
57
|
|
|
* @return string The conflicting repository path. |
58
|
|
|
*/ |
59
|
22 |
|
public function getConflictingToken() |
60
|
|
|
{ |
61
|
22 |
|
return $this->conflictingToken; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Returns the names of the modules causing the conflict. |
66
|
|
|
* |
67
|
|
|
* @return string[] The name of the first conflicting module. |
|
|
|
|
68
|
|
|
*/ |
69
|
22 |
|
public function getModuleNames() |
70
|
|
|
{ |
71
|
22 |
|
return array_keys($this->moduleNames); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Returns whether the conflict involves a given module name. |
76
|
|
|
* |
77
|
|
|
* @param string $moduleName A module name. |
78
|
|
|
* |
79
|
|
|
* @return bool Returns `true` if the module caused the conflict. |
80
|
|
|
*/ |
81
|
1 |
|
public function involvesModule($moduleName) |
82
|
|
|
{ |
83
|
1 |
|
return isset($this->moduleNames[$moduleName]); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Returns the opposing module names in the conflict. |
88
|
|
|
* |
89
|
|
|
* @param string $moduleName The name of a module. |
90
|
|
|
* |
91
|
|
|
* @return string[] Returns the names of the opposing modules or an empty |
92
|
|
|
* array if the module is not involved in the conflict. |
93
|
|
|
*/ |
94
|
1 |
|
public function getOpponents($moduleName) |
95
|
|
|
{ |
96
|
1 |
|
if (!isset($this->moduleNames[$moduleName])) { |
97
|
1 |
|
return array(); |
98
|
|
|
} |
99
|
|
|
|
100
|
1 |
|
$opponents = $this->moduleNames; |
101
|
|
|
|
102
|
1 |
|
unset($opponents[$moduleName]); |
103
|
|
|
|
104
|
1 |
|
return array_keys($opponents); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.