| Conditions | 16 |
| Paths | 16 |
| Total Lines | 69 |
| Code Lines | 38 |
| 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 |
||
| 119 | public function validId($Id, $type = null): bool |
||
| 120 | { |
||
| 121 | if (!v::stringType()->notEmpty()->validate($Id)) { |
||
| 122 | return false; |
||
| 123 | } |
||
| 124 | |||
| 125 | switch ($type) { |
||
| 126 | case 'classPass': |
||
| 127 | |||
| 128 | $exploded = explode('-', $Id); |
||
| 129 | |||
| 130 | if (count($exploded) !== 2) { |
||
| 131 | return false; |
||
| 132 | } |
||
| 133 | |||
| 134 | if ($exploded[0] !== 'cp') { |
||
| 135 | return false; |
||
| 136 | } |
||
| 137 | |||
| 138 | return v::stringType()->notEmpty()->alnum()->length(12, 12)->validate($exploded[1]); |
||
| 139 | break; |
||
|
|
|||
| 140 | case 'event': |
||
| 141 | |||
| 142 | $exploded = explode('-', $Id); |
||
| 143 | |||
| 144 | if (count($exploded) !== 3) { |
||
| 145 | return false; |
||
| 146 | } |
||
| 147 | |||
| 148 | if ($exploded[0] !== 'ev') { |
||
| 149 | return false; |
||
| 150 | } |
||
| 151 | |||
| 152 | // Syntax. |
||
| 153 | if (!v::stringType()->notEmpty()->alnum()->length(4, 4)->validate($exploded[1])) { |
||
| 154 | return false; |
||
| 155 | } |
||
| 156 | |||
| 157 | return $this->validDate($exploded[2]); |
||
| 158 | break; |
||
| 159 | |||
| 160 | case 'ticket': |
||
| 161 | $exploded = explode('-', $Id); |
||
| 162 | |||
| 163 | if (count($exploded) !== 4) { |
||
| 164 | return false; |
||
| 165 | } |
||
| 166 | |||
| 167 | if ($exploded[0] !== 'ti') { |
||
| 168 | return false; |
||
| 169 | } |
||
| 170 | |||
| 171 | // Syntax. |
||
| 172 | if (!v::stringType()->notEmpty()->alnum()->length(4, 4)->validate($exploded[1])) { |
||
| 173 | return false; |
||
| 174 | } |
||
| 175 | |||
| 176 | if (!$this->validDate($exploded[2])) { |
||
| 177 | return false; |
||
| 178 | } |
||
| 179 | |||
| 180 | return v::stringType()->notEmpty()->alnum()->length(4, 4)->validate($exploded[3]); |
||
| 181 | break; |
||
| 182 | |||
| 183 | case 'attachment': |
||
| 184 | case 'location': |
||
| 185 | default: |
||
| 186 | return v::alnum()->length(12, 12)->validate($Id); |
||
| 187 | break; |
||
| 188 | } |
||
| 213 |
The
breakstatement is not necessary if it is preceded for example by areturnstatement:If you would like to keep this construct to be consistent with other
casestatements, you can safely mark this issue as a false-positive.