Description   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 39
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A build() 0 18 3
A __toString() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Damianopetrungaro\PHPCommitizen\Section;
6
7
use Damianopetrungaro\PHPCommitizen\Configuration;
8
use Damianopetrungaro\PHPCommitizen\Exception\InvalidArgumentException;
9
use function strlen;
10
11
class Description
12
{
13
    /**
14
     * @var string
15
     */
16
    private $description;
17
18 5
    private function __construct(string $description)
19
    {
20 5
        $this->description = $description;
21 5
    }
22
23
    /**
24
     * @throws InvalidArgumentException
25
     */
26 8
    public static function build(string $description, Configuration $configuration): self
27
    {
28 8
        $description = trim($description);
29 8
        $descriptionLength = strlen($description);
30
31 8
        if ($descriptionLength > $configuration->maxLengthDescription() ||
32 8
            $descriptionLength < $configuration->minLengthDescription()
33
        ) {
34 3
            $errorMessage = sprintf("Invalid length for description: '%s'. Must be between %s and %s",
35 3
                $description,
36 3
                $configuration->minLengthDescription(),
37 3
                $configuration->maxLengthDescription()
38
            );
39 3
            throw new InvalidArgumentException($errorMessage);
40
        }
41
42 5
        return new self($description);
43
    }
44
45 5
    public function __toString(): string
46
    {
47 5
        return $this->description;
48
    }
49
}