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 |
||
| 13 | final class ManagingProductBlocksContext implements Context |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var IndexPageInterface |
||
| 17 | */ |
||
| 18 | private $indexPage; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var CreatePageInterface |
||
| 22 | */ |
||
| 23 | private $createPage; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var UpdatePageInterface |
||
| 27 | */ |
||
| 28 | private $updatePage; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var ShowPageInterface |
||
| 32 | */ |
||
| 33 | private $showPage; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @param IndexPageInterface $indexPage |
||
| 37 | * @param CreatePageInterface $createPage |
||
| 38 | * @param UpdatePageInterface $updatePage |
||
| 39 | * @param ShowPageInterface $showPage |
||
| 40 | */ |
||
| 41 | public function __construct( |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @Given I want to create a new product block |
||
| 55 | * @Given I want to add a new product block |
||
| 56 | */ |
||
| 57 | public function iWantToCreateNewProductBlock() |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @Given I browse product blocks of the store |
||
| 64 | */ |
||
| 65 | public function iWantToBrowseProductBlocksOfTheStore() |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @Given I have created a product block :name with image :imagePath |
||
| 72 | */ |
||
| 73 | public function iHaveCreatedProductBlockWithImage($name, $imagePath) |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @When I set its body to :body |
||
| 83 | */ |
||
| 84 | public function iSetItsBodyTo($body) |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @When I set its link to :link |
||
| 91 | */ |
||
| 92 | public function iSetItsLinkTo($link) |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @When I set its name to :name |
||
| 99 | */ |
||
| 100 | public function iSetItsNameTo($name) |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @When I set its title to :title |
||
| 107 | */ |
||
| 108 | public function iSetItsTitleTo($title) |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @When I choose :productName as its product |
||
| 115 | */ |
||
| 116 | public function iChooseProduct($productName) |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @When I attach :imagePath as its image |
||
| 123 | */ |
||
| 124 | public function iAttachAsItsImage($imagePath) |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @When I add it |
||
| 131 | * @When I try to add it |
||
| 132 | */ |
||
| 133 | public function iAddIt() |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @Then /^I should be notified that (body|name) is required$/ |
||
| 140 | */ |
||
| 141 | public function iShouldBeNotifiedThatElementIsRequired($element) |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @Then the product block :name should appear in the store |
||
| 151 | * @Then I should see the product block :name in the list |
||
| 152 | */ |
||
| 153 | public function theProductBlockShouldAppearInTheStore($name) |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @Then I should see :amount product blocks in the list |
||
| 164 | */ |
||
| 165 | public function iShouldSeeThatManyProductBlocksInTheList($amount) |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @Then the product block :name should not be added |
||
| 176 | */ |
||
| 177 | public function theProductBlockShouldNotBeAdded($name) |
||
| 185 | |||
| 186 | /** |
||
| 187 | * @When /^I preview (this product block)$/ |
||
| 188 | * @When I preview product block :productBlock |
||
| 189 | */ |
||
| 190 | public function iPreviewProductBlock(ProductBlock $productBlock) |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @Given /^I want to edit (this product block)$/ |
||
| 197 | */ |
||
| 198 | public function iWantToEditThisProductBlock(ProductBlock $productBlock) |
||
| 202 | |||
| 203 | /** |
||
| 204 | * @When I change its body to :body |
||
| 205 | */ |
||
| 206 | public function iChangeItsBodyTo($body) |
||
| 210 | |||
| 211 | /** |
||
| 212 | * @When I change its link to :link |
||
| 213 | */ |
||
| 214 | public function iChangeItsLinkTo($link) |
||
| 218 | |||
| 219 | /** |
||
| 220 | * @When I change its title to :title |
||
| 221 | */ |
||
| 222 | public function iChangeItsTitleTo($title) |
||
| 226 | |||
| 227 | /** |
||
| 228 | * @When I change its product to :productName |
||
| 229 | */ |
||
| 230 | public function iChangeItsProductTo($productName) |
||
| 234 | |||
| 235 | /** |
||
| 236 | * @When I save my changes |
||
| 237 | * @When I try to save my changes |
||
| 238 | */ |
||
| 239 | public function iSaveMyChanges() |
||
| 243 | |||
| 244 | /** |
||
| 245 | * @When I delete product block :name |
||
| 246 | */ |
||
| 247 | public function iDeleteProductBlock($name) |
||
| 252 | |||
| 253 | /** |
||
| 254 | * @Then I should see :expected in this block contents |
||
| 255 | */ |
||
| 256 | public function iShouldSeeInThisBlockContents($expected) |
||
| 260 | |||
| 261 | /** |
||
| 262 | * @Then I should see an image |
||
| 263 | */ |
||
| 264 | public function iShouldSeeImage() |
||
| 269 | |||
| 270 | /** |
||
| 271 | * @Then /^(this product block) should have body "([^"]+)"$/ |
||
| 272 | */ |
||
| 273 | public function thisProductBlockShouldHaveBody(ProductBlock $productBlock, $body) |
||
| 279 | |||
| 280 | /** |
||
| 281 | * @Then /^(this product block) should have link "([^"]+)"$/ |
||
| 282 | */ |
||
| 283 | public function thisProductBlockShouldHaveLink(ProductBlock $productBlock, $link) |
||
| 289 | |||
| 290 | /** |
||
| 291 | * @Then /^(this product block) should have title "([^"]+)"$/ |
||
| 292 | */ |
||
| 293 | public function thisProductBlockShouldHaveTitle(ProductBlock $productBlock, $title) |
||
| 299 | |||
| 300 | /** |
||
| 301 | * @Then /^(this product block) should have product "([^"]+)"$/ |
||
| 302 | */ |
||
| 303 | public function thisProductBlockShouldHaveProduct(ProductBlock $productBlock, $productName) |
||
| 309 | |||
| 310 | /** |
||
| 311 | * @Then the product block :name should no longer exist in the store |
||
| 312 | */ |
||
| 313 | public function theProductBlockShouldNoLongerExistInTheStore($name) |
||
| 317 | } |
||
| 318 |