| Conditions | 13 |
| Paths | 5 |
| Total Lines | 31 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 32 | public static function generate(DateTime $birthDate, string $gender, ?int $orderNumber = null, string $type) |
||
| 33 | { |
||
| 34 | // Checks orderNumber |
||
| 35 | if ($orderNumber !== null && ($orderNumber < 1 || $orderNumber > 999)) { |
||
| 36 | throw new InvalidArgumentException('The order number must be null or between 1 and 999.'); |
||
| 37 | } |
||
| 38 | |||
| 39 | // Checks gender |
||
| 40 | if ($gender !== NISS::GENDER_FEMALE && $gender !== NISS::GENDER_MALE && $gender !== NISS::GENDER_UNKNOWN) { |
||
| 41 | throw new InvalidArgumentException('The gender must be null, F or M. Given: ' . $gender); |
||
| 42 | } |
||
| 43 | |||
| 44 | // TODO: Function + match bis and gender unknown |
||
| 45 | // check if order number matches the gender |
||
| 46 | if ($orderNumber == !null && $gender !== NISS::GENDER_UNKNOWN) { |
||
| 47 | $isEven = $orderNumber % 2 == 0; |
||
| 48 | if (($isEven && $gender === NISS::GENDER_MALE) || (!$isEven && $gender === NISS::GENDER_FEMALE)) { |
||
| 49 | throw new InvalidArgumentException('The gender does not match the order number.'); |
||
| 50 | } |
||
| 51 | } |
||
| 52 | |||
| 53 | // generate the dob string matching the type |
||
| 54 | $birthString = self::modifyDateOfBirth($birthDate, $type, $gender); |
||
| 55 | |||
| 56 | // generate the order number, matching the gender |
||
| 57 | $orderString = self::generateStringOrderNumber($orderNumber, $gender); |
||
| 58 | |||
| 59 | // generate the control number |
||
| 60 | $controlNumber = self::generateStringControlNumber($birthDate, $birthString, $orderString); |
||
| 61 | |||
| 62 | return $birthString . $orderString . $controlNumber; |
||
| 63 | } |
||
| 153 |