Conditions | 3 |
Paths | 3 |
Total Lines | 18 |
Lines | 18 |
Ratio | 100 % |
Tests | 9 |
CRAP Score | 3 |
Changes | 0 |
1 | <?php |
||
26 | 17 | public function createAccount(string $number): AccountNumber |
|
27 | { |
||
28 | 17 | if (!preg_match('/^0*(\d{3,4})-?(\d{3})(\d)$/', $number, $matches)) { |
|
29 | 12 | throw new InvalidAccountNumberException("Invalid bankgiro account number structure"); |
|
30 | } |
||
31 | |||
32 | 5 | $account = new Bankgiro($number, $matches[1].$matches[2], $matches[3]); |
|
33 | |||
34 | 5 | $result = $this->validator->validate($account); |
|
35 | |||
36 | 5 | if (!$result->isValid()) { |
|
37 | 1 | throw new InvalidAccountNumberException( |
|
38 | 1 | "Unable to parse bankgiro $number: {$result->getMessage()}" |
|
39 | ); |
||
40 | } |
||
41 | |||
42 | 4 | return $account; |
|
43 | } |
||
44 | } |
||
45 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.