Expose   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 34
ccs 6
cts 6
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 4 1
A shouldExpose() 0 3 2
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