Passed
Push — master ( 2e278f...341743 )
by Dominik
02:18
created

FieldMapping::getName()   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
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Serialization\Mapping;
6
7
use Chubbyphp\Serialization\Accessor\PropertyAccessor;
8
use Chubbyphp\Serialization\Serializer\Field\FieldSerializerInterface;
9
use Chubbyphp\Serialization\Serializer\Field\ValueSerializer;
10
11
final class FieldMapping implements FieldMappingInterface
12
{
13
    /**
14
     * @var string
15
     */
16
    private $name;
17
18
    /**
19
     * @var FieldSerializerInterface
20
     */
21
    private $fieldSerializer;
22
23
    /**
24
     * @param string                        $name
25
     * @param FieldSerializerInterface|null $fieldSerializer
26
     */
27 1
    public function __construct(string $name, FieldSerializerInterface $fieldSerializer = null)
28
    {
29 1
        $this->name = $name;
30 1
        $this->fieldSerializer = $fieldSerializer ?? new ValueSerializer(new PropertyAccessor($name));
31 1
    }
32
33
    /**
34
     * @return string
35
     */
36 1
    public function getName(): string
37
    {
38 1
        return $this->name;
39
    }
40
41
    /**
42
     * @return FieldSerializerInterface
43
     */
44 1
    public function getFieldSerializer(): FieldSerializerInterface
45
    {
46 1
        return $this->fieldSerializer;
47
    }
48
}
49