Completed
Push — master ( 289dee...aec877 )
by Alexandre
03:35
created

AddressClaim::jsonSerialize()   C

Complexity

Conditions 8
Paths 128

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
c 0
b 0
f 0
rs 5.8333
cc 8
eloc 14
nc 128
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: GCC-MED
5
 * Date: 29/01/2018
6
 * Time: 15:34
7
 */
8
9
namespace OAuth2\OpenID\Models;
10
11
12
class AddressClaim implements \JsonSerializable
13
{
14
    /**
15
     * @var null|string
16
     */
17
    protected $formatted;
18
    /**
19
     * @var null|string
20
     */
21
    protected $streetAddress;
22
    /**
23
     * @var null|string
24
     */
25
    protected $locality;
26
    /**
27
     * @var null|string
28
     */
29
    protected $region;
30
    /**
31
     * @var string
32
     */
33
    protected $postalCode;
34
    /**
35
     * @var null|string
36
     */
37
    protected $country;
38
39
    /**
40
     * @return null|string
41
     */
42
    public function getFormatted(): ?string
43
    {
44
        return $this->formatted;
45
    }
46
47
    /**
48
     * @param null|string $formatted
49
     */
50
    public function setFormatted(?string $formatted)
51
    {
52
        $this->formatted = $formatted;
53
    }
54
55
    /**
56
     * @return null|string
57
     */
58
    public function getStreetAddress(): ?string
59
    {
60
        return $this->streetAddress;
61
    }
62
63
    /**
64
     * @param null|string $streetAddress
65
     */
66
    public function setStreetAddress(?string $streetAddress)
67
    {
68
        $this->streetAddress = $streetAddress;
69
    }
70
71
    /**
72
     * @return null|string
73
     */
74
    public function getLocality(): ?string
75
    {
76
        return $this->locality;
77
    }
78
79
    /**
80
     * @param null|string $locality
81
     */
82
    public function setLocality(?string $locality)
83
    {
84
        $this->locality = $locality;
85
    }
86
87
    /**
88
     * @return null|string
89
     */
90
    public function getRegion(): ?string
91
    {
92
        return $this->region;
93
    }
94
95
    /**
96
     * @param null|string $region
97
     */
98
    public function setRegion(?string $region)
99
    {
100
        $this->region = $region;
101
    }
102
103
    /**
104
     * @return null|string
105
     */
106
    public function getPostalCode(): ?string
107
    {
108
        return $this->postalCode;
109
    }
110
111
    /**
112
     * @param null|string $postalCode
113
     */
114
    public function setPostalCode(?string $postalCode)
115
    {
116
        $this->postalCode = $postalCode;
117
    }
118
119
    /**
120
     * @return null|string
121
     */
122
    public function getCountry(): ?string
123
    {
124
        return $this->country;
125
    }
126
127
    /**
128
     * @param null|string $country
129
     */
130
    public function setCountry(?string $country)
131
    {
132
        $this->country = $country;
133
    }
134
135
    /**
136
     * Specify data which should be serialized to JSON
137
     * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
138
     * @return mixed data which can be serialized by <b>json_encode</b>,
139
     * which is a value of any type other than a resource.
140
     * @since 5.4.0
141
     */
142
    function jsonSerialize()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
143
    {
144
        $data = [];
145
        if($this->formatted) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->formatted of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
146
            $data['formatted'] = $this->formatted;
147
        }
148
        if($this->streetAddress) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->streetAddress of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
149
            $data['street_address'] = $this->streetAddress;
150
        }
151
        if($this->locality) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->locality of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
152
            $data['locality'] = $this->locality;
153
        }
154
        if($this->region) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->region of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
155
            $data['region'] = $this->region;
156
        }
157
        if($this->postalCode) {
158
            $data['postal_code'] = $this->postalCode;
159
        }
160
        if($this->country) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->country of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
161
            $data['country'] = $this->country;
162
        }
163
        return empty($data) ? '' : json_encode($data);
164
    }
165
}