| Conditions | 14 |
| Paths | 72 |
| Total Lines | 47 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 210 |
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 |
||
| 39 | public function fire() |
||
| 40 | { |
||
| 41 | $options = $this->option(); |
||
| 42 | $newPost = []; |
||
| 43 | |||
| 44 | //POST TYPE |
||
| 45 | $options['type'] = strtolower($options['type']); |
||
| 46 | if ($options['type'] and ($options['type'] == 'article' or $options['type'] == 'page')) { |
||
| 47 | $newPost['type'] = $options['type']; |
||
| 48 | } else { |
||
| 49 | $newPost['type'] = $this->ask("What's the post type? draft/article/page"); |
||
| 50 | if ($newPost['type'] != 'page' or $newPost['type'] != 'article') { |
||
| 51 | $newPost['type'] = 'draft'; |
||
| 52 | } |
||
| 53 | } |
||
| 54 | //COMMENTS |
||
| 55 | $options['comments'] = strtolower($options['comments']); |
||
| 56 | if ($options['comments'] and ($options['comments'] == 'y' or $options['comments'] == 'n')) { |
||
| 57 | $newPost['comments'] = $options['comments']; |
||
| 58 | } else { |
||
| 59 | $newPost['comments'] = $this->ask('Enable comments? y/n'); |
||
| 60 | if ($newPost['comments'] == 'n') { |
||
| 61 | $newPost['comments'] = false; |
||
| 62 | } else { |
||
| 63 | $newPost['comments'] = true; |
||
| 64 | } |
||
| 65 | } |
||
| 66 | //title |
||
| 67 | if ($options['title']) { |
||
| 68 | $newPost['title'] = $options['title']; |
||
| 69 | } else { |
||
| 70 | while (true) { |
||
| 71 | $newPost['title'] = $this->ask("What's the title of post?"); |
||
| 72 | if ($newPost['title']) { |
||
| 73 | break; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | if ($options['post']) { |
||
| 79 | $newPost['post'] = $options['post']; |
||
| 80 | } else { |
||
| 81 | $newPost['post'] = $this->ask("What's the content of post?"); |
||
| 82 | } |
||
| 83 | $this->info($this->post->store($newPost)); |
||
| 84 | $this->call('cache:clear'); |
||
| 85 | } |
||
| 86 | |||
| 112 |
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.