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 |
||
| 16 | class PageModule extends app\components\BaseModule implements EventInterface |
||
| 17 | { |
||
| 18 | const BACKEND_PAGE_GRID = 'pageGrid'; |
||
| 19 | /** |
||
| 20 | * @var int minimum pages per list to show |
||
| 21 | */ |
||
| 22 | public $minPagesPerList = 1; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var int maximum pages per list to show |
||
| 26 | */ |
||
| 27 | public $maxPagesPerList = 50; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var int pages per list to show |
||
| 31 | */ |
||
| 32 | public $pagesPerList = 10; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var int How much pages to show on search results page |
||
| 36 | */ |
||
| 37 | public $searchResultsLimit = 10; |
||
| 38 | |||
| 39 | public $controllerMap = [ |
||
| 40 | 'backend' => 'app\modules\page\backend\PageController', |
||
| 41 | ]; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @inheritdoc |
||
| 45 | */ |
||
| 46 | public function behaviors() |
||
| 56 | |||
| 57 | /** @inheritdoc */ |
||
| 58 | public function getBackendGrids() |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @return void |
||
| 71 | */ |
||
| 72 | public static function attachEventsHandlers() |
||
| 93 | } |
||
| 94 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: