| Conditions | 12 |
| Paths | 1 |
| Total Lines | 96 |
| Code Lines | 67 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 80 | public function __construct( |
||
| 81 | Application $app, |
||
| 82 | Config $config |
||
| 83 | ) { |
||
| 84 | $this->application = $app; |
||
| 85 | $this->config = $config; |
||
| 86 | |||
| 87 | $this->setName('maintenance') |
||
| 88 | ->setDescription('Command to manage application maintenance'); |
||
| 89 | |||
| 90 | $this->addArgument('type', 'type of action [up|down|status]', 'status', true, true, false, function ($val) { |
||
| 91 | if (!in_array($val, ['up', 'down', 'status'])) { |
||
| 92 | throw new RuntimeException(sprintf( |
||
| 93 | 'Invalid argument type [%s], must be one of [up, down, status]', |
||
| 94 | $val |
||
| 95 | )); |
||
| 96 | } |
||
| 97 | |||
| 98 | return $val; |
||
| 99 | }); |
||
| 100 | |||
| 101 | $this->addOption( |
||
| 102 | '-t|--template', |
||
| 103 | 'The template that should be rendered for display during maintenance mode', |
||
| 104 | null, |
||
| 105 | false, |
||
| 106 | true |
||
| 107 | ); |
||
| 108 | |||
| 109 | $this->addOption( |
||
| 110 | '-r|--retry', |
||
| 111 | 'The number of seconds after which the request may be retried', |
||
| 112 | 3600, |
||
| 113 | false, |
||
| 114 | true, |
||
| 115 | false, |
||
| 116 | function ($val) { |
||
| 117 | if (strlen($val) > 0 && (!is_numeric($val) || (int) $val <= 0)) { |
||
| 118 | throw new RuntimeException(sprintf( |
||
| 119 | 'Invalid retry value [%s], must be an integer greather than zero', |
||
| 120 | $val |
||
| 121 | )); |
||
| 122 | } |
||
| 123 | |||
| 124 | return $val; |
||
| 125 | } |
||
| 126 | ); |
||
| 127 | $this->addOption( |
||
| 128 | '-e|--refresh', |
||
| 129 | 'The number of seconds after which the browser may refresh', |
||
| 130 | 3600, |
||
| 131 | false, |
||
| 132 | true, |
||
| 133 | false, |
||
| 134 | function ($val) { |
||
| 135 | if (strlen($val) > 0 && (!is_numeric($val) || (int) $val <= 0)) { |
||
| 136 | throw new RuntimeException(sprintf( |
||
| 137 | 'Invalid refresh value [%s], must be an integer greather than zero', |
||
| 138 | $val |
||
| 139 | )); |
||
| 140 | } |
||
| 141 | |||
| 142 | return $val; |
||
| 143 | } |
||
| 144 | ); |
||
| 145 | $this->addOption( |
||
| 146 | '-s|--secret', |
||
| 147 | 'The secret phrase that may be used to bypass maintenance mode', |
||
| 148 | null, |
||
| 149 | false, |
||
| 150 | true |
||
| 151 | ); |
||
| 152 | $this->addOption( |
||
| 153 | '-c|--status', |
||
| 154 | 'The status code that should be used when returning the maintenance mode response', |
||
| 155 | 503, |
||
| 156 | false, |
||
| 157 | true, |
||
| 158 | false, |
||
| 159 | function ($val) { |
||
| 160 | if (strlen($val) > 0 && (!is_numeric($val) || (int) $val < 200 || (int) $val > 505)) { |
||
| 161 | throw new RuntimeException(sprintf( |
||
| 162 | 'Invalid HTTP status value [%s], must be between 200 and 505', |
||
| 163 | $val |
||
| 164 | )); |
||
| 165 | } |
||
| 166 | |||
| 167 | return $val; |
||
| 168 | } |
||
| 169 | ); |
||
| 170 | $this->addOption( |
||
| 171 | '-m|--message', |
||
| 172 | 'The message that will be shown to user during maintenance mode', |
||
| 173 | null, |
||
| 174 | false, |
||
| 175 | true |
||
| 176 | ); |
||
| 297 |