| Conditions | 14 | 
| Paths | 39 | 
| Total Lines | 54 | 
| Code Lines | 35 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 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 | ||
| 53 | public function handle() | ||
| 54 |     { | ||
| 55 |         $delete = $this->option('delete'); | ||
| 56 |         if ($this->option('pop') || $delete) { | ||
| 57 |             if ($delete) { | ||
| 58 | $device = Device::find($delete); | ||
| 59 |             } else { | ||
| 60 |                 $device = Device::orderBy('device_id', 'desc')->first(); | ||
| 61 | } | ||
| 62 | |||
| 63 | $device->delete(); | ||
| 64 | return; | ||
| 65 | } | ||
| 66 | |||
| 67 |         if ($this->option('list') || is_null($this->option())) { | ||
| 68 | event(new ListDevices()); | ||
| 69 | echo "Sending Device List Event\n"; | ||
| 70 |         } else { | ||
| 71 | // Fire off an event, just randomly grabbing the first user for now | ||
| 72 |             $id = $this->option('id'); | ||
| 73 | |||
| 74 |             if ($id == 'all') { | ||
| 75 |                 $this->info('all'); | ||
| 76 | $devices = Device::all(); | ||
| 77 |             } elseif ($this->option('push')) { | ||
| 78 |                 $this->info('push'); | ||
| 79 | $devices = [new Device(['hostname' => 'Mockery'])]; | ||
| 80 |             } elseif ($id === null) { | ||
| 81 |                 $this->info('first'); | ||
| 82 | $devices = [Device::first()]; | ||
| 83 |             } else { | ||
| 84 |                 $this->info('findOrNew'); | ||
| 85 | $devices = [Device::findOrNew($id)]; | ||
| 86 | } | ||
| 87 | |||
| 88 | /** @var Device $device */ | ||
| 89 |             foreach ($devices as $device) { | ||
| 90 |                 if ($this->option('status') !== null) { | ||
| 91 |                     $device->status = $this->option('status'); | ||
| 92 | } | ||
| 93 | |||
| 94 |                 if ($this->option('uptime') !== null) { | ||
| 95 |                     $device->uptime = $this->option('uptime'); | ||
| 96 | } | ||
| 97 | |||
| 98 | $device->save(); | ||
| 99 | |||
| 100 |                 if (empty($device->hostname) || $device->hostname == 'Mockery') { | ||
| 101 | $device->hostname = 'Mockery'.$device->device_id; | ||
| 102 | $device->save(); | ||
| 103 | } | ||
| 104 | } | ||
| 105 | } | ||
| 106 | } | ||
| 107 | } | ||
| 108 |