Passed
Push — main ( c89000...333101 )
by Andrey
01:24
created

HttpBuilderPrepare::suffix()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Helldar\Support\Tools;
4
5
use Helldar\Support\Concerns\Makeable;
6
7
final class HttpBuilderPrepare
8
{
9
    use Makeable;
10
11
    protected $of;
12
13
    protected $prefix = '';
14
15
    protected $suffix = '';
16
17
    protected $default = '';
18
19 12
    public function of(?string $value): self
20
    {
21 12
        $this->of = $value;
22
23 12
        return $this;
24
    }
25
26 12
    public function prefix(string $value): self
27
    {
28 12
        $this->prefix = $value;
29
30 12
        return $this;
31
    }
32
33 12
    public function suffix(string $value): self
34
    {
35 12
        $this->suffix = $value;
36
37 12
        return $this;
38
    }
39
40 12
    public function get(): ?string
41
    {
42 12
        if (! empty($this->of)) {
43 12
            return $this->prefexible();
44
        }
45
46 12
        return $this->default;
47
    }
48
49 12
    protected function getValue(): ?string
50
    {
51 12
        $characters = " \t\n\r\0\x0B" . $this->prefix . $this->suffix;
52
53 12
        return ! empty($this->of) ? trim($this->of, $characters) : null;
54
    }
55
56 12
    protected function prefexible(): ?string
57
    {
58 12
        return $this->prefix . $this->getValue() . $this->suffix;
59
    }
60
}
61