1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2017–2018 Ryan Parman <http://ryanparman.com>. |
4
|
|
|
* Copyright (c) 2017–2018 Contributors. |
5
|
|
|
* |
6
|
|
|
* http://opensource.org/licenses/Apache2.0 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
declare(strict_types=1); |
10
|
|
|
|
11
|
|
|
namespace SimplePie\Type; |
12
|
|
|
|
13
|
|
|
use Psr\Log\NullLogger; |
14
|
|
|
use SimplePie\Configuration as C; |
15
|
|
|
use SimplePie\Exception\SimplePieException; |
16
|
|
|
use SimplePie\Mixin as Tr; |
17
|
|
|
use SimplePie\Parser\Date as DateParser; |
18
|
|
|
use stdClass; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Represents the top-level of a feed. |
22
|
|
|
*/ |
23
|
|
|
class Feed extends AbstractType implements BranchInterface, C\SetLoggerInterface |
24
|
|
|
{ |
25
|
|
|
use Tr\DateTrait; |
26
|
|
|
use Tr\DeepTypeTrait; |
27
|
|
|
use Tr\LoggerTrait; |
28
|
|
|
use Tr\RootTrait; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* The preferred namespace alias for a given XML namespace URI. Should be |
32
|
|
|
* the result of a call to `SimplePie\Util\Ns`. |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $namespaceAlias; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Constructs a new instance of this class. |
40
|
|
|
* |
41
|
|
|
* @param string $namespaceAlias [description] |
42
|
|
|
*/ |
43
|
|
|
public function __construct(string $namespaceAlias) |
44
|
|
|
{ |
45
|
|
|
$this->root = new stdClass(); |
|
|
|
|
46
|
|
|
$this->logger = new NullLogger(); |
47
|
|
|
$this->namespaceAlias = $namespaceAlias; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Finds the common internal alias for a given method name. |
52
|
|
|
* |
53
|
|
|
* @param string $nodeName The name of the method being called. |
54
|
|
|
* |
55
|
|
|
* @return string |
56
|
|
|
* |
57
|
|
|
* phpcs:disable Generic.Metrics.CyclomaticComplexity.MaxExceeded |
58
|
|
|
*/ |
59
|
|
|
public function getAlias(string $nodeName): string |
60
|
|
|
{ |
61
|
|
|
switch ($nodeName) { |
62
|
|
|
case 'categories': |
63
|
|
|
return 'category'; |
64
|
|
|
|
65
|
|
|
case 'contributors': |
66
|
|
|
return 'contributor'; |
67
|
|
|
|
68
|
|
|
case 'entries': |
69
|
|
|
case 'items': |
70
|
|
|
return 'entry'; |
71
|
|
|
|
72
|
|
|
case 'language': |
73
|
|
|
return 'lang'; |
74
|
|
|
|
75
|
|
|
case 'links': |
76
|
|
|
return 'link'; |
77
|
|
|
|
78
|
|
|
case 'pubDate': |
79
|
|
|
case 'publishDate': |
80
|
|
|
case 'publishedDate': |
81
|
|
|
return 'published'; |
82
|
|
|
|
83
|
|
|
default: |
84
|
|
|
return $nodeName; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
// phpcs:enable |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Get the correct handler for a whitelisted method name. |
92
|
|
|
* |
93
|
|
|
* @param string $nodeName The name of the method being called. |
94
|
|
|
* @param array $args Any arguments passed into that method. The default value is an empty array. |
95
|
|
|
* |
96
|
|
|
* @throws SimplePieException |
97
|
|
|
* |
98
|
|
|
* @return mixed Either `TypeInterface` or `TypeInterface[]`. |
99
|
|
|
* |
100
|
|
|
* phpcs:disable Generic.Metrics.CyclomaticComplexity.MaxExceeded |
101
|
|
|
*/ |
102
|
|
|
public function getHandler(string $nodeName, array $args = []) |
103
|
|
|
{ |
104
|
|
|
switch ($nodeName) { |
105
|
|
|
case 'id': |
106
|
|
|
case 'lang': |
107
|
|
|
case 'rights': |
108
|
|
|
case 'subtitle': |
109
|
|
|
case 'summary': |
110
|
|
|
case 'title': |
111
|
|
|
return $this->getScalarSingleValue($this->getRoot(), $nodeName, $args[0] ?? null); |
112
|
|
|
|
113
|
|
|
case 'published': |
114
|
|
|
case 'updated': |
115
|
|
|
return (new DateParser( |
116
|
|
|
$this->getScalarSingleValue($this->getRoot(), $nodeName, $args[0] ?? null)->getValue(), |
117
|
|
|
$this->outputTimezone, |
118
|
|
|
$this->createFromFormat |
119
|
|
|
))->getDateTime(); |
120
|
|
|
|
121
|
|
|
case 'author': |
122
|
|
|
return $this->getComplexSingleValue($this->getRoot(), $nodeName, Person::class, $args[0] ?? null); |
123
|
|
|
|
124
|
|
|
case 'generator': |
125
|
|
|
return $this->getComplexSingleValue($this->getRoot(), $nodeName, Generator::class, $args[0] ?? null); |
126
|
|
|
|
127
|
|
|
case 'icon': |
128
|
|
|
case 'logo': |
129
|
|
|
return $this->getComplexSingleValue($this->getRoot(), $nodeName, Image::class, $args[0] ?? null); |
130
|
|
|
|
131
|
|
|
case 'category': |
132
|
|
|
case 'contributor': |
133
|
|
|
case 'entry': |
134
|
|
|
case 'link': |
135
|
|
|
return $this->getComplexMultipleValues($this->getRoot(), $nodeName, $args[0] ?? null); |
136
|
|
|
|
137
|
|
|
default: |
138
|
|
|
throw new SimplePieException( |
139
|
|
|
$this->getUnresolvableMessage($nodeName) |
140
|
|
|
); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
// phpcs:enable |
145
|
|
|
} |
146
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..