Expose::shouldExpose()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 2
rs 10
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\Annotation;
10
11
use Tebru\AnnotationReader\AbstractAnnotation;
12
13
/**
14
 * Class Expose
15
 *
16
 * Use this annotation to include serialization or deserialization of a property.  This
17
 * annotation only works with the flag to require this Expose annotation on the [@see Excluder].
18
 *
19
 * @author Nate Brunette <[email protected]>
20
 *
21
 * @Annotation
22
 * @Target({"CLASS", "PROPERTY", "METHOD"})
23
 */
24
class Expose extends AbstractAnnotation
25
{
26
    /**
27
     * Expose this property during serialization
28
     *
29
     * @var bool
30
     */
31
    private $serialize = true;
32
33
    /**
34
     * Expose this property during deserialization
35
     *
36
     * @var bool
37
     */
38
    private $deserialize = true;
39
40
    /**
41
     * Initialize annotation data
42
     */
43 3
    protected function init(): void
44
    {
45 3
        $this->serialize = $this->data['serialize'] ?? true;
46 3
        $this->deserialize = $this->data['deserialize'] ?? true;
47 3
    }
48
49
    /**
50
     * Returns true if the property should be exposed based on the direction (serialize/deserialize)
51
     *
52
     * @param bool $serialize
53
     * @return bool
54
     */
55 3
    public function shouldExpose(bool $serialize): bool
56
    {
57 3
        return $serialize ? $this->serialize : $this->deserialize;
58
    }
59
}
60