HttpBuilderPrepare::prefixed()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 10
1
<?php
2
/*
3
 * This file is part of the "andrey-helldar/support" project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author Andrey Helldar <[email protected]>
9
 *
10
 * @copyright 2021 Andrey Helldar
11
 *
12
 * @license MIT
13
 *
14
 * @see https://github.com/andrey-helldar/support
15
 */
16
17
namespace Helldar\Support\Tools;
18
19
use Helldar\Contracts\Support\Stringable;
20
use Helldar\Support\Concerns\Makeable;
21
use Helldar\Support\Facades\Helpers\Str;
22
23
class HttpBuilderPrepare implements Stringable
24
{
25
    use Makeable;
26
27
    protected $of;
28
29
    protected $prefix = '';
30
31
    protected $suffix = '';
32
33
    protected $default = '';
34
35 21
    public function __toString()
36
    {
37 21
        if (! empty($this->of)) {
38 18
            return $this->prefixed();
39
        }
40
41 16
        return $this->default;
42
    }
43
44 21
    public function of(?string $value): self
45
    {
46 21
        $this->of = $value;
47
48 21
        return $this;
49
    }
50
51 21
    public function prefix(string $value): self
52
    {
53 21
        $this->prefix = $value;
54
55 21
        return $this;
56
    }
57
58 21
    public function suffix(string $value): self
59
    {
60 21
        $this->suffix = $value;
61
62 21
        return $this;
63
    }
64
65 18
    protected function prefixed(): ?string
66
    {
67 18
        return (string) Str::of($this->of)
68 18
            ->start($this->prefix)
69 18
            ->finish($this->suffix)
70 18
            ->trim();
71
    }
72
}
73