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 |
||
| 21 | class Webhook implements Listener, Logger |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * @var array: List of all debug messages |
||
| 25 | */ |
||
| 26 | protected $debug = []; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var array: options for Webhook |
||
| 30 | */ |
||
| 31 | protected $options = []; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var null: timer start |
||
| 35 | */ |
||
| 36 | protected $start = null; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Constructor will only set the start time to be able to log duration |
||
| 40 | */ |
||
| 41 | 7 | public function __construct() |
|
| 45 | |||
| 46 | /** |
||
| 47 | * Returns an array of event names this subscriber wants to listen to. |
||
| 48 | * |
||
| 49 | * The array keys are event names and the value can be: |
||
| 50 | * |
||
| 51 | * * The method name to call (priority defaults to 0) |
||
| 52 | * * An array composed of the method name to call and the priority |
||
| 53 | * * An array of arrays composed of the method names to call and respective |
||
| 54 | * priorities, or 0 if unset |
||
| 55 | * |
||
| 56 | * @return array The event names to listen to |
||
| 57 | */ |
||
| 58 | 1 | public static function getSubscribedEvents() |
|
| 65 | |||
| 66 | /** |
||
| 67 | * Setup the logger. |
||
| 68 | * |
||
| 69 | * @see \phpbu\App\Log\Logger::setup |
||
| 70 | * @param array $options |
||
| 71 | * @throws \phpbu\App\Exception |
||
| 72 | */ |
||
| 73 | 6 | public function setup(array $options) |
|
| 88 | |||
| 89 | /** |
||
| 90 | * phpbu end event. |
||
| 91 | * |
||
| 92 | * @param \phpbu\App\Event\App\End $event |
||
| 93 | */ |
||
| 94 | public function onPhpbuEnd(Event\App\End $event) |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Debugging. |
||
| 105 | * |
||
| 106 | * @param \phpbu\App\Event\Debug $event |
||
| 107 | */ |
||
| 108 | public function onDebug(Event\Debug $event) |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Method will use the input Result to replace the placeholders in $this->jsonOutput or return an array with |
||
| 115 | * the default values. |
||
| 116 | * |
||
| 117 | * @param $result \phpbu\App\Result |
||
| 118 | * @return array: will return array placeholders are replaced with correct data |
||
|
|
|||
| 119 | */ |
||
| 120 | 3 | public function getOutput($result) : array |
|
| 154 | |||
| 155 | public function execute($output) |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Method will format the output data in the format requested by the content-type |
||
| 181 | * @param $output: different formats |
||
| 182 | */ |
||
| 183 | 4 | public function formatPostOutput($output) |
|
| 199 | |||
| 200 | /** |
||
| 201 | * Simple toXml function |
||
| 202 | * |
||
| 203 | * @author Francis Lewis: https://stackoverflow.com/a/19987539 |
||
| 204 | * @param SimpleXMLElement $object |
||
| 205 | * @param array $data |
||
| 206 | */ |
||
| 207 | 1 | private function toXml(\SimpleXMLElement $object, array $data) |
|
| 223 | |||
| 224 | |||
| 225 | /** |
||
| 226 | * Get error information. |
||
| 227 | * |
||
| 228 | * @param \phpbu\App\Result $result |
||
| 229 | * @return array |
||
| 230 | */ |
||
| 231 | 3 | View Code Duplication | protected function extractErrors(Result $result) : array |
| 245 | |||
| 246 | /** |
||
| 247 | * Return backup information. |
||
| 248 | * |
||
| 249 | * @param \phpbu\App\Result $result |
||
| 250 | * @return array |
||
| 251 | */ |
||
| 252 | 3 | View Code Duplication | protected function extractBackups(Result $result) : array |
| 286 | } |
||
| 287 |
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.