| Conditions | 7 |
| Paths | 48 |
| Total Lines | 81 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 defined('SYSPATH') OR die('No direct script access.'); |
||
| 37 | protected function _execute(array $options) |
||
| 38 | { |
||
| 39 | $module_name = $options['module'] ?: 'applicaiton'; |
||
| 40 | $module_dir = $options['module'] ? Arr::get(Kohana::modules(), $module_name) : APPPATH; |
||
| 41 | |||
| 42 | $author = $options['author'] ?: '-'; |
||
| 43 | |||
| 44 | $name = $options['name']; |
||
| 45 | $title = Jam::capitalize_class_name(str_replace('_', ' ', $name)); |
||
| 46 | $path = str_replace('_', DIRECTORY_SEPARATOR, $title); |
||
| 47 | |||
| 48 | $dir = $module_dir.'classes'.DIRECTORY_SEPARATOR.'Model'; |
||
| 49 | $file = $dir.DIRECTORY_SEPARATOR.$path.EXT; |
||
| 50 | $class ='Model_'.str_replace(' ', '_', $title); |
||
| 51 | |||
| 52 | if ( ! is_dir(dirname($file))) |
||
| 53 | { |
||
| 54 | mkdir(dirname($file), 0777, TRUE); |
||
| 55 | } |
||
| 56 | |||
| 57 | $content = <<<MODEL |
||
| 58 | <?php defined('SYSPATH') OR die('No direct script access.'); |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Jam Model: $title |
||
| 62 | * |
||
| 63 | * @package $module_name |
||
| 64 | * @author $author |
||
| 65 | * @copyright (c) 2011-2013 Despark Ltd. |
||
| 66 | */ |
||
| 67 | class {$class} extends Jam_Model { |
||
| 68 | |||
| 69 | public static function initialize(Jam_Meta \$meta) |
||
| 70 | { |
||
| 71 | \$meta |
||
| 72 | ->associations(array( |
||
| 73 | )) |
||
| 74 | |||
| 75 | ->fields(array( |
||
| 76 | 'id' => Jam::field('primary'), |
||
| 77 | 'name' => Jam::field('string'), |
||
| 78 | )) |
||
| 79 | |||
| 80 | ->validator('name', array('present' => TRUE)); |
||
| 81 | } |
||
| 82 | } |
||
| 83 | MODEL; |
||
| 84 | |||
| 85 | Minion_Jam_Generate::modify_file($file, $content, $options['force'] !== FALSE, $options['unlink'] !== FALSE); |
||
| 86 | |||
| 87 | if ($options['collection'] !== FALSE) |
||
| 88 | { |
||
| 89 | |||
| 90 | $dir = $module_dir.'classes'.DIRECTORY_SEPARATOR.'model'.DIRECTORY_SEPARATOR.'collection'; |
||
| 91 | $file = $dir.DIRECTORY_SEPARATOR.$path.EXT; |
||
| 92 | $class ='Model_Collection_'.str_replace(' ', '_', $title); |
||
| 93 | |||
| 94 | if ( ! is_dir(dirname($file))) |
||
| 95 | { |
||
| 96 | mkdir(dirname($file), 0777, TRUE); |
||
| 97 | } |
||
| 98 | |||
| 99 | $content = <<<COLLECTION |
||
| 100 | <?php defined('SYSPATH') OR die('No direct script access.'); |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Collection for $title |
||
| 104 | * |
||
| 105 | * @package $module_name |
||
| 106 | * @author $author |
||
| 107 | * @copyright (c) 2011-2013 Despark Ltd. |
||
| 108 | */ |
||
| 109 | class {$class} extends Jam_Query_Builder_Collection { |
||
| 110 | |||
| 111 | |||
| 112 | } |
||
| 113 | COLLECTION; |
||
| 114 | Minion_Jam_Generate::modify_file($file, $content, $options['force'] !== FALSE, $options['unlink'] !== FALSE); |
||
| 115 | } |
||
| 116 | |||
| 117 | } |
||
| 118 | } |
||
| 119 |