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 string
18
*/
19
private $type;
20
21
3
private function __construct(string $type)
22
{
23
3
$this->type = $type;
24
3
}
25
26
/**
27
* @throws InvalidArgumentException
28
*/
29
6
public static function build(string $type, Configuration $configuration): self
30
{
31
6
$type = trim($type);
32
6
$typeLength = strlen($type);
33
34
6
if ($typeLength > $configuration->maxLengthType() || $typeLength < $configuration->minLengthType()) {
35
2
$errorMessage = sprintf("Invalid length for type: '%s'. Must be between %s and %s",
36
2
$type,
37
2
$configuration->minLengthType(),
38
2
$configuration->maxLengthType()
39
);
40
2
throw new InvalidArgumentException($errorMessage);
41
}
42
43
4
if (!$configuration->acceptExtraType() && !in_array($type, $configuration->types(), true)) {
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.