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 */ |
||
22 | class Asset |
||
23 | { |
||
24 | /** @var string $sourcePath Full-path to source asset dir */ |
||
25 | public $sourcePath; |
||
26 | |||
27 | /** @var bool $isHead Is a publish into head block */ |
||
28 | public $isHead = true; |
||
29 | /** @var array $js JavaScript files links */ |
||
30 | public $js = []; |
||
31 | /** @var array $css CSS files links */ |
||
32 | public $css = []; |
||
33 | /** @var array $required Required assets */ |
||
34 | public $required = []; |
||
35 | /** @var array $excludes Excludes extensions */ |
||
36 | public $excludes = []; |
||
37 | |||
38 | /** @var IView $view View for install current asset */ |
||
39 | protected $view; |
||
40 | /** @var string $hash Unique directory to publish into assets dir */ |
||
41 | protected $hash; |
||
42 | /** @var string $publishPath Publish path */ |
||
43 | protected $publishPath; |
||
44 | /** @var array $published Published required extends */ |
||
45 | private $published = []; |
||
46 | |||
47 | |||
48 | /** |
||
49 | * Constructor asset |
||
50 | * |
||
51 | * @access public |
||
52 | * |
||
53 | * @param IView $view |
||
54 | * |
||
55 | * @result void |
||
56 | * @throws \Micro\Base\Exception |
||
57 | */ |
||
58 | public function __construct(IView $view) |
||
82 | |||
83 | /** |
||
84 | * Send asset into view |
||
85 | * |
||
86 | * @access public |
||
87 | * @return void |
||
88 | */ |
||
89 | public function publish() |
||
117 | } |
||
118 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: