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 /** MicroRichController */ |
||
| 23 | abstract class RichController extends Controller |
||
| 24 | { |
||
| 25 | /** @var string $format Format for response */ |
||
| 26 | public $format = 'application/json'; |
||
| 27 | |||
| 28 | /** @var string $methodType */ |
||
| 29 | protected $methodType = 'get'; |
||
| 30 | |||
| 31 | |||
| 32 | /** |
||
| 33 | * Construct RICH controller |
||
| 34 | * |
||
| 35 | * @access public |
||
| 36 | * |
||
| 37 | * @param string $modules |
||
| 38 | * |
||
| 39 | * @result void |
||
| 40 | * @throws Exception |
||
| 41 | */ |
||
| 42 | public function __construct($modules = '') |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @inheritdoc |
||
| 54 | * @throws \InvalidArgumentException |
||
| 55 | */ |
||
| 56 | public function action($name = 'index') |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Define types for actions |
||
| 100 | * |
||
| 101 | * <code> |
||
| 102 | * // DELETE, GET, HEAD, OPTIONS, POST, PUT |
||
| 103 | * public function actionsTypes() { |
||
| 104 | * return [ |
||
| 105 | * 'create' => 'POST', |
||
| 106 | * 'read' => 'GET', |
||
| 107 | * 'update' => 'UPDATE' |
||
| 108 | * 'delete' => 'DELETE' |
||
| 109 | * ]; |
||
| 110 | * } |
||
| 111 | * </code> |
||
| 112 | * |
||
| 113 | * @access public |
||
| 114 | * |
||
| 115 | * @return array |
||
| 116 | * @abstract |
||
| 117 | */ |
||
| 118 | abstract public function actionsTypes(); |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Switch content type |
||
| 122 | * |
||
| 123 | * @access protected |
||
| 124 | * |
||
| 125 | * @param null|string $data Any content |
||
| 126 | * |
||
| 127 | * @return string |
||
| 128 | */ |
||
| 129 | protected function switchContentType($data) |
||
| 146 | } |
||
| 147 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.