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 |
||
| 28 | class EventManager extends ZfEventManager implements EventProviderInterface |
||
| 29 | { |
||
| 30 | |||
| 31 | /** |
||
| 32 | * The event prototype. |
||
| 33 | * |
||
| 34 | * @var EventInterface |
||
| 35 | */ |
||
| 36 | protected $eventPrototype; |
||
| 37 | |||
| 38 | public function setEventPrototype(EventInterface $event) |
||
| 45 | |||
| 46 | public function getEvent($name = null, $target = null, $params = null) |
||
| 47 | { |
||
| 48 | if (!$this->eventPrototype) { |
||
| 49 | $this->setEventPrototype(new Event()); |
||
| 50 | } |
||
| 51 | |||
| 52 | $event = clone $this->eventPrototype; |
||
| 53 | |||
| 54 | if (is_array($name)) { |
||
| 55 | $params = $name; |
||
| 56 | $name = null; |
||
| 57 | |||
| 58 | } else if (is_array($target)) { |
||
| 59 | $params = $target; |
||
| 60 | $target = null; |
||
| 61 | } |
||
| 62 | |||
| 63 | View Code Duplication | if (!$name && isset($params['name'])) { |
|
| 64 | $name = $params['name']; |
||
| 65 | unset($params['name']); |
||
| 66 | } |
||
| 67 | |||
| 68 | View Code Duplication | if (!$target && isset($params['target'])) { |
|
| 69 | $target = $params['target']; |
||
| 70 | unset($params['target']); |
||
| 71 | } |
||
| 72 | |||
| 73 | $event->setName($name); |
||
| 74 | if (null !== $target) { $event->setTarget($target); } |
||
| 75 | if (null !== $params) { $event->setParams($params); } |
||
| 76 | |||
| 77 | return $event; |
||
| 78 | } |
||
| 79 | |||
| 80 | public function trigger($event, $target = null, $argv = [], $callback = null) |
||
| 97 | |||
| 98 | |||
| 99 | } |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.