Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
20 | class Webhook implements Listener, Logger |
||
21 | { |
||
22 | /** |
||
23 | * @var array: List of all debug messages |
||
24 | */ |
||
25 | protected $debug = []; |
||
26 | |||
27 | /** |
||
28 | * @var array: options for Webhook |
||
29 | */ |
||
30 | protected $options = []; |
||
31 | |||
32 | /** |
||
33 | * @var null: timer start |
||
34 | */ |
||
35 | protected $start = null; |
||
36 | |||
37 | /** |
||
38 | * Constructor will only set the start time to be able to log duration |
||
39 | */ |
||
40 | 7 | public function __construct() |
|
44 | |||
45 | /** |
||
46 | * Returns an array of event names this subscriber wants to listen to. |
||
47 | * |
||
48 | * The array keys are event names and the value can be: |
||
49 | * |
||
50 | * * The method name to call (priority defaults to 0) |
||
51 | * * An array composed of the method name to call and the priority |
||
52 | * * An array of arrays composed of the method names to call and respective |
||
53 | * priorities, or 0 if unset |
||
54 | * |
||
55 | * @return array The event names to listen to |
||
56 | */ |
||
57 | 1 | public static function getSubscribedEvents() |
|
64 | |||
65 | /** |
||
66 | * Setup the logger. |
||
67 | * |
||
68 | * @see \phpbu\App\Log\Logger::setup |
||
69 | * @param array $options |
||
70 | * @throws \phpbu\App\Exception |
||
71 | */ |
||
72 | 6 | public function setup(array $options) |
|
84 | |||
85 | /** |
||
86 | * phpbu end event. |
||
87 | * |
||
88 | * @param \phpbu\App\Event\App\End $event |
||
89 | */ |
||
90 | public function onPhpbuEnd(Event\App\End $event) |
||
98 | |||
99 | /** |
||
100 | * Debugging. |
||
101 | * |
||
102 | * @param \phpbu\App\Event\Debug $event |
||
103 | */ |
||
104 | public function onDebug(Event\Debug $event) |
||
108 | |||
109 | /** |
||
110 | * Method will use the input Result to replace the placeholders in $this->jsonOutput or return an array with |
||
111 | * the default values. |
||
112 | * |
||
113 | * @param $result \phpbu\App\Result |
||
114 | * @return array: will return array placeholders are replaced with correct data |
||
|
|||
115 | */ |
||
116 | 3 | public function getOutput($result) : array |
|
150 | |||
151 | public function execute($output) |
||
171 | |||
172 | /** |
||
173 | * Method will format the output data in the format requested by the content-type |
||
174 | * @param $output: different formats |
||
175 | */ |
||
176 | 4 | public function formatPostOutput($output) |
|
192 | |||
193 | /** |
||
194 | * Simple toXml function |
||
195 | * |
||
196 | * @author Francis Lewis: https://stackoverflow.com/a/19987539 |
||
197 | * @param SimpleXMLElement $object |
||
198 | * @param array $data |
||
199 | */ |
||
200 | 1 | private function toXml(\SimpleXMLElement $object, array $data) |
|
216 | |||
217 | |||
218 | /** |
||
219 | * Get error information. |
||
220 | * |
||
221 | * @param \phpbu\App\Result $result |
||
222 | * @return array |
||
223 | */ |
||
224 | 3 | View Code Duplication | protected function extractErrors(Result $result) : array |
238 | |||
239 | /** |
||
240 | * Return backup information. |
||
241 | * |
||
242 | * @param \phpbu\App\Result $result |
||
243 | * @return array |
||
244 | */ |
||
245 | 3 | View Code Duplication | protected function extractBackups(Result $result) : array |
279 | } |
||
280 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.