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 |
||
26 | class GridBuilder implements GridBuilderInterface, \IteratorAggregate |
||
27 | { |
||
28 | protected $dispatcher; |
||
29 | public $options; |
||
30 | |||
31 | /** |
||
32 | * The children of the grid builder. |
||
33 | * |
||
34 | * @var ColumnInterface[] |
||
35 | */ |
||
36 | public $children = array(); |
||
37 | |||
38 | /** |
||
39 | * @var ObjectManager |
||
40 | */ |
||
41 | public $doctrine; |
||
42 | |||
43 | /** |
||
44 | * @var array |
||
45 | */ |
||
46 | protected $data; |
||
47 | |||
48 | /** |
||
49 | * Creates an empty form configuration. |
||
50 | * |
||
51 | * @param ObjectManager $doctrine The EntityManager |
||
52 | * @param EventDispatcherInterface $dispatcher The event dispatcher |
||
53 | * @param array $options The form options |
||
54 | * |
||
55 | * @throws InvalidArgumentException If the data class is not a valid class or if |
||
56 | * the name contains invalid characters. |
||
57 | */ |
||
58 | public function __construct(ObjectManager $doctrine, EventDispatcherInterface $dispatcher, array $options = array()) |
||
64 | |||
65 | /** |
||
66 | * @param ColumnInterface $child |
||
67 | * @param null $type |
||
68 | * @param array $options |
||
69 | * @return $this |
||
70 | */ |
||
71 | public function add(ColumnInterface $child, $type = null, array $options = array()) |
||
77 | |||
78 | /** |
||
79 | * @param string $name |
||
80 | * @return ColumnInterface |
||
81 | */ |
||
82 | View Code Duplication | public function get($name) : ColumnInterface |
|
90 | |||
91 | /** |
||
92 | * @param string $name |
||
93 | * @return $this |
||
94 | */ |
||
95 | public function remove($name) |
||
101 | |||
102 | /** |
||
103 | * @param string $name |
||
104 | * @return bool |
||
105 | */ |
||
106 | public function has($name) |
||
110 | |||
111 | /** |
||
112 | * @return \Cwd\FancyGridBundle\Column\ColumnInterface[] |
||
113 | */ |
||
114 | public function all() |
||
118 | |||
119 | /** |
||
120 | * @return GridBuilder |
||
121 | */ |
||
122 | protected function getGridConfig() |
||
128 | |||
129 | /** |
||
130 | * @return int |
||
131 | */ |
||
132 | public function count() |
||
136 | |||
137 | /** |
||
138 | * {@inheritdoc} |
||
139 | * |
||
140 | * @return \ArrayIterator |
||
141 | */ |
||
142 | public function getIterator() |
||
146 | |||
147 | |||
148 | /** |
||
149 | * @return array |
||
150 | */ |
||
151 | public function getOptions() |
||
155 | |||
156 | /** |
||
157 | * @param array $options |
||
158 | */ |
||
159 | public function setOptions(array $options) |
||
163 | |||
164 | /** |
||
165 | * @param string $name |
||
166 | * @return bool |
||
167 | */ |
||
168 | public function hasOption($name) |
||
172 | |||
173 | /** |
||
174 | * @param string $name |
||
175 | * @param string|null $default |
||
176 | * @return misc |
||
177 | */ |
||
178 | public function getOption($name, $default = null) |
||
182 | |||
183 | } |
||
184 |