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 |
||
| 10 | class EA09PluginUninstallerCest |
||
| 11 | { |
||
| 12 | const ページタイトル = '#main .page-header'; |
||
| 13 | |||
| 14 | protected $plugins = []; |
||
| 15 | |||
| 16 | public function _before(\AcceptanceTester $I) |
||
| 17 | { |
||
| 18 | $fixtures = __DIR__.'/../_data/plugin_fixtures.php'; |
||
| 19 | if (file_exists($fixtures)) { |
||
| 20 | $this->plugins = require $fixtures; |
||
| 21 | } |
||
| 22 | $I->loginAsAdmin(); |
||
| 23 | } |
||
| 24 | |||
| 25 | public function _after(\AcceptanceTester $I) |
||
| 26 | { |
||
| 27 | } |
||
| 28 | |||
| 29 | public function plugin_プラグインアンインストール(\AcceptanceTester $I) |
||
| 30 | { |
||
| 31 | $I->wantTo('プラグインアンインストール'); |
||
| 32 | |||
| 33 | foreach ($this->plugins as $num => $plugin) { |
||
| 34 | |||
| 35 | // プラグイン無効化 |
||
| 36 | OwnersPluginPage::go($I)->無効にする($plugin['code']); |
||
| 37 | $I->see('プラグインを無効にしました。', OwnersPluginPage::$完了メッセージ); |
||
| 38 | } |
||
| 39 | |||
| 40 | foreach ($this->plugins as $num => $plugin) { |
||
| 41 | |||
| 42 | // プラグイン削除 |
||
| 43 | OwnersPluginPage::go($I)->削除($plugin['code']); |
||
| 44 | $I->see(' プラグインを削除しました。', OwnersPluginPage::$完了メッセージ); |
||
| 45 | } |
||
| 46 | } |
||
| 47 | } |
||
| 48 |