1 | <?php |
||||
2 | |||||
3 | namespace ByTIC\MFinante\Parsers; |
||||
4 | |||||
5 | use ByTIC\MFinante\Models\AbstractModel; |
||||
6 | use ByTIC\MFinante\Scrapers\AbstractScraper; |
||||
7 | use Symfony\Component\DomCrawler\Crawler; |
||||
8 | |||||
9 | /** |
||||
10 | * Class AbstractParser |
||||
11 | * @package ByTIC\MFinante\Parsers |
||||
12 | */ |
||||
13 | abstract class AbstractParser |
||||
14 | { |
||||
15 | |||||
16 | /** |
||||
17 | * @var AbstractScraper |
||||
18 | */ |
||||
19 | protected $scraper; |
||||
20 | |||||
21 | /** |
||||
22 | * @var Crawler |
||||
23 | */ |
||||
24 | protected $crawler; |
||||
25 | |||||
26 | /** |
||||
27 | * @var null|boolean |
||||
28 | */ |
||||
29 | protected $isValidContent = null; |
||||
30 | |||||
31 | /** |
||||
32 | * @var null|array |
||||
33 | */ |
||||
34 | protected $contents = null; |
||||
35 | |||||
36 | /** |
||||
37 | * @return mixed |
||||
38 | */ |
||||
39 | 2 | public function getContent() |
|||
40 | { |
||||
41 | 2 | if ($this->contents === null) { |
|||
42 | 2 | if ($this->isValidContent()) { |
|||
43 | 2 | $this->contents = $this->generateContent(); |
|||
44 | } else { |
||||
45 | $this->contents = false; |
||||
0 ignored issues
–
show
|
|||||
46 | } |
||||
47 | } |
||||
48 | |||||
49 | 2 | return $this->contents; |
|||
50 | } |
||||
51 | |||||
52 | abstract protected function generateContent(); |
||||
53 | |||||
54 | /** |
||||
55 | * @return bool|null |
||||
56 | */ |
||||
57 | 2 | public function isValidContent() |
|||
58 | { |
||||
59 | 2 | if ($this->isValidContent == null) { |
|||
60 | 2 | $this->doValidation(); |
|||
61 | 2 | $this->isValidContent = true; |
|||
62 | } |
||||
63 | |||||
64 | 2 | return $this->isValidContent; |
|||
65 | } |
||||
66 | |||||
67 | /** |
||||
68 | * @return void |
||||
69 | */ |
||||
70 | 2 | protected function doValidation() |
|||
71 | { |
||||
72 | 2 | } |
|||
73 | |||||
74 | /** |
||||
75 | * @return AbstractScraper |
||||
76 | */ |
||||
77 | 1 | public function getScraper() |
|||
78 | { |
||||
79 | 1 | return $this->scraper; |
|||
80 | } |
||||
81 | |||||
82 | /** |
||||
83 | * @param AbstractScraper $scraper |
||||
84 | */ |
||||
85 | 2 | public function setScraper($scraper) |
|||
86 | { |
||||
87 | 2 | $this->scraper = $scraper; |
|||
88 | 2 | } |
|||
89 | |||||
90 | /** |
||||
91 | * @return Crawler |
||||
92 | */ |
||||
93 | 2 | public function getCrawler(): Crawler |
|||
94 | { |
||||
95 | 2 | return $this->crawler; |
|||
96 | } |
||||
97 | |||||
98 | /** |
||||
99 | * @param Crawler $crawler |
||||
100 | */ |
||||
101 | 2 | public function setCrawler(Crawler $crawler) |
|||
102 | { |
||||
103 | 2 | $this->crawler = $crawler; |
|||
104 | 2 | } |
|||
105 | |||||
106 | /** |
||||
107 | * @return array |
||||
108 | */ |
||||
109 | public function getArray() |
||||
110 | { |
||||
111 | return $this->getContent(); |
||||
0 ignored issues
–
show
The expression
return $this->getContent() could also return false which is incompatible with the documented return type array . Did you maybe forget to handle an error condition?
If the returned type also contains false, it is an indicator that maybe an error condition leading to the specific return statement remains unhandled. ![]() |
|||||
112 | } |
||||
113 | |||||
114 | public function getModel() |
||||
115 | { |
||||
116 | $model = $this->getNewModel(); |
||||
117 | $parameters = $this->getContent(); |
||||
0 ignored issues
–
show
|
|||||
118 | $model->setParameters($model); |
||||
0 ignored issues
–
show
$model of type ByTIC\MFinante\Models\AbstractModel is incompatible with the type array expected by parameter $parameters of ByTIC\MFinante\Models\Ab...tModel::setParameters() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
119 | } |
||||
120 | |||||
121 | /** |
||||
122 | * @return AbstractModel |
||||
123 | */ |
||||
124 | public function getNewModel() |
||||
125 | { |
||||
126 | $className = $this->getModelClassName(); |
||||
127 | $model = new $className(); |
||||
128 | return $model; |
||||
129 | } |
||||
130 | |||||
131 | abstract public function getModelClassName(); |
||||
132 | } |
||||
133 |
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..