These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Onigoetz\Deployer\Configuration; |
||
4 | |||
5 | use Onigoetz\Deployer\Configuration\Containers\ExtendableConfigurationContainer; |
||
6 | use Onigoetz\Deployer\Configuration\Sources\Cloned; |
||
7 | use Onigoetz\Deployer\Configuration\Sources\Upload; |
||
8 | |||
9 | class Source extends ExtendableConfigurationContainer |
||
10 | { |
||
11 | /** |
||
12 | * Create a source with the right class |
||
13 | * |
||
14 | * @param string $name The source name |
||
15 | * @param array $data |
||
16 | * @param ConfigurationManager $manager |
||
17 | * @param Source $parent |
||
18 | * @throws \LogicException |
||
19 | * @return Cloned|Upload |
||
20 | */ |
||
21 | 135 | public static function make($name, array $data, ConfigurationManager $manager, Source $parent = null) |
|
22 | { |
||
23 | 135 | $strategy = static::findStrategy($name, $data, $manager, $parent); |
|
24 | |||
25 | switch ($strategy) { |
||
26 | 132 | case 'clone': |
|
27 | 96 | return new Cloned($name, $data, $manager, $parent); |
|
0 ignored issues
–
show
|
|||
28 | break; |
||
29 | 27 | case 'upload': |
|
30 | 36 | return new Upload($name, $data, $manager, $parent); |
|
0 ignored issues
–
show
It seems like
$parent defined by parameter $parent on line 21 can also be of type object<Onigoetz\Deployer\Configuration\Source> ; however, Onigoetz\Deployer\Config...ontainer::__construct() does only seem to accept null|object<self> , maybe add an additional type check?
This check looks at variables that have been passed in as parameters and are passed out again to other methods. If the outgoing method call has stricter type requirements than the method itself, an issue is raised. An additional type check may prevent trouble.
Loading history...
|
|||
31 | break; |
||
32 | 2 | default: |
|
33 | 2 | } |
|
34 | |||
35 | 3 | throw new \LogicException("Unrecognized strategy '{$strategy}'"); |
|
36 | } |
||
37 | |||
38 | 135 | protected static function findStrategy($name, $data, ConfigurationManager $manager, Source $parent = null) |
|
39 | { |
||
40 | 135 | if (isset($data['strategy'])) { |
|
41 | 132 | return $data['strategy']; |
|
42 | } |
||
43 | |||
44 | 15 | if ($parent) { |
|
45 | 6 | return $parent->getStrategy(); |
|
46 | } |
||
47 | |||
48 | 12 | if (isset($data['extends']) && $manager->has('source', $data['extends'])) { |
|
49 | 9 | return $manager->get('source', $data['extends'])->getStrategy(); |
|
50 | } |
||
51 | |||
52 | 3 | throw new \LogicException("Cannot find a valid strategy for the source '$name'"); |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * {@inheritdoc} |
||
57 | */ |
||
58 | 48 | public function getContainerType() |
|
59 | { |
||
60 | 48 | return 'source'; |
|
61 | } |
||
62 | |||
63 | 12 | public function getStrategy() |
|
64 | { |
||
65 | 12 | return $this->getValueOrFail('strategy', "no 'strategy' specified for source '{$this->name}''"); |
|
66 | } |
||
67 | |||
68 | /** |
||
69 | * @throws \LogicException |
||
70 | * @return mixed |
||
71 | */ |
||
72 | 60 | public function getPath() |
|
73 | { |
||
74 | 60 | return $this->getValueOrFail('path', "no 'path' specified for source '{$this->name}''"); |
|
75 | } |
||
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | */ |
||
80 | 27 | public function checkValidity() |
|
81 | { |
||
82 | 27 | $this->getPath(); |
|
83 | |||
84 | 21 | return true; |
|
85 | } |
||
86 | } |
||
87 |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.