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  | 
            ||
| 25 | class EntityListeners implements Buildable  | 
            ||
| 26 | { | 
            ||
| 27 | /**  | 
            ||
| 28 | * @var ClassMetadataBuilder  | 
            ||
| 29 | */  | 
            ||
| 30 | private $builder;  | 
            ||
| 31 | |||
| 32 | /**  | 
            ||
| 33 | * @var array  | 
            ||
| 34 | */  | 
            ||
| 35 | private $events = [  | 
            ||
| 36 | Events::preRemove => [],  | 
            ||
| 37 | Events::postRemove => [],  | 
            ||
| 38 | Events::prePersist => [],  | 
            ||
| 39 | Events::postPersist => [],  | 
            ||
| 40 | Events::preUpdate => [],  | 
            ||
| 41 | Events::postUpdate => [],  | 
            ||
| 42 | Events::postLoad => [],  | 
            ||
| 43 | Events::loadClassMetadata => [],  | 
            ||
| 44 | Events::onClassMetadataNotFound => [],  | 
            ||
| 45 | Events::preFlush => [],  | 
            ||
| 46 | Events::onFlush => [],  | 
            ||
| 47 | Events::postFlush => [],  | 
            ||
| 48 | Events::onClear => [],  | 
            ||
| 49 | ];  | 
            ||
| 50 | |||
| 51 | /**  | 
            ||
| 52 | * LifecycleEvents constructor.  | 
            ||
| 53 | *  | 
            ||
| 54 | * @param ClassMetadataBuilder $builder  | 
            ||
| 55 | */  | 
            ||
| 56 | 68 | public function __construct(ClassMetadataBuilder $builder)  | 
            |
| 60 | |||
| 61 | /**  | 
            ||
| 62 | * Magically call all methods that match an event name.  | 
            ||
| 63 | *  | 
            ||
| 64 | * @param string $event  | 
            ||
| 65 | * @param array $args  | 
            ||
| 66 | *  | 
            ||
| 67 | * @throws InvalidArgumentException  | 
            ||
| 68 | *  | 
            ||
| 69 | * @return LifecycleEvents  | 
            ||
| 70 | */  | 
            ||
| 71 | 64 | View Code Duplication | public function __call($event, $args)  | 
            
| 81 | |||
| 82 | /**  | 
            ||
| 83 | * @param string $event  | 
            ||
| 84 | * @param string $class  | 
            ||
| 85 | * @param string|null $method  | 
            ||
| 86 | *  | 
            ||
| 87 | * @return EntityListeners  | 
            ||
| 88 | */  | 
            ||
| 89 | 64 | private function add($event, $class, $method = null)  | 
            |
| 98 | |||
| 99 | /**  | 
            ||
| 100 | * Execute the build process.  | 
            ||
| 101 | */  | 
            ||
| 102 | 64 | public function build()  | 
            |
| 110 | }  | 
            ||
| 111 |