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 Error extends \Exception { |
||
| 22 | /** |
||
| 23 | * Detailed message. |
||
| 24 | * |
||
| 25 | * A more detailed error message when available. If not available, contains the same as error.message. |
||
| 26 | * |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | private $detailed_message; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Construct and initialize payment response |
||
| 33 | * |
||
| 34 | * @param int $code Code. |
||
| 35 | * @param string $message Message. |
||
| 36 | * @param string $detailed_message Detailed message. |
||
| 37 | * @return void |
||
|
|
|||
| 38 | */ |
||
| 39 | 2 | public function __construct( $code, $message, $detailed_message ) { |
|
| 44 | |||
| 45 | /** |
||
| 46 | * From JSON. |
||
| 47 | * |
||
| 48 | * @param object $object Object. |
||
| 49 | * @return self |
||
| 50 | * @throws \JsonSchema\Exception\ValidationException Throws exception when JSON is not valid. |
||
| 51 | */ |
||
| 52 | 1 | View Code Duplication | public static function from_json( $object ) { |
| 66 | |||
| 67 | /** |
||
| 68 | * Get code. |
||
| 69 | * |
||
| 70 | * @return int|string |
||
| 71 | */ |
||
| 72 | 1 | public function get_code() { |
|
| 75 | |||
| 76 | /** |
||
| 77 | * Get message. |
||
| 78 | * |
||
| 79 | * @return string |
||
| 80 | */ |
||
| 81 | 1 | public function get_message() { |
|
| 84 | |||
| 85 | /** |
||
| 86 | * Get detailed message. |
||
| 87 | * |
||
| 88 | * @return string |
||
| 89 | */ |
||
| 90 | public function get_detailed_message() { |
||
| 93 | } |
||
| 94 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.