Completed
Push — master ( bc20b4...b7ce52 )
by Nate
03:15
created

Exclude::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 5
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 5
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
/*
3
 * Copyright (c) Nate Brunette.
4
 * Distributed under the MIT License (http://opensource.org/licenses/MIT)
5
 */
6
7
namespace Tebru\Gson\Annotation;
8
9
use Tebru\AnnotationReader\AbstractAnnotation;
10
11
/**
12
 * Class Exclude
13
 *
14
 * Use this annotation to exclude serialization or deserialization of a property
15
 * that would otherwise be included.
16
 *
17
 * @author Nate Brunette <[email protected]>
18
 *
19
 * @Annotation
20
 * @Target({"CLASS", "PROPERTY", "METHOD"})
21
 */
22 View Code Duplication
class Exclude extends AbstractAnnotation
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
{
24
    /**
25
     * Exclude this property during serialization
26
     *
27
     * @var bool
28
     */
29
    private $serialize = true;
30
31
    /**
32
     * Exclude this property during deserialization
33
     *
34
     * @var bool
35
     */
36
    private $deserialize = true;
37
38
    /**
39
     * Initialize annotation data
40
     */
41 3
    protected function init(): void
42
    {
43 3
        $this->serialize = $this->data['serialize'] ?? true;
44 3
        $this->deserialize = $this->data['deserialize'] ?? true;
45 3
    }
46
47
    /**
48
     * Returns true if the property should be excluded based on the direction (serialize/deserialize)
49
     *
50
     * @param bool $serialize
51
     * @return bool
52
     */
53 3
    public function shouldExclude(bool $serialize): bool
54
    {
55 3
        return $serialize ? $this->serialize : $this->deserialize;
56
    }
57
}
58