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 |
||
| 23 | class LocaleWebContext extends AbstractLocaleContext |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * @var GridWebContext |
||
| 27 | */ |
||
| 28 | private $gridContext; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var RoutingContext |
||
| 32 | */ |
||
| 33 | private $routingContext; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @BeforeScenario |
||
| 37 | */ |
||
| 38 | public function init(BeforeScenarioScope $scope) |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @Given I am on the locale listing page |
||
| 49 | */ |
||
| 50 | public function visitIndex() |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @Given I am on the locale creation page |
||
| 57 | */ |
||
| 58 | public function visitCreate() |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @param string $code |
||
| 65 | * |
||
| 66 | * @Given I am on the locale ":code" page |
||
| 67 | */ |
||
| 68 | public function visitShow($code) |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @param string $code |
||
| 75 | * |
||
| 76 | * @Given I am on the locale ":code" edition page |
||
| 77 | */ |
||
| 78 | public function visitUpdate($code) |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @Given I toggle the locale grid batches |
||
| 85 | */ |
||
| 86 | public function toggleGridBatch() |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @param string $code |
||
| 93 | * |
||
| 94 | * @Given I select the locale grid batch ":code" |
||
| 95 | */ |
||
| 96 | public function selectGridBatch($code) |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @Given I select the "all" locale grid batch |
||
| 103 | */ |
||
| 104 | public function selectGridBatchAll() |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @param string $code |
||
| 111 | * @param string $sorting |
||
| 112 | * |
||
| 113 | * @Given I follow the locale grid sorting link ":code" ":sorting" |
||
| 114 | */ |
||
| 115 | public function followGridSortingLink($code, $sorting) |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @param string $code |
||
| 122 | * |
||
| 123 | * @Given I follow the locale grid show link ":code" |
||
| 124 | */ |
||
| 125 | public function followGridShowLink($code) |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @param string $code |
||
| 132 | * |
||
| 133 | * @Given I follow the locale grid edition link ":code" |
||
| 134 | */ |
||
| 135 | public function followGridEditionLink($code) |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @param string $code |
||
| 142 | * |
||
| 143 | * @Given I follow the locale grid deletion link ":code" |
||
| 144 | */ |
||
| 145 | public function followGridDeletionLink($code) |
||
| 149 | |||
| 150 | /** |
||
| 151 | * @Given I wait the locale grid filters |
||
| 152 | */ |
||
| 153 | public function waitGridFilters() |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @Given I wait the locale grid filters refresh |
||
| 160 | */ |
||
| 161 | public function waitGridFiltersRefresh() |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @param TableNode $table |
||
| 168 | * |
||
| 169 | * @Then the locale grid should be: |
||
| 170 | */ |
||
| 171 | public function assertGrid(TableNode $table) |
||
| 175 | |||
| 176 | /** |
||
| 177 | * @param string $column |
||
| 178 | * @param string $order |
||
| 179 | * |
||
| 180 | * @Then the locale grid column ":column" should be sorted ":order" |
||
| 181 | */ |
||
| 182 | public function assertGridSorting($column, $order) |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @param string $column |
||
| 189 | * @param string $cells |
||
| 190 | * |
||
| 191 | * @Given the locale grid for the column ":column" should be ":cells" |
||
| 192 | */ |
||
| 193 | public function assertGridCells($column, $cells) |
||
| 200 | |||
| 201 | /** |
||
| 202 | * @Then all locale grid batches should be checked |
||
| 203 | */ |
||
| 204 | public function assertGridBatchesChecked() |
||
| 208 | |||
| 209 | /** |
||
| 210 | * @Then all locale grid batches should not be checked |
||
| 211 | */ |
||
| 212 | public function assertGridBatchesUnchecked() |
||
| 216 | |||
| 217 | /** |
||
| 218 | * @Then I should be on the locale listing page |
||
| 219 | */ |
||
| 220 | public function assertIndexAddress() |
||
| 224 | |||
| 225 | /** |
||
| 226 | * @Then I should be on the locale batching page |
||
| 227 | */ |
||
| 228 | public function assertBatchAddress() |
||
| 232 | |||
| 233 | /** |
||
| 234 | * @Then I should be on the locale creation page |
||
| 235 | */ |
||
| 236 | public function assertCreateAddress() |
||
| 240 | |||
| 241 | /** |
||
| 242 | * @param string $code |
||
| 243 | * |
||
| 244 | * @Then I should be on the locale ":code" page |
||
| 245 | */ |
||
| 246 | public function assertShowAddress($code) |
||
| 250 | |||
| 251 | /** |
||
| 252 | * @param string $code |
||
| 253 | * |
||
| 254 | * @Then I should be on the locale ":code" edition page |
||
| 255 | */ |
||
| 256 | public function assertUpdateAddress($code) |
||
| 260 | |||
| 261 | /** |
||
| 262 | * @param string $action |
||
| 263 | * @param string|null $code |
||
| 264 | */ |
||
| 265 | View Code Duplication | private function visit($action, $code = null) |
|
| 275 | |||
| 276 | /** |
||
| 277 | * @param string $action |
||
| 278 | * @param string|null $code |
||
| 279 | */ |
||
| 280 | View Code Duplication | private function assertAddress($action, $code = null) |
|
| 290 | } |
||
| 291 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: