Passed
Pull Request — master (#44)
by
unknown
02:03
created

ConfigurationSerializer::toJson()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LTDBeget\sphinx\configurator;
6
7
use LTDBeget\sphinx\configurator\serializers\ArraySerializer;
8
use LTDBeget\sphinx\configurator\serializers\JsonSerializer;
9
use LTDBeget\sphinx\configurator\serializers\PlainSerializer;
10
11
class ConfigurationSerializer
12
{
13
    private $configuration;
14
15 3
    public function __construct(Configuration $configuration)
16
    {
17 3
        $this->configuration = $configuration;
18 3
    }
19
20
    /**
21
     * @return string
22
     * @throws \LTDBeget\sphinx\configurator\exceptions\ConfigurationException
23
     */
24 3
    public function toString(): string
25
    {
26 3
        return PlainSerializer::serialize($this->configuration);
27
    }
28
29
    /**
30
     * @return string
31
     * @throws \LogicException
32
     * @throws \LTDBeget\sphinx\configurator\exceptions\SectionException
33
     * @throws \InvalidArgumentException
34
     * @throws \LTDBeget\sphinx\configurator\exceptions\ConfigurationException
35
     */
36 1
    public function toJson(): string
37
    {
38 1
        return JsonSerializer::serialize($this->configuration);
39
    }
40
41
    /**
42
     * @return array
43
     * @throws \InvalidArgumentException
44
     * @throws \LTDBeget\sphinx\configurator\exceptions\SectionException
45
     * @throws \LogicException
46
     * @throws \LTDBeget\sphinx\configurator\exceptions\ConfigurationException
47
     */
48 1
    public function toArray(): array
49
    {
50 1
        return ArraySerializer::serialize($this->configuration);
51
    }
52
}
53