Conditions | 10 |
Paths | 17 |
Total Lines | 38 |
Lines | 14 |
Ratio | 36.84 % |
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 |
||
54 | public function validate() |
||
55 | { |
||
56 | if (empty($this->argument('name'))) { |
||
57 | $this->listConfigurations(); |
||
58 | |||
59 | return false; |
||
60 | } |
||
61 | $harvestConfig = \Config::get('oaipmh.harvests.' . $this->argument('name'), null); |
||
62 | if (is_null($harvestConfig)) { |
||
63 | $this->error('Unknown configuration specified.'); |
||
64 | $this->listConfigurations(); |
||
65 | |||
66 | return false; |
||
67 | } |
||
68 | if ($this->option('daily')) { |
||
69 | if ($this->option('from') || $this->option('until')) { |
||
70 | $this->error('--daily cannot be combined with --from / --until.'); |
||
71 | |||
72 | return false; |
||
73 | } |
||
74 | } |
||
75 | View Code Duplication | if ($this->option('from')) { |
|
76 | if (!preg_match('/[0-9]{4}-[0-9]{2}-[0-9]{2}/', $this->option('from'))) { |
||
77 | $this->error('--from must be on ISO-format YYYY-MM-DD.'); |
||
78 | |||
79 | return false; |
||
80 | } |
||
81 | } |
||
82 | View Code Duplication | if ($this->option('until')) { |
|
83 | if (!preg_match('/[0-9]{4}-[0-9]{2}-[0-9]{2}/', $this->option('until'))) { |
||
84 | $this->error('--until must be on ISO-format YYYY-MM-DD.'); |
||
85 | |||
86 | return false; |
||
87 | } |
||
88 | } |
||
89 | |||
90 | return true; |
||
91 | } |
||
92 | |||
132 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.