| Conditions | 15 |
| Paths | 81 |
| Total Lines | 82 |
| Code Lines | 44 |
| 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 |
||
| 23 | public function main() { |
||
| 24 | |||
| 25 | $this->clear(); |
||
| 26 | |||
| 27 | $this->helper('Multidimensional/Subdomains.Header')->output(); |
||
| 28 | |||
| 29 | $subdomains = $this->_getSubdomains(); |
||
| 30 | |||
| 31 | if ($this->_countSubdomains($subdomains) ? $this->_askInstall() : $this->_askUpdate()) { |
||
| 32 | |||
| 33 | do { |
||
| 34 | |||
| 35 | $addMore = true; |
||
| 36 | |||
| 37 | if ($this->_countSubdomains($subdomains)) { |
||
| 38 | |||
| 39 | $subdomains = array_values(array_unique($subdomains)); |
||
| 40 | $subdomains = $this->_modifyArray($subdomains); |
||
| 41 | $this->_currentSubdomains($subdomains); |
||
| 42 | $addMore = $this->_askAddSubdomain(); |
||
| 43 | |||
| 44 | } |
||
| 45 | |||
| 46 | if ($addMore) { |
||
| 47 | |||
| 48 | if (!$this->_countSubdomains($subdomains)) { |
||
|
1 ignored issue
–
show
|
|||
| 49 | $this->out(); |
||
| 50 | $this->out('Add your first subdomain.'); |
||
| 51 | } |
||
| 52 | |||
| 53 | do { |
||
| 54 | |||
| 55 | $this->out(); |
||
| 56 | |||
| 57 | $subdomain = $this->in('Subdomain:'); |
||
| 58 | $valid = $this->_validateSubdomain($subdomain); |
||
| 59 | |||
| 60 | $this->out(); |
||
| 61 | |||
| 62 | if ($valid) { |
||
| 63 | $subdomains[] = $subdomain; |
||
| 64 | } else { |
||
| 65 | $this->err('Invalid subdomain.'); |
||
| 66 | } |
||
| 67 | |||
| 68 | } while (!$valid || $this->_askAddSubdomain()); |
||
| 69 | |||
| 70 | } |
||
| 71 | |||
| 72 | $subdomains = array_values(array_unique($subdomains)); |
||
| 73 | |||
| 74 | $subdomains = $this->_modifyArray($subdomains); |
||
| 75 | |||
| 76 | $this->_currentSubdomains($subdomains); |
||
| 77 | |||
| 78 | while ($this->_countSubdomains($subdomains) && $this->_askDeleteSubdomain()) { |
||
| 79 | |||
| 80 | $this->out(); |
||
| 81 | $deleteKey = (int) $this->in('Enter number to delete:', array_keys($subdomains)); |
||
| 82 | $this->_deleteSubdomain($subdomains, $deleteKey); |
||
| 83 | |||
| 84 | } |
||
| 85 | |||
| 86 | Configure::write('Multidimensional/Subdomains.subdomains', array_values($subdomains)); |
||
| 87 | Configure::dump('subdomains', 'default', ['Multidimensional/Subdomains']); |
||
| 88 | |||
| 89 | if (!$this->_countSubdomains($subdomains)) { |
||
|
1 ignored issue
–
show
|
|||
| 90 | $this->out(); |
||
| 91 | $this->err('No subdomains configured.', 2); |
||
| 92 | } |
||
| 93 | |||
| 94 | } while (!$this->_countSubdomains($subdomains) && $this->_askStartOver()); |
||
|
1 ignored issue
–
show
|
|||
| 95 | |||
| 96 | $this->out(); |
||
| 97 | if ($this->_countSubdomains($subdomains)) { |
||
| 98 | $this->out('Configuration saved!', 2); |
||
| 99 | } else { |
||
| 100 | $this->err('Plugin not currently active.', 2); |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | } |
||
| 105 | |||
| 228 | } |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: