| Conditions | 10 |
| Paths | 32 |
| Total Lines | 51 |
| Code Lines | 38 |
| Lines | 18 |
| Ratio | 35.29 % |
| 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 |
||
| 103 | public function getStub() |
||
| 104 | { |
||
| 105 | $parser = $this->getNameParser(); |
||
| 106 | |||
| 107 | $action = $parser->getAction(); |
||
| 108 | switch ($action) { |
||
| 109 | case 'add': |
||
| 110 | case 'append': |
||
| 111 | case 'update': |
||
| 112 | View Code Duplication | case 'insert': |
|
| 113 | $file = 'change'; |
||
| 114 | $replacements = [ |
||
| 115 | 'class' => $this->getClass(), |
||
| 116 | 'table' => $parser->getTable(), |
||
| 117 | 'fields_up' => $this->getSchemaParser()->up(), |
||
| 118 | 'fields_down' => $this->getSchemaParser()->down(), |
||
| 119 | ]; |
||
| 120 | break; |
||
| 121 | |||
| 122 | case 'delete': |
||
| 123 | case 'remove': |
||
| 124 | View Code Duplication | case 'alter': |
|
| 125 | $file = 'change'; |
||
| 126 | $replacements = [ |
||
| 127 | 'class' => $this->getClass(), |
||
| 128 | 'table' => $parser->getTable(), |
||
| 129 | 'fields_down' => $this->getSchemaParser()->up(), |
||
| 130 | 'fields_up' => $this->getSchemaParser()->down(), |
||
| 131 | ]; |
||
| 132 | break; |
||
| 133 | default: |
||
| 134 | $file = 'create'; |
||
| 135 | $replacements = [ |
||
| 136 | 'class' => $this->getClass(), |
||
| 137 | 'table' => $parser->getTable(), |
||
| 138 | 'fields' => $this->getSchemaParser()->up(), |
||
| 139 | ]; |
||
| 140 | break; |
||
| 141 | } |
||
| 142 | $path = config('repository.generator.stubsOverridePath', __DIR__); |
||
| 143 | |||
| 144 | if (! file_exists($path."/Stubs/migration/{$file}.stub")) { |
||
| 145 | $path = __DIR__; |
||
| 146 | } |
||
| 147 | |||
| 148 | if (! file_exists($path."/Stubs/migration/{$file}.stub")) { |
||
| 149 | throw new FileNotFoundException($path."/Stubs/migration/{$file}.stub"); |
||
| 150 | } |
||
| 151 | |||
| 152 | return Stub::create($path."/Stubs/migration/{$file}.stub", $replacements); |
||
| 153 | } |
||
| 154 | } |
||
| 155 |
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.