Conditions | 11 |
Paths | 1024 |
Total Lines | 39 |
Code Lines | 27 |
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 |
||
73 | public function handle() |
||
74 | { |
||
75 | $locations = Location::all(['id', 'short', 'long']); |
||
76 | |||
77 | $this->data['name'] = (is_null($this->option('name'))) ? $this->ask('Node Name') : $this->option('name'); |
||
78 | |||
79 | if (is_null($this->option('location'))) { |
||
80 | $this->table(['ID', 'Short Code', 'Description'], $locations->toArray()); |
||
81 | $selectedLocation = $this->anticipate('Node Location (Short Name)', $locations->pluck('short')->toArray()); |
||
82 | } else { |
||
83 | $selectedLocation = $this->option('location'); |
||
84 | } |
||
85 | |||
86 | $this->data['location_id'] = $locations->where('short', $selectedLocation)->first()->id; |
||
87 | |||
88 | if (is_null($this->option('fqdn'))) { |
||
89 | $this->line('Please enter domain name (e.g node.example.com) to be used for connecting to the daemon. An IP address may only be used if you are not using SSL for this node.'); |
||
90 | $this->data['fqdn'] = $this->ask('Fully Qualified Domain Name'); |
||
91 | } else { |
||
92 | $this->data['fqdn'] = $this->option('fqdn'); |
||
93 | } |
||
94 | |||
95 | $useSSL = (is_null($this->option('ssl'))) ? $this->confirm('Use SSL', true) : $this->option('ssl'); |
||
96 | |||
97 | $this->data['scheme'] = ($useSSL) ? 'https' : 'http'; |
||
98 | $this->data['memory'] = (is_null($this->option('memory'))) ? $this->ask('Total Memory (in MB)') : $this->option('memory'); |
||
99 | $this->data['memory_overallocate'] = 0; |
||
100 | $this->data['disk'] = (is_null($this->option('disk'))) ? $this->ask('Total Disk Space (in MB)') : $this->option('disk'); |
||
101 | $this->data['disk_overallocate'] = 0; |
||
102 | $this->data['public'] = 1; |
||
103 | $this->data['daemonBase'] = (is_null($this->option('daemonBase'))) ? $this->ask('Daemon Server File Location', '/srv/daemon-data') : $this->option('daemonBase'); |
||
104 | $this->data['daemonListen'] = (is_null($this->option('daemonListen'))) ? $this->ask('Daemon Listening Port', 8080) : $this->option('daemonListen'); |
||
105 | $this->data['daemonSFTP'] = (is_null($this->option('daemonSFTP'))) ? $this->ask('Daemon SFTP Port', 2022) : $this->option('daemonSFTP'); |
||
106 | |||
107 | $repo = new NodeRepository; |
||
108 | $id = $repo->create($this->data); |
||
109 | |||
110 | $this->info('Node created with ID: ' . $id); |
||
111 | } |
||
112 | } |
||
113 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.