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

FieldMapping   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 38
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2
ccs 8
cts 8
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getName() 0 4 1
A getFieldSerializer() 0 4 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