|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (c) 2017 Ryan Parman <http://ryanparman.com>. |
|
4
|
|
|
* Copyright (c) 2017 Contributors. |
|
5
|
|
|
* |
|
6
|
|
|
* http://opensource.org/licenses/Apache2.0 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
declare(strict_types=1); |
|
10
|
|
|
|
|
11
|
|
|
namespace SimplePie\Type; |
|
12
|
|
|
|
|
13
|
|
|
use DOMNode; |
|
14
|
|
|
use Psr\Log\LoggerInterface; |
|
15
|
|
|
use SimplePie\Configuration as C; |
|
16
|
|
|
use SimplePie\Mixin as T; |
|
17
|
|
|
|
|
18
|
|
|
class Person extends AbstractType implements TypeInterface, C\SetLoggerInterface |
|
19
|
|
|
{ |
|
20
|
|
|
use T\LoggerTrait; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* The DOMNode element to parse. |
|
24
|
|
|
* |
|
25
|
|
|
* @var DOMNode |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $node; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* The person's name. |
|
31
|
|
|
* |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $name; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* The person's URL. |
|
38
|
|
|
* |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $uri; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* The person's email address. |
|
45
|
|
|
* |
|
46
|
|
|
* @var string |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $email; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* The person's avatar. |
|
52
|
|
|
* |
|
53
|
|
|
* @var string |
|
54
|
|
|
*/ |
|
55
|
|
|
protected $avatar; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Constructs a new instance of this class. |
|
59
|
|
|
* |
|
60
|
|
|
* @param DOMNode|null $node The `DOMNode` element to parse. |
|
61
|
|
|
* @param LoggerInterface $logger The PSR-3 logger. |
|
|
|
|
|
|
62
|
|
|
*/ |
|
63
|
|
|
public function __construct(?DOMNode $node = null, LoggerInterface $logger = null) |
|
64
|
|
|
{ |
|
65
|
|
|
if ($node) { |
|
66
|
|
|
$this->logger = $logger ?? new NullLogger(); |
|
|
|
|
|
|
67
|
|
|
$this->node = $node; |
|
68
|
|
|
$this->name = new Node($this->node); |
|
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
foreach ($this->node->childNodes as $child) { |
|
71
|
|
|
$this->{$child->tagName} = new Node($child); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Converts this object into a string representation. |
|
78
|
|
|
* |
|
79
|
|
|
* @return string |
|
80
|
|
|
*/ |
|
81
|
|
|
public function __toString(): string |
|
82
|
|
|
{ |
|
83
|
|
|
if (null !== $this->name && null !== $this->uri) { |
|
84
|
|
|
return \trim(\sprintf('%s <%s>', (string) $this->name, (string) $this->uri)); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
if (null !== $this->name && null !== $this->email) { |
|
88
|
|
|
return \trim(\sprintf('%s <%s>', (string) $this->name, (string) $this->email)); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
if (null !== $this->name) { |
|
92
|
|
|
return \trim((string) $this->name); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
if (null !== $this->uri) { |
|
96
|
|
|
return \trim((string) $this->uri); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
if (null !== $this->email) { |
|
100
|
|
|
return \trim((string) $this->email); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
return 'Unknown'; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Gets the DOMNode element. |
|
108
|
|
|
* |
|
109
|
|
|
* @return DOMNode|null |
|
110
|
|
|
*/ |
|
111
|
|
|
public function getNode(): ?DOMNode |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->node; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Gets the person's name. |
|
118
|
|
|
* |
|
119
|
|
|
* @return Node |
|
120
|
|
|
*/ |
|
121
|
|
|
public function getName(): Node |
|
122
|
|
|
{ |
|
123
|
|
|
return $this->name ?? new Node(); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Gets the person's URL. |
|
128
|
|
|
* |
|
129
|
|
|
* @return Node |
|
130
|
|
|
*/ |
|
131
|
|
|
public function getUrl(): Node |
|
132
|
|
|
{ |
|
133
|
|
|
return $this->uri ?? new Node(); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Gets the person's email address. |
|
138
|
|
|
* |
|
139
|
|
|
* @return Node |
|
140
|
|
|
*/ |
|
141
|
|
|
public function getEmail(): Node |
|
142
|
|
|
{ |
|
143
|
|
|
return $this->email ?? new Node(); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* Gets the person's avatar. |
|
148
|
|
|
* |
|
149
|
|
|
* @return Node |
|
150
|
|
|
*/ |
|
151
|
|
|
public function getAvatar(): Node |
|
152
|
|
|
{ |
|
153
|
|
|
return $this->avatar ?? new Node(); |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.