1 | <?php |
||
12 | class Projects extends BaseOutput |
||
13 | { |
||
14 | /** |
||
15 | * output for projects API. |
||
16 | * |
||
17 | * @param OutputInterface $output |
||
18 | * @param array $response |
||
19 | */ |
||
20 | 1 | public function all(OutputInterface $output, array $response) |
|
21 | { |
||
22 | 1 | $this->printTable($output, |
|
23 | 1 | ['Key', 'Name', 'Type', 'Public', 'Dependencies', 'Outdated', 'Updated At', 'Bad Licenses', 'Unknown Licenses'], |
|
24 | 1 | ['ids', 'name', 'project_type', 'public', 'dep_number', 'out_number', 'updated_at', 'licenses_red', 'licenses_unknown'], |
|
25 | $response, |
||
26 | function ($key, $value) use ($output) { |
||
27 | 1 | if ('public' === $key) { |
|
28 | 1 | return $value === 1 ? 'Yes' : 'No'; |
|
29 | } |
||
30 | |||
31 | 1 | if (!in_array($key, ['out_number', 'licenses_red', 'licenses_unknown'], true)) { |
|
32 | 1 | return $value; |
|
33 | } |
||
34 | |||
35 | 1 | return $this->printBoolean($output, $value > 0 ? $value : 'No', $value, !$value, false); |
|
36 | 1 | } |
|
37 | ); |
||
38 | 1 | } |
|
39 | |||
40 | /** |
||
41 | * output for licenses API. |
||
42 | * |
||
43 | * @param OutputInterface $output |
||
44 | * @param array $response |
||
45 | */ |
||
46 | 1 | public function licenses(OutputInterface $output, array $response) |
|
47 | { |
||
48 | 1 | $table = $this->createTable($output); |
|
49 | 1 | $table->setHeaders(['license', 'name']); |
|
50 | |||
51 | 1 | foreach ($response['licenses'] as $license => $projects) { |
|
52 | 1 | foreach ($projects as $project) { |
|
53 | 1 | $name = $license === 'unknown' ? '<error>' . $project['name'] . '</error>' : $project['name']; |
|
54 | 1 | $license = $license === 'unknown' ? '<error>unknown</error>' : $license; |
|
55 | |||
56 | 1 | $table->addRow([$license, $name]); |
|
57 | } |
||
58 | } |
||
59 | |||
60 | 1 | $table->render($output); |
|
|
|||
61 | 1 | } |
|
62 | |||
63 | /** |
||
64 | * output for show API. |
||
65 | * |
||
66 | * @param OutputInterface $output |
||
67 | * @param array $response |
||
68 | */ |
||
69 | 1 | public function show(OutputInterface $output, array $response) |
|
70 | { |
||
71 | 1 | $this->output($output, $response); |
|
72 | 1 | } |
|
73 | |||
74 | /** |
||
75 | * output for update API. |
||
76 | * |
||
77 | * @param OutputInterface $output |
||
78 | * @param array $response |
||
79 | */ |
||
80 | 1 | public function update(OutputInterface $output, array $response) |
|
81 | { |
||
82 | 1 | $this->output($output, $response); |
|
83 | 1 | } |
|
84 | |||
85 | /** |
||
86 | * output for create API. |
||
87 | * |
||
88 | * @param OutputInterface $output |
||
89 | * @param array $response |
||
90 | */ |
||
91 | 1 | public function create(OutputInterface $output, array $response) |
|
92 | { |
||
93 | 1 | $this->output($output, $response); |
|
94 | 1 | } |
|
95 | |||
96 | /** |
||
97 | * output for delete API. |
||
98 | * |
||
99 | * @param OutputInterface $output |
||
100 | * @param array $response |
||
101 | */ |
||
102 | 1 | public function delete(OutputInterface $output, array $response) |
|
103 | { |
||
104 | 1 | $this->printMessage($output, $response); |
|
105 | 1 | } |
|
106 | |||
107 | /** |
||
108 | * default output for create/show/update. |
||
109 | * |
||
110 | * @param OutputInterface $output |
||
111 | * @param array $response |
||
112 | */ |
||
113 | 3 | private function output(OutputInterface $output, array $response) |
|
114 | { |
||
115 | 3 | $this->printList($output, |
|
116 | 3 | ['Name', 'Key', 'Type', 'Public', 'Outdated', 'Updated At', 'Bad Licenses', 'Unknown Licenses'], |
|
117 | 3 | ['name', 'id', 'project_type', 'public', 'out_number', 'updated_at', 'licenses_red', 'licenses_unknown'], |
|
118 | $response, |
||
119 | function ($key, $value) use ($output) { |
||
120 | 3 | if (in_array($key, ['Outdated', 'Bad Licenses', 'Unknown Licenses'], true)) { |
|
121 | 3 | return $this->printBoolean($output, $value === 0 ? 'No' : $value, $value, !$value, false); |
|
122 | } |
||
123 | |||
124 | 3 | return $value; |
|
125 | 3 | } |
|
126 | ); |
||
127 | |||
128 | 3 | $this->printTable($output, |
|
129 | 3 | ['Name', 'Stable', 'Outdated', 'Current', 'Requested', 'Licenses', 'Vulnerabilities'], |
|
130 | 3 | ['name', 'stable', 'outdated', 'version_current', 'version_requested', 'licenses', 'security_vulnerabilities'], |
|
131 | 3 | $response['dependencies'], |
|
132 | 3 | function ($key, $value) use ($output) { |
|
133 | 3 | if ('licenses' === $key) { |
|
134 | 3 | return implode(', ', array_column($value, 'name')); |
|
135 | } |
||
136 | 3 | if ('stable' === $key) { |
|
137 | 3 | return $this->printBoolean($output, 'Yes', 'No', $value, false); |
|
138 | } |
||
139 | 3 | if ('outdated' === $key) { |
|
140 | 3 | return $this->printBoolean($output, 'No', 'Yes', !$value, false); |
|
141 | } |
||
142 | |||
143 | 3 | if ('security_vulnerabilities' === $key) { |
|
144 | 3 | if (is_array($value)) { |
|
145 | 3 | return $this->printBoolean($output, 'No', implode(', ', array_column($value, 'cve')), count($value) === 0, false); |
|
146 | } |
||
147 | |||
148 | return $this->printBoolean($output, 'No', 'Yes', true, false); |
||
149 | } |
||
150 | |||
151 | 3 | return $value; |
|
152 | 3 | } |
|
153 | ); |
||
154 | 3 | } |
|
155 | |||
156 | /** |
||
157 | * output for the merge API. |
||
158 | * |
||
159 | * @param OutputInterface $output |
||
160 | * @param array $response |
||
161 | */ |
||
162 | 1 | public function merge(OutputInterface $output, array $response) |
|
163 | { |
||
164 | 1 | $this->printBoolean($output, 'OK', 'FAIL', true === $response['success']); |
|
165 | 1 | } |
|
166 | |||
167 | /** |
||
168 | * output for the merge_ga API. |
||
169 | * |
||
170 | * @param OutputInterface $output |
||
171 | * @param array $response |
||
172 | */ |
||
173 | 1 | public function mergeGa(OutputInterface $output, array $response) |
|
177 | |||
178 | /** |
||
179 | * output for the unmerge API. |
||
180 | * |
||
181 | * @param OutputInterface $output |
||
182 | * @param array $response |
||
183 | */ |
||
184 | 1 | public function unmerge(OutputInterface $output, array $response) |
|
188 | } |
||
189 |
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.