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 /** MicroAsset */ |
||
| 24 | class Asset |
||
| 25 | { |
||
| 26 | /** @var string $sourcePath Full-path to source asset dir */ |
||
| 27 | public $sourcePath; |
||
| 28 | |||
| 29 | /** @var bool $isHead Is a publish into head block */ |
||
| 30 | public $isHead = true; |
||
| 31 | /** @var array $js JavaScript files links */ |
||
| 32 | public $js = []; |
||
| 33 | /** @var array $css CSS files links */ |
||
| 34 | public $css = []; |
||
| 35 | /** @var array $required Required assets */ |
||
| 36 | public $required = []; |
||
| 37 | /** @var array $excludes Excludes extensions */ |
||
| 38 | public $excludes = []; |
||
| 39 | |||
| 40 | /** @var IView $view View for install current asset */ |
||
| 41 | protected $view; |
||
| 42 | /** @var string $hash Unique directory to publish into assets dir */ |
||
| 43 | protected $hash; |
||
| 44 | /** @var string $publishPath Publish path */ |
||
| 45 | protected $publishPath; |
||
| 46 | /** @var array $published Published required extends */ |
||
| 47 | private $published = []; |
||
| 48 | |||
| 49 | |||
| 50 | /** |
||
| 51 | * Constructor asset |
||
| 52 | * |
||
| 53 | * @access public |
||
| 54 | * |
||
| 55 | * @param IView $view |
||
| 56 | * |
||
| 57 | * @result void |
||
| 58 | * @throws \Micro\Base\Exception |
||
| 59 | */ |
||
| 60 | public function __construct(IView $view) |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Send asset into view |
||
| 87 | * |
||
| 88 | * @access public |
||
| 89 | * @return void |
||
| 90 | */ |
||
| 91 | public function publish() |
||
| 129 | } |
||
| 130 |
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.