Completed
Pull Request — master (#39)
by Daniel
04:05
created

hasPropertyNameConverterStrategy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Jellyfish\SerializerSymfony;
4
5
use Jellyfish\Serializer\NameConverter\PropertyNameConverterStrategyInterface;
6
use Jellyfish\Serializer\SerializerFacadeInterface;
7
8
class SerializerSymfonyFacade implements SerializerFacadeInterface
9
{
10
    /**
11
     * @var \Jellyfish\SerializerSymfony\SerializerSymfonyFactory
12
     */
13
    protected $factory;
14
15
    /**
16
     * @param \Jellyfish\SerializerSymfony\SerializerSymfonyFactory $factory
17
     */
18
    public function __construct(SerializerSymfonyFactory $factory)
19
    {
20
        $this->factory = $factory;
21
    }
22
23
24
    /**
25
     * @param object $data
26
     * @param string $format
27
     *
28
     * @return string
29
     */
30
    public function serialize(object $data, string $format): string
31
    {
32
        return $this->factory->getSerializer()->serialize($data, $format);
33
    }
34
35
    /**
36
     * @param string $data
37
     * @param string $type
38
     * @param string $format
39
     *
40
     * @return object
41
     */
42
    public function deserialize(string $data, string $type, string $format): object
43
    {
44
        return $this->factory->getSerializer()->deserialize($data, $type, $format);
45
    }
46
47
    /**
48
     * @param string $propertyNameConverterStrategyKey
49
     * @param \Jellyfish\Serializer\NameConverter\PropertyNameConverterStrategyInterface $propertyNameConverterStrategy
50
     *
51
     * @return \Jellyfish\Serializer\SerializerFacadeInterface
52
     */
53
    public function addPropertyNameConverterStrategy(
54
        string $propertyNameConverterStrategyKey,
55
        PropertyNameConverterStrategyInterface $propertyNameConverterStrategy
56
    ): SerializerFacadeInterface {
57
        $this->factory->getPropertyNameConverterStrategyProvider()
58
            ->add($propertyNameConverterStrategyKey, $propertyNameConverterStrategy);
59
60
        return $this;
61
    }
62
63
    /**
64
     * @param string $propertyNameConverterStrategyKey
65
     *
66
     * @return \Jellyfish\Serializer\SerializerFacadeInterface
67
     */
68
    public function removePropertyNameConverterStrategy(
69
        string $propertyNameConverterStrategyKey
70
    ): SerializerFacadeInterface {
71
        $this->factory->getPropertyNameConverterStrategyProvider()
72
            ->remove($propertyNameConverterStrategyKey);
73
74
        return $this;
75
    }
76
77
    /**
78
     * @return \Jellyfish\Serializer\NameConverter\PropertyNameConverterStrategyInterface[]
79
     */
80
    public function getAllPropertyNameConverterStrategies(): array
81
    {
82
        return $this->factory->getPropertyNameConverterStrategyProvider()
83
            ->getAll();
84
    }
85
86
    /**
87
     * @param string $propertyNameConverterStrategyKey
88
     *
89
     * @return bool
90
     */
91
    public function hasPropertyNameConverterStrategy(string $propertyNameConverterStrategyKey): bool
92
    {
93
        return $this->factory->getPropertyNameConverterStrategyProvider()
94
            ->has($propertyNameConverterStrategyKey);
95
    }
96
97
    /**
98
     * @param string $propertyNameConverterStrategyKey
99
     *
100
     * @return \Jellyfish\Serializer\NameConverter\PropertyNameConverterStrategyInterface|null
101
     */
102
    public function getPropertyNameConverterStrategy(string $propertyNameConverterStrategyKey): ?PropertyNameConverterStrategyInterface
103
    {
104
        return $this->factory->getPropertyNameConverterStrategyProvider()
105
            ->get($propertyNameConverterStrategyKey);
106
    }
107
}
108