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 |
||
| 14 | class RequestProcessor implements HTTPMiddleware |
||
| 15 | { |
||
| 16 | use Injectable; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * List of currently assigned request filters |
||
| 20 | * |
||
| 21 | * @var RequestFilter[] |
||
| 22 | */ |
||
| 23 | private $filters = array(); |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Construct new RequestFilter with a list of filter objects |
||
| 27 | * |
||
| 28 | * @param RequestFilter[] $filters |
||
| 29 | */ |
||
| 30 | public function __construct($filters = array()) |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Assign a list of request filters |
||
| 37 | * |
||
| 38 | * @param RequestFilter[] $filters |
||
| 39 | * @return $this |
||
| 40 | */ |
||
| 41 | public function setFilters($filters) |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @inheritdoc |
||
| 49 | */ |
||
| 50 | public function process(HTTPRequest $request, callable $delegate) |
||
| 77 | } |
||
| 78 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.