This class seems to be duplicated in your project.
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.
Loading history...
15
{
16
/**
17
* @var ValidatorInterface
18
*/
19
private $validator;
20
21
17
public function __construct()
22
{
23
17
$this->validator = new CheckDigitType2Validator;
24
17
}
25
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()}"
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.