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

Expose::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 4
nop 1
crap 3
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 Expose
13
 *
14
 * Use this annotation to include serialization or deserialization of a property.  This
15
 * annotation only works with the flag to require this Expose annotation on the [@see Excluder].
16
 *
17
 * @author Nate Brunette <[email protected]>
18
 *
19
 * @Annotation
20
 * @Target({"CLASS", "PROPERTY", "METHOD"})
21
 */
22 View Code Duplication
class Expose 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
     * Expose this property during serialization
26
     *
27
     * @var bool
28
     */
29
    private $serialize = true;
30
31
    /**
32
     * Expose 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 exposed based on the direction (serialize/deserialize)
49
     *
50
     * @param bool $serialize
51
     * @return bool
52
     */
53 3
    public function shouldExpose(bool $serialize): bool
54
    {
55 3
        return $serialize ? $this->serialize : $this->deserialize;
56
    }
57
}
58