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 |
||
| 17 | class InsuranceManagerContext extends ContextRepositoryInterface implements Context, SnippetAcceptingContext |
||
|
|
|||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @Then chciałbym do samochodu :carId dodać ubezpieczenie o następujących danych: |
||
| 21 | */ |
||
| 22 | View Code Duplication | public function chcialbymDoSamochoduDodacUbezpieczenieONastepujacychDanych($carId, TableNode $table) |
|
| 38 | |||
| 39 | /** |
||
| 40 | * @Then nie można dodać ubezpieczenia do samochodu :carId, gdy różnica między dateFrom i dateTo jest inna niż jeden rok: |
||
| 41 | * |
||
| 42 | * @throws \Madkom\RegistryApplication\Domain\CarManagement\CarExceptions\InvalidDatesException |
||
| 43 | * @throws \InvalidArgumentException |
||
| 44 | */ |
||
| 45 | View Code Duplication | public function nieMoznaDodacUbezpieczeniaDoSamochoduGdyRoznicaMiedzyDateFromIDateToJestInnaNizJedenRok($carId, TableNode $table) |
|
| 66 | |||
| 67 | /** |
||
| 68 | * @Then nie można dodać kolejnego ubezpieczenia do samochodu :carId, którego data rozpoczęcia będzie wcześniej niż data końca poprzedniego: |
||
| 69 | * @Then nie można dodać kolejnego ubezpieczenia do samochodu :carId, którego data rozpoczęcia będzie później niż data końca poprzedniego: |
||
| 70 | * |
||
| 71 | * @throws \Madkom\RegistryApplication\Domain\CarManagement\CarExceptions\InvalidDatesException |
||
| 72 | * @throws \InvalidArgumentException |
||
| 73 | */ |
||
| 74 | View Code Duplication | public function nieMoznaDodacKolejnegoUbezpieczeniaDoSamochoduKtoregoDataRozpoczeciaBedzieWczesniejNizDataKoncaPoprzedniego($carId, TableNode $table) |
|
| 96 | |||
| 97 | /** |
||
| 98 | * @Given w repozytorium dodane ubezpieczenia |
||
| 99 | */ |
||
| 100 | public function wRepozytoriumDodaneUbezpieczenia() |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @Then chciałbym do istniejącego ubezpieczenia dodać plik: |
||
| 108 | * @Then chciałbym dodać do istniejącego ubezpieczenia kolejny plik: |
||
| 109 | * @Then chciałbym aby nie było możliwe dodanie pliku do nieistniejącego ubezpieczenia: |
||
| 110 | */ |
||
| 111 | public function chcialbymDoIstniejacegoUbezpieczeniaDodacPlik(TableNode $table) |
||
| 112 | { |
||
| 113 | foreach ($table as $item) { |
||
| 114 | $dto = new DocumentDTO($item['fileId'], |
||
| 115 | $item['title'], |
||
| 116 | $item['description'], |
||
| 117 | $item['source'] |
||
| 118 | ); |
||
| 119 | |||
| 120 | $newInsuranceDocument = new AddInsuranceDocumentCommand(self::$carRepository, |
||
| 121 | $item['carId'], |
||
| 122 | $item['insuranceId'], |
||
| 123 | $dto |
||
| 124 | ); |
||
| 125 | |||
| 126 | try { |
||
| 127 | $newInsuranceDocument->execute(); |
||
| 128 | } catch (NonexistentInsuranceException $nonexistent) { |
||
| 129 | } |
||
| 130 | } |
||
| 131 | } |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @Then chciałbym aby dla samochodu :carId istniały ubezpieczenia: |
||
| 135 | */ |
||
| 136 | public function chcialbymAbyDlaSamochoduIstnialyUbezpieczenia($carId, TableNode $table) |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @Then chciałbym aby dla samochodu :arg1 nie istniały ubezpieczenia o :arg2: |
||
| 149 | */ |
||
| 150 | public function chcialbymAbyDlaSamochoduNieIstnialyUbezpieczeniaO($arg1, $arg2, TableNode $table) |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @Then chciałbym aby w samochodzie :arg1 było ubezpieczenie o id :arg2 |
||
| 157 | */ |
||
| 158 | public function chcialbymAbyWSamochodzieByloUbezpieczenieOId($arg1, $arg2) |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @Then chciałbym aby w samochodzie :arg1 nie było ubezpieczenia o id :arg2 |
||
| 165 | */ |
||
| 166 | public function chcialbymAbyWSamochodzieNieByloUbezpieczeniaOId($arg1, $arg2) |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @Then chciałbym aby nie było możliwe dodanie kolejnego pliku o id :arg1 |
||
| 173 | */ |
||
| 174 | public function chcialbymAbyNieByloMozliweDodanieKolejnegoPlikuOId($arg1) |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @Then chciałbym aby nie była możliwa podmiana istniejącego pliku :arg1 |
||
| 181 | */ |
||
| 182 | public function chcialbymAbyNieBylaMozliwaPodmianaIstniejacegoPliku($arg1) |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @Then chciałbym usunąć plik :arg1 |
||
| 189 | */ |
||
| 190 | public function chcialbymUsunacPlik($arg1) |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @Then chciałbym aby nie było możliwe pobranie pliku :arg1 |
||
| 197 | */ |
||
| 198 | public function chcialbymAbyNieByloMozliwePobraniePliku($arg1) |
||
| 202 | |||
| 203 | /** |
||
| 204 | * @Then chciałbym aby nie było możliwe usunięcie pliku :arg1 |
||
| 205 | */ |
||
| 206 | public function chcialbymAbyNieByloMozliweUsunieciePliku($arg1) |
||
| 210 | } |
||
| 211 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.