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 |
||
| 22 | class Version20140408114519_EditListStudios extends AbstractMigration implements ContainerAwareInterface |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * Entity manager. |
||
| 26 | * |
||
| 27 | * @var EntityManagerInterface |
||
| 28 | */ |
||
| 29 | protected $em; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Add studios. |
||
| 33 | * |
||
| 34 | * @var array |
||
| 35 | */ |
||
| 36 | protected $add = [ |
||
| 37 | 'Actas', |
||
| 38 | 'OB Planning', |
||
| 39 | 'Studio Rikka', |
||
| 40 | 'Group TAC', |
||
| 41 | 'Brains Base', |
||
| 42 | 'Studio Nue', |
||
| 43 | 'Anima', |
||
| 44 | 'Hoods Entertainment', |
||
| 45 | 'Palm Studio', |
||
| 46 | 'MAPPA', |
||
| 47 | 'Cammot', |
||
| 48 | 'Fifth Avenue', |
||
| 49 | 'NAZ', |
||
| 50 | 'Pierrot Plus', |
||
| 51 | ]; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Rename studios. |
||
| 55 | * |
||
| 56 | * @var array |
||
| 57 | */ |
||
| 58 | protected $rename = [ |
||
| 59 | 'Xebec' => 'XEBEC', |
||
| 60 | 'Ufotable' => 'ufotable', |
||
| 61 | 'Shaft' => 'SHAFT', |
||
| 62 | 'A-1 Pictures' => 'A-1 Pictures Inc.', |
||
| 63 | 'Imagin' => 'IMAGIN', |
||
| 64 | 'Feel' => 'feel.', |
||
| 65 | 'Animax Entertainment' => 'Animax', |
||
| 66 | 'A.C.G.T' => 'A.C.G.T.', |
||
| 67 | 'Zexcs' => 'ZEXCS', |
||
| 68 | ]; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Set container. |
||
| 72 | * |
||
| 73 | * @param ContainerInterface $container |
||
| 74 | */ |
||
| 75 | public function setContainer(ContainerInterface $container = null) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @param Schema $schema |
||
| 82 | */ |
||
| 83 | public function up(Schema $schema) |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @param Schema $schema |
||
| 106 | */ |
||
| 107 | public function down(Schema $schema) |
||
| 124 | } |
||
| 125 |
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe: