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 |
||
| 10 | * Represents an unknown error response exception. |
||
| 11 | */ |
||
| 12 | class UnknownErrorResponseException extends Exception |
||
| 13 | { |
||
| 14 | private ?string $response = null; |
||
|
|
|||
| 15 | |||
| 16 | public function __construct(string $message = '', ?string $response = null, ?Throwable $previous = null) |
||
| 17 | { |
||
| 18 | $this->response = $response; |
||
| 19 | |||
| 20 | parent::__construct($message, 0, $previous); |
||
| 21 | } |
||
| 22 | |||
| 23 | 1 | public function __toString(): string |
|
| 24 | { |
||
| 25 | 1 | return '[' . static::class . '] ' . $this->message . "\n" . |
|
| 26 | 'Response: ' . "\n" . |
||
| 27 | 1 | $this->response; |
|
| 28 | 1 | } |
|
| 29 | |||
| 30 | /** |
||
| 31 | * Gets the Unknown error response. |
||
| 32 | */ |
||
| 33 | public function getResponse(): ?string |
||
| 34 | { |
||
| 35 | return $this->response; |
||
| 36 | } |
||
| 37 | } |
||
| 38 |