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 |
||
| 20 | final class SendMailAction extends AbstractAction |
||
| 21 | { |
||
| 22 | /** The socket that is activated when this action is successful. */ |
||
| 23 | const SOCKET_OUTPUT_SUCCESS = 'success'; |
||
| 24 | |||
| 25 | /** The socket that is activated when this action is not successful. */ |
||
| 26 | const SOCKET_OUTPUT_ERROR = 'error'; |
||
| 27 | |||
| 28 | /** The socket that contains the addresses to send to. */ |
||
| 29 | const SOCKET_TO = 'to'; |
||
| 30 | |||
| 31 | /** The socket that contains the address to send to. */ |
||
| 32 | const SOCKET_SUBJECT = 'subject'; |
||
| 33 | |||
| 34 | /** The socket that contains the message to send. */ |
||
| 35 | const SOCKET_MESSAGE = 'message'; |
||
| 36 | |||
| 37 | /** The socket that contains the from address. */ |
||
| 38 | const SOCKET_FROM = 'from'; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var TransportInterface |
||
| 42 | */ |
||
| 43 | private $transport; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Initializes a new instance of this class. |
||
| 47 | * |
||
| 48 | * @param TransportInterface $transport The mail transport used to send email messages. |
||
| 49 | */ |
||
| 50 | View Code Duplication | public function __construct(TransportInterface $transport) |
|
| 63 | |||
| 64 | /** |
||
| 65 | * Executes the node's logic. |
||
| 66 | */ |
||
| 67 | public function execute() |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Gets the value of the given socket. |
||
| 87 | * |
||
| 88 | * @param string $socketName The name of the socket to get the value for. |
||
| 89 | * @param string $message The message of the exception that is thrown in case of an error. |
||
| 90 | * @return mixed |
||
| 91 | * @throws RuntimeException Thrown when there are no nodes. |
||
| 92 | */ |
||
| 93 | private function getSocketValue($socketName, $message) |
||
| 108 | } |
||
| 109 |