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 |
||
| 38 | class Queue extends ObjectAbstract implements QueueInterface |
||
| 39 | { |
||
| 40 | /** |
||
| 41 | * @var \SplQueue |
||
| 42 | * @access protected |
||
| 43 | */ |
||
| 44 | protected $queue; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var bool |
||
| 48 | * @access protected |
||
| 49 | */ |
||
| 50 | protected $terminate = false; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Constructor |
||
| 54 | * |
||
| 55 | * @param array $middlewares |
||
| 56 | * @access public |
||
| 57 | */ |
||
| 58 | public function __construct( |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Compatible with middlewares of the signature |
||
| 70 | * |
||
| 71 | * ```php |
||
| 72 | * fn($request, $response, callable $next) |
||
| 73 | * ``` |
||
| 74 | * |
||
| 75 | * @param RequestInterface $request |
||
| 76 | * @param ResponseInterface $response |
||
| 77 | * @param DelegateInterface $next |
||
| 78 | * @return ResponseInterface |
||
| 79 | * @access public |
||
| 80 | */ |
||
| 81 | public function __invoke( |
||
| 88 | |||
| 89 | /** |
||
| 90 | * {@inheritDoc} |
||
| 91 | */ |
||
| 92 | public function push($middleware, $condition = null) |
||
| 98 | |||
| 99 | /** |
||
| 100 | * {@inheritDoc} |
||
| 101 | */ |
||
| 102 | public function process( |
||
| 115 | |||
| 116 | /** |
||
| 117 | * {@inheritDoc} |
||
| 118 | */ |
||
| 119 | public function next( |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Fill the queue with middlewares |
||
| 141 | * |
||
| 142 | * @param array $middlewares |
||
| 143 | * @access protected |
||
| 144 | */ |
||
| 145 | protected function fillTheQueue(array $middlewares) |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Process/run this middleware |
||
| 161 | * |
||
| 162 | * @param MiddlewareInterface|callable $middleware |
||
| 163 | * @param RequestInterface $request |
||
| 164 | * @param ResponseInterface $response |
||
| 165 | * @return ResponseInterface |
||
| 166 | * @throws LogicException if invalid middleware type |
||
| 167 | * @access protected |
||
| 168 | */ |
||
| 169 | View Code Duplication | protected function runMiddleware( |
|
| 190 | |||
| 191 | /** |
||
| 192 | * Evaluate the condition |
||
| 193 | * |
||
| 194 | * support both a callable returns bool value or an object instance of |
||
| 195 | * ConditionInterface. |
||
| 196 | * |
||
| 197 | * @param ConditionInterface|callable $condition |
||
| 198 | * @param RequestInterface $request |
||
| 199 | * @param ResponseInterface $response |
||
| 200 | * @return bool |
||
| 201 | * @throws LogicException if condition is invalid |
||
| 202 | * @access protected |
||
| 203 | */ |
||
| 204 | View Code Duplication | protected function evalCondition( |
|
| 225 | } |
||
| 226 |