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 |
||
| 11 | trait Representer |
||
| 12 | { |
||
| 13 | use ArraySerializer; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Object that is being represented |
||
| 17 | * or a collection handler |
||
| 18 | */ |
||
| 19 | protected $source; |
||
| 20 | /** |
||
| 21 | * Class name to be restored |
||
| 22 | * |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | protected $targetClassName; |
||
| 26 | /** |
||
| 27 | * Strategy indicator |
||
| 28 | * 1 = one |
||
| 29 | * 2 = collection |
||
| 30 | * 3 = restore one |
||
| 31 | * 4 = restore collection |
||
| 32 | * |
||
| 33 | * @var string |
||
| 34 | */ |
||
| 35 | protected $strategy; |
||
| 36 | |||
| 37 | 10 | public function __construct($source, $strategy) |
|
| 46 | |||
| 47 | public function rules() |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Return property name to wrap a collection representation |
||
| 54 | * If `null` - no wrapper added |
||
| 55 | * @return null | string |
||
| 56 | */ |
||
| 57 | 2 | public function collectionWrapper() |
|
| 61 | |||
| 62 | 5 | public function setTargetClassName($name) |
|
| 66 | |||
| 67 | /** |
||
| 68 | * @param $name |
||
| 69 | * @return PropertyRule |
||
| 70 | */ |
||
| 71 | 10 | public function property($name) |
|
| 75 | |||
| 76 | /** |
||
| 77 | * Represent one instance |
||
| 78 | * |
||
| 79 | * @param $source |
||
| 80 | * @return static |
||
| 81 | */ |
||
| 82 | 8 | public static function one($source) |
|
| 86 | |||
| 87 | /** |
||
| 88 | * Represent collection of instances |
||
| 89 | * |
||
| 90 | * @param array $array |
||
| 91 | * @return static |
||
| 92 | */ |
||
| 93 | 4 | public static function collection(array $array) |
|
| 97 | |||
| 98 | 4 | protected function getCollectionRepresentation() |
|
| 112 | |||
| 113 | 8 | View Code Duplication | protected function getOneRepresentation() |
| 135 | |||
| 136 | 8 | protected function getRepresentation() |
|
| 149 | |||
| 150 | |||
| 151 | /** |
||
| 152 | * @param $className |
||
| 153 | * @return static |
||
| 154 | */ |
||
| 155 | 5 | public static function restore($className) |
|
| 161 | |||
| 162 | /** |
||
| 163 | * @param string $className |
||
| 164 | * @return static |
||
| 165 | */ |
||
| 166 | 2 | public static function restoreCollection($className) |
|
| 172 | |||
| 173 | 5 | protected function getReverseRepresentation($projection) |
|
| 185 | |||
| 186 | 5 | View Code Duplication | protected function getOneReverseRepresentation($projection) |
| 208 | |||
| 209 | 2 | protected function getCollectionReverseRepresentation($projectionArray) |
|
| 226 | } |
||
| 227 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.