Passed
Push — master ( 21a5dc...1ca6d2 )
by Nate
40s
created

skipSerializingProperty()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 3
nop 1
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * Copyright (c) Nate Brunette.
4
 * Distributed under the MIT License (http://opensource.org/licenses/MIT)
5
 */
6
7
declare(strict_types=1);
8
9
namespace Tebru\Gson\Internal;
10
11
use Tebru\Gson\Cacheable;
12
use Tebru\Gson\ClassMetadata;
13
use Tebru\Gson\Exclusion\ClassDeserializationExclusionStrategy;
14
use Tebru\Gson\Exclusion\ClassSerializationExclusionStrategy;
15
use Tebru\Gson\Exclusion\DeserializationExclusionData;
16
use Tebru\Gson\Exclusion\DeserializationExclusionDataAware;
17
use Tebru\Gson\Exclusion\PropertyDeserializationExclusionStrategy;
18
use Tebru\Gson\Exclusion\PropertySerializationExclusionStrategy;
19
use Tebru\Gson\Exclusion\SerializationExclusionData;
20
use Tebru\Gson\Exclusion\SerializationExclusionDataAware;
21
use Tebru\Gson\ExclusionData;
22
use Tebru\Gson\ExclusionStrategy;
23
use Tebru\Gson\PropertyMetadata;
24
25
/**
26
 * Class ExclusionStrategyAdapter
27
 *
28
 * Wraps the legacy [@see ExclusionData] in new interfaces
29
 *
30
 * @author Nate Brunette <[email protected]>
31
 */
32
class ExclusionStrategyAdapter implements
33
    ClassSerializationExclusionStrategy,
34
    ClassDeserializationExclusionStrategy,
35
    PropertySerializationExclusionStrategy,
36
    PropertyDeserializationExclusionStrategy,
37
    SerializationExclusionDataAware,
38
    DeserializationExclusionDataAware
39
{
40
    /**
41
     * @var ExclusionStrategy
42
     */
43
    private $exclusionStrategy;
44
45
    /**
46
     * @var bool
47
     */
48
    private $serialization;
49
50
    /**
51
     * @var bool
52
     */
53
    private $deserialization;
54
55
    /**
56
     * @var SerializationExclusionData
57
     */
58
    private $serializationData;
59
60
    /**
61
     * @var DeserializationExclusionData
62
     */
63
    private $deserializationData;
64
65
    /**
66
     * Constructor
67
     *
68
     * @param ExclusionStrategy $exclusionStrategy
69
     * @param bool $serialization
70
     * @param bool $deserialization
71
     */
72 3
    public function __construct(ExclusionStrategy $exclusionStrategy, bool $serialization, bool $deserialization)
73
    {
74 3
        $this->exclusionStrategy = $exclusionStrategy;
75 3
        $this->serialization = $serialization;
76 3
        $this->deserialization = $deserialization;
77 3
    }
78
79
    /**
80
     * Return true if caching should be enabled
81
     *
82
     * @return bool
83
     */
84 3
    public function shouldCache(): bool
85
    {
86 3
        return $this->exclusionStrategy instanceof Cacheable && $this->exclusionStrategy->shouldCache();
87
    }
88
89
    /**
90
     * Returns true if the class should be skipped during deserialization
91
     *
92
     * @param ClassMetadata $class
93
     * @return bool
94
     */
95 1
    public function skipDeserializingClass(ClassMetadata $class): bool
96
    {
97 1
        return $this->deserialization && $this->deserializationData && $this->exclusionStrategy->shouldSkipClass(
0 ignored issues
show
Deprecated Code introduced by
The function Tebru\Gson\ExclusionStrategy::shouldSkipClass() has been deprecated: Since v0.6.0 to be removed in v0.7.0. Use \Tebru\Gson\Exclusion\ExclusionStrategy instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

97
        return $this->deserialization && $this->deserializationData && /** @scrutinizer ignore-deprecated */ $this->exclusionStrategy->shouldSkipClass(

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
98 1
            $class,
99 1
            new DefaultExclusionData(
0 ignored issues
show
Deprecated Code introduced by
The class Tebru\Gson\Internal\DefaultExclusionData has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

99
            /** @scrutinizer ignore-deprecated */ new DefaultExclusionData(
Loading history...
100 1
                false,
101 1
                $this->deserializationData->getObjectToReadInto(),
102 1
                $this->deserializationData->getPayload()
103
            )
104
        );
105
    }
106
107
    /**
108
     * Returns true if the class should be skipped during serialization
109
     *
110
     * @param ClassMetadata $class
111
     * @return bool
112
     */
113 2
    public function skipSerializingClass(ClassMetadata $class): bool
114
    {
115 2
        return $this->serialization && $this->serializationData && $this->exclusionStrategy->shouldSkipClass(
0 ignored issues
show
Deprecated Code introduced by
The function Tebru\Gson\ExclusionStrategy::shouldSkipClass() has been deprecated: Since v0.6.0 to be removed in v0.7.0. Use \Tebru\Gson\Exclusion\ExclusionStrategy instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

115
        return $this->serialization && $this->serializationData && /** @scrutinizer ignore-deprecated */ $this->exclusionStrategy->shouldSkipClass(

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
116 2
            $class,
117 2
            new DefaultExclusionData(true, $this->serializationData->getObjectToSerialize())
0 ignored issues
show
Deprecated Code introduced by
The class Tebru\Gson\Internal\DefaultExclusionData has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

117
            /** @scrutinizer ignore-deprecated */ new DefaultExclusionData(true, $this->serializationData->getObjectToSerialize())
Loading history...
118
        );
119
    }
120
121
    /**
122
     * Returns true if the property should be skipped during deserialization
123
     *
124
     * @param PropertyMetadata $property
125
     * @return bool
126
     */
127 1
    public function skipDeserializingProperty(PropertyMetadata $property): bool
128
    {
129 1
        return $this->deserialization && $this->deserializationData && $this->exclusionStrategy->shouldSkipProperty(
0 ignored issues
show
Deprecated Code introduced by
The function Tebru\Gson\ExclusionStrategy::shouldSkipProperty() has been deprecated: Since v0.6.0 to be removed in v0.7.0. Use \Tebru\Gson\Exclusion\ExclusionStrategy instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

129
        return $this->deserialization && $this->deserializationData && /** @scrutinizer ignore-deprecated */ $this->exclusionStrategy->shouldSkipProperty(

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
130 1
            $property,
131 1
            new DefaultExclusionData(
0 ignored issues
show
Deprecated Code introduced by
The class Tebru\Gson\Internal\DefaultExclusionData has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

131
            /** @scrutinizer ignore-deprecated */ new DefaultExclusionData(
Loading history...
132 1
                false,
133 1
                $this->deserializationData->getObjectToReadInto(),
134 1
                $this->deserializationData->getPayload()
135
            )
136
        );
137
    }
138
139
    /**
140
     * Returns true if the property should be skipped during serialization
141
     *
142
     * @param PropertyMetadata $property
143
     * @return bool
144
     */
145 2
    public function skipSerializingProperty(PropertyMetadata $property): bool
146
    {
147 2
        return $this->serialization && $this->serializationData && $this->exclusionStrategy->shouldSkipProperty(
0 ignored issues
show
Deprecated Code introduced by
The function Tebru\Gson\ExclusionStrategy::shouldSkipProperty() has been deprecated: Since v0.6.0 to be removed in v0.7.0. Use \Tebru\Gson\Exclusion\ExclusionStrategy instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

147
        return $this->serialization && $this->serializationData && /** @scrutinizer ignore-deprecated */ $this->exclusionStrategy->shouldSkipProperty(

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
148 2
            $property,
149 2
            new DefaultExclusionData(false, $this->serializationData->getObjectToSerialize())
0 ignored issues
show
Deprecated Code introduced by
The class Tebru\Gson\Internal\DefaultExclusionData has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

149
            /** @scrutinizer ignore-deprecated */ new DefaultExclusionData(false, $this->serializationData->getObjectToSerialize())
Loading history...
150
        );
151
    }
152
153
    /**
154
     * Sets the deserialization exclusion data
155
     *
156
     * @param DeserializationExclusionData $data
157
     * @return void
158
     */
159 1
    public function setDeserializationExclusionData(DeserializationExclusionData $data): void
160
    {
161 1
        $this->deserializationData = $data;
162 1
    }
163
164
    /**
165
     * Sets the serialization exclusion data
166
     *
167
     * @param SerializationExclusionData $data
168
     * @return void
169
     */
170 2
    public function setSerializationExclusionData(SerializationExclusionData $data): void
171
    {
172 2
        $this->serializationData = $data;
173 2
    }
174
}
175