1 | <?php declare(strict_types=1); |
||
27 | abstract class ParserAbstract |
||
28 | { |
||
29 | |||
30 | /** |
||
31 | * @var \Psr\Log\LoggerInterface |
||
32 | */ |
||
33 | protected $logger; |
||
34 | |||
35 | /** |
||
36 | * @var array[FilterInterface] |
||
37 | */ |
||
38 | protected $filters = array(); |
||
39 | |||
40 | /** |
||
41 | * @var StandardAbstract |
||
42 | */ |
||
43 | protected $standard; |
||
44 | |||
45 | /** |
||
46 | * @param StandardAbstract $standard |
||
47 | * @param LoggerInterface $logger |
||
48 | */ |
||
49 | 45 | public function __construct(StandardAbstract $standard, LoggerInterface $logger) |
|
50 | { |
||
51 | 45 | $this->standard = $standard; |
|
52 | 45 | $this->logger = $logger; |
|
53 | 45 | } |
|
54 | |||
55 | /** |
||
56 | * Tries to parse the document |
||
57 | * |
||
58 | * @param Document $document |
||
59 | * @param FeedInterface $feed |
||
60 | * @return \FeedIo\FeedInterface |
||
61 | * @throws \FeedIo\Parser\UnsupportedFormatException |
||
62 | */ |
||
63 | 16 | public function parse(Document $document, FeedInterface $feed) : FeedInterface |
|
64 | { |
||
65 | 16 | if (!$this->standard->canHandle($document)) { |
|
66 | 1 | throw new UnsupportedFormatException('this is not a supported format'); |
|
67 | } |
||
68 | |||
69 | 15 | $this->checkBodyStructure($document, $this->standard->getMandatoryFields()); |
|
|
|||
70 | 14 | $this->parseContent($document, $feed); |
|
71 | |||
72 | 14 | return $feed; |
|
73 | } |
||
74 | |||
75 | /** |
||
76 | * This method is called by parse() if and only if the checkBodyStructure was successful |
||
77 | * |
||
78 | * @param Document $document |
||
79 | * @param FeedInterface $feed |
||
80 | * @return \FeedIo\FeedInterface |
||
81 | */ |
||
82 | abstract public function parseContent(Document $document, FeedInterface $feed) : FeedInterface; |
||
83 | |||
84 | /** |
||
85 | * @param Document $document |
||
86 | * @param iterable $mandatoryFields |
||
87 | * @throws MissingFieldsException |
||
88 | * @return bool |
||
89 | */ |
||
90 | abstract public function checkBodyStructure(Document $document, iterable $mandatoryFields) : bool; |
||
91 | |||
92 | /** |
||
93 | * @return StandardAbstract |
||
94 | */ |
||
95 | 29 | public function getStandard() : StandardAbstract |
|
99 | |||
100 | /** |
||
101 | * @param FeedInterface $feed |
||
102 | * @param NodeInterface $item |
||
103 | * @return ParserAbstract |
||
104 | */ |
||
105 | 11 | public function addValidItem(FeedInterface $feed, NodeInterface $item) : ParserAbstract |
|
113 | |||
114 | /** |
||
115 | * @param ItemInterface $item |
||
116 | * @return bool |
||
117 | */ |
||
118 | 13 | public function isValid(ItemInterface $item) : bool |
|
128 | |||
129 | /** |
||
130 | * @param FilterInterface $filter |
||
131 | * @return ParserAbstract |
||
132 | */ |
||
133 | 4 | public function addFilter(FilterInterface $filter) : ParserAbstract |
|
139 | |||
140 | /** |
||
141 | * Reset filters |
||
142 | * @return ParserAbstract |
||
143 | */ |
||
144 | 2 | public function resetFilters() : ParserAbstract |
|
150 | } |
||
151 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: