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