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 |
||
| 27 | final class UserContext implements Context |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * @var SharedStorageInterface |
||
| 31 | */ |
||
| 32 | private $sharedStorage; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var UserRepositoryInterface |
||
| 36 | */ |
||
| 37 | private $userRepository; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var TestUserFactoryInterface |
||
| 41 | */ |
||
| 42 | private $userFactory; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var FactoryInterface |
||
| 46 | */ |
||
| 47 | private $addressFactory; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var ObjectManager |
||
| 51 | */ |
||
| 52 | private $userManager; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var CountryNameConverterInterface |
||
| 56 | */ |
||
| 57 | private $countryCodeConverter; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @param SharedStorageInterface $sharedStorage |
||
| 61 | * @param UserRepositoryInterface $userRepository |
||
| 62 | * @param TestUserFactoryInterface $userFactory |
||
| 63 | * @param FactoryInterface $addressFactory |
||
| 64 | * @param ObjectManager $userManager |
||
| 65 | * @param CountryNameConverterInterface $countryCodeConverter |
||
| 66 | */ |
||
| 67 | public function __construct( |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @Given there is user :email identified by :password |
||
| 85 | * @Given there was account of :email with password :password |
||
| 86 | * @Given there is a user :email |
||
| 87 | */ |
||
| 88 | public function thereIsUserIdentifiedBy($email, $password = 'sylius') |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @Given there is user :email identified by :password, with :country as shipping country |
||
| 99 | */ |
||
| 100 | public function thereIsUserWithShippingCountry($email, $password, $country) |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @Given my default shipping address is :country |
||
| 113 | */ |
||
| 114 | public function myDefaultShippingAddressIs($country) |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @Given the account of :email was deleted |
||
| 125 | */ |
||
| 126 | public function accountWasDeleted($email) |
||
| 134 | |||
| 135 | /** |
||
| 136 | * @Given his account was deleted |
||
| 137 | */ |
||
| 138 | public function hisAccountWasDeleted() |
||
| 144 | |||
| 145 | /** |
||
| 146 | * @Given there is an administrator identified by :email |
||
| 147 | */ |
||
| 148 | public function theStoreHasCustomerServiceAccountIdentifiedBy($email) |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @param string $firstName |
||
| 159 | * @param string $lastName |
||
| 160 | * @param string $country |
||
| 161 | * @param string $street |
||
| 162 | * @param string $city |
||
| 163 | * @param string $postcode |
||
| 164 | * |
||
| 165 | * @return AddressInterface |
||
| 166 | */ |
||
| 167 | View Code Duplication | private function createAddress( |
|
| 185 | } |
||
| 186 |