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 |
||
12 | class Sheet implements ISheetParser |
||
13 | { |
||
14 | private $parser; |
||
15 | |||
16 | /** |
||
17 | * Конструктор |
||
18 | * |
||
19 | * @param IExcel $excel (Класс реализующий IExcel интерфейс) |
||
20 | */ |
||
21 | public function __construct(IExcel $excel) |
||
25 | |||
26 | /** |
||
27 | * Метод чтения документа (c активного листа). |
||
28 | * |
||
29 | * @return array (Содержимое документа) |
||
30 | * |
||
31 | * @throws PHPExcel_Reader_Exception |
||
32 | */ |
||
33 | public function readActiveSheet() |
||
42 | |||
43 | /** |
||
44 | * Метод для чтения отдельного листа (по названию). |
||
45 | * |
||
46 | * @param string $sheetName (Название листа) |
||
47 | * |
||
48 | * @return array (Содержимое документа) |
||
49 | * |
||
50 | * @throws PHPExcel_Reader_Exception |
||
51 | */ |
||
52 | View Code Duplication | public function readSheetByName($sheetName) |
|
61 | |||
62 | /** |
||
63 | * Метод для чтения отдельного листа (по индексу). |
||
64 | * |
||
65 | * @param int $sheetIndex (Индекс листа (счит.с 0)) |
||
66 | * |
||
67 | * @return array (Содержимое документа) |
||
68 | * |
||
69 | * @throws PHPExcel_Exception |
||
70 | * @throws PHPExcel_Reader_Exception |
||
71 | */ |
||
72 | View Code Duplication | public function readSheetByIndex($sheetIndex) |
|
81 | } |
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: