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 |
||
| 11 | class PanelsInPlaceContext extends DrupalSubContextBase { |
||
| 12 | |||
| 13 | /** |
||
| 14 | * The Mink context. |
||
| 15 | * |
||
| 16 | * @var MinkContext |
||
| 17 | */ |
||
| 18 | protected $minkContext; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Gathers required contexts. |
||
| 22 | * |
||
| 23 | * @BeforeScenario |
||
| 24 | */ |
||
| 25 | public function gatherContexts() { |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Returns the active Panels IPE tab's contents. |
||
| 31 | * |
||
| 32 | * @return \Behat\Mink\Element\NodeElement |
||
| 33 | * The active tab's contents. |
||
| 34 | */ |
||
| 35 | protected function getActiveTab() { |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Asserts the presence of the Panels IPE tray. |
||
| 42 | * |
||
| 43 | * @return \Behat\Mink\Element\NodeElement |
||
| 44 | * The Panels IPE tray element. |
||
| 45 | * |
||
| 46 | * @Then I should see the Panels IPE tray |
||
| 47 | */ |
||
| 48 | public function assertTray() { |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Opens a tab of the Panels IPE tray. |
||
| 54 | * |
||
| 55 | * @param string $tab |
||
| 56 | * The title of the tab to activate. |
||
| 57 | * |
||
| 58 | * @return \Behat\Mink\Element\NodeElement |
||
| 59 | * The tab contents. |
||
| 60 | * |
||
| 61 | * @When I open the :tab tab |
||
| 62 | */ |
||
| 63 | public function openTab($tab) { |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Close the Panels IPE tray. |
||
| 84 | * |
||
| 85 | * @When I close the editor |
||
| 86 | */ |
||
| 87 | public function closeEditor() { |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Opens a particular block category of the "Manage Content" tab. |
||
| 104 | * |
||
| 105 | * @param string $category |
||
| 106 | * The category to open. |
||
| 107 | * |
||
| 108 | * @return \Behat\Mink\Element\NodeElement |
||
| 109 | * The tab contents. |
||
| 110 | * |
||
| 111 | * @When I open the :category category |
||
| 112 | */ |
||
| 113 | public function openCategory($category) { |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Asserts that a particular block plugin is available. |
||
| 134 | * |
||
| 135 | * @param string $plugin_id |
||
| 136 | * The block plugin ID. |
||
| 137 | * @param string $category |
||
| 138 | * (optional) The category to open. |
||
| 139 | * |
||
| 140 | * @return \Behat\Mink\Element\NodeElement |
||
| 141 | * The link to instantiate the block plugin. |
||
| 142 | * |
||
| 143 | * @Then I should see the :plugin_id plugin |
||
| 144 | * @Then I should see the :plugin_id plugin in the :category category |
||
| 145 | */ |
||
| 146 | View Code Duplication | public function assertBlockPluginExists($plugin_id, $category = NULL) { |
|
| 154 | |||
| 155 | /** |
||
| 156 | * Asserts that a particular block plugin is not available. |
||
| 157 | * |
||
| 158 | * @param string $plugin_id |
||
| 159 | * The block plugin ID. |
||
| 160 | * @param string $category |
||
| 161 | * (optional) The category to open. |
||
| 162 | * |
||
| 163 | * @Then I should not see the :plugin_id plugin |
||
| 164 | * @Then I should not see the :plugin_id plugin in the :category category |
||
| 165 | */ |
||
| 166 | View Code Duplication | public function assertBlockPluginNotExists($plugin_id, $category = NULL) { |
|
| 174 | |||
| 175 | /** |
||
| 176 | * Instantiates a block plugin. |
||
| 177 | * |
||
| 178 | * @param string $plugin_id |
||
| 179 | * The block plugin ID. |
||
| 180 | * @param string $category |
||
| 181 | * (optional) The category in which the block plugin resides. |
||
| 182 | * |
||
| 183 | * @return \Behat\Mink\Element\NodeElement |
||
| 184 | * The block plugin configuration form. |
||
| 185 | * |
||
| 186 | * @When I instantiate the :plugin_id block |
||
| 187 | * @When I instantiate the :plugin_id block from the :category category |
||
| 188 | */ |
||
| 189 | public function instantiateBlock($plugin_id, $category = NULL) { |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Saves the current IPE layout. |
||
| 201 | * |
||
| 202 | * @When I save the layout |
||
| 203 | */ |
||
| 204 | public function saveLayout() { |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Saves the current IPE layout as a custom layout. |
||
| 212 | * |
||
| 213 | * @When I save the layout as custom |
||
| 214 | */ |
||
| 215 | View Code Duplication | public function saveLayoutAsCustom() { |
|
| 222 | |||
| 223 | /** |
||
| 224 | * Saves the current IPE layout as a default layout. |
||
| 225 | * |
||
| 226 | * @When I save the layout as default |
||
| 227 | */ |
||
| 228 | View Code Duplication | public function saveLayoutAsDefault() { |
|
| 235 | |||
| 236 | /** |
||
| 237 | * Places a block into a Panels IPE layout. |
||
| 238 | * |
||
| 239 | * @param string $plugin_id |
||
| 240 | * The block plugin ID. |
||
| 241 | * @param string $category |
||
| 242 | * (optional) The category in which the block plugin resides. |
||
| 243 | * |
||
| 244 | * @When I place the :plugin_id block from the :category category |
||
| 245 | * @When I place the :plugin_id block |
||
| 246 | */ |
||
| 247 | public function placeBlock($plugin_id, $category = NULL) { |
||
| 253 | |||
| 254 | /** |
||
| 255 | * Reverts a panelized layout to its default state. |
||
| 256 | * |
||
| 257 | * @When I revert the layout |
||
| 258 | */ |
||
| 259 | public function revertLayout() { |
||
| 266 | |||
| 267 | } |
||
| 268 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..