| Conditions | 11 |
| Paths | 259 |
| Total Lines | 49 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 12 | public function init() |
||
| 13 | { |
||
| 14 | parent::init(); |
||
| 15 | |||
| 16 | if (!Permission::check("VIEW_DEVTASKS")) { |
||
| 17 | return; |
||
| 18 | } |
||
| 19 | |||
| 20 | $default_tasks = array( |
||
| 21 | 'devbuild' => array( |
||
| 22 | 'title' => 'Dev/Build', |
||
| 23 | 'link' => 'dev/build', |
||
| 24 | 'reset_time' => '5000', |
||
| 25 | 'error_markup'=> '.xdebug-error,.xe-parse-error', |
||
| 26 | 'error_handler' => 'newtab', |
||
| 27 | 'success_markup'=> 'li[style="color: blue"],li[style="color: green"]', |
||
| 28 | 'success_handler' => 'ignore' |
||
| 29 | ) |
||
| 30 | ); |
||
| 31 | |||
| 32 | $config_tasks = Config::inst()->get(__CLASS__, 'tasks'); |
||
| 33 | |||
| 34 | if (is_array($config_tasks)) { |
||
| 35 | $tasks = array_merge($default_tasks, $config_tasks); |
||
| 36 | }else{ |
||
| 37 | $tasks = $default_tasks; |
||
| 38 | } |
||
| 39 | |||
| 40 | foreach ($tasks as $item => $values) { |
||
| 41 | |||
| 42 | $attributes = array( |
||
| 43 | 'class' => 'devbuild-trigger', |
||
| 44 | 'data-title' => (isset($values['title']) ? $values['title'] : $item), |
||
| 45 | 'data-link' => (isset($values['link']) ? $values['link'] : $default_tasks['devbuild']['link']), |
||
| 46 | 'data-reset-time' => (isset($values['reset_time']) ? $values['reset_time'] : $default_tasks['devbuild']['reset_time']), |
||
| 47 | 'data-error-markup' => (isset($values['error_markup']) ? $values['error_markup'] : $default_tasks['devbuild']['error_markup']), |
||
| 48 | 'data-error-handler' => (isset($values['error_handler']) ? $values['error_handler'] : $default_tasks['devbuild']['error_handler']), |
||
| 49 | 'data-success-markup' => (isset($values['success_markup']) ? $values['success_markup'] : $default_tasks['devbuild']['success_markup']), |
||
| 50 | 'data-success-handler' => (isset($values['success_handler']) ? $values['success_handler'] : $default_tasks['devbuild']['success_handler']) |
||
| 51 | ); |
||
| 52 | |||
| 53 | // priority controls the ordering of the link in the stack. The |
||
| 54 | // lower the number, the lower in the list |
||
| 55 | $priority = -90; |
||
| 56 | |||
| 57 | CMSMenu::add_link($item, '', '#', $priority, $attributes); |
||
| 58 | |||
| 59 | } |
||
| 60 | } |
||
| 61 | |||
| 72 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.