PrefixAppendFormatter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 27
ccs 8
cts 8
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A formatName() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lamoda\MultiEnv\Formatter;
6
7
use Lamoda\MultiEnv\Formatter\Exception\FormatterException;
8
use Lamoda\MultiEnv\Model\HostId;
9
10
final class PrefixAppendFormatter implements FormatterInterface
11
{
12
    /**
13
     * @var string $delimiter
14
     */
15
    private $delimiter;
16
17 14
    public function __construct(string $delimiter = '')
18
    {
19 14
        $this->delimiter = trim($delimiter);
20 14
    }
21
22
    /**
23
     * @param string $originalName
24
     * @param HostId $hostId
25
     * @throws FormatterException
26
     * @return string
27
     */
28 42
    public function formatName(string $originalName, HostId $hostId): string
29
    {
30 42
        $originalName = trim($originalName);
31
32 42
        if (empty($originalName)) {
33 4
            throw FormatterException::becauseEmptyNamePassed();
34
        }
35
36 38
        return $hostId . $this->delimiter . $originalName;
37
    }
38
}
39