1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sportic\Timing\RaceTecClient\Parsers; |
4
|
|
|
|
5
|
|
|
use Sportic\Timing\CommonClient\Content\ContentFactory; |
6
|
|
|
use Sportic\Timing\CommonClient\Models\AbstractModel; |
7
|
|
|
use Sportic\Timing\RaceTecClient\Scrapers\AbstractScraper; |
8
|
|
|
use Symfony\Component\DomCrawler\Crawler; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class AbstractParser |
12
|
|
|
* @package Sportic\Timing\RaceTecClient\Parsers |
13
|
|
|
*/ |
14
|
|
|
abstract class AbstractParser |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var AbstractScraper |
19
|
|
|
*/ |
20
|
|
|
protected $scraper; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var Crawler |
24
|
|
|
*/ |
25
|
|
|
protected $crawler; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var null|boolean |
29
|
|
|
*/ |
30
|
|
|
protected $isValidContent = null; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var null|AbstractContent |
34
|
|
|
*/ |
35
|
|
|
protected $contents = null; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return mixed |
39
|
|
|
*/ |
40
|
|
|
public function getContent() |
41
|
|
|
{ |
42
|
|
|
if ($this->contents === null) { |
43
|
|
|
if ($this->isValidContent()) { |
44
|
|
|
$contents = $this->generateContent(); |
45
|
|
|
$this->contents = ContentFactory::createFromArray($contents); |
|
|
|
|
46
|
|
|
} else { |
47
|
|
|
$this->contents = false; |
|
|
|
|
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $this->contents; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
abstract protected function generateContent(); |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return bool|null |
58
|
|
|
*/ |
59
|
|
|
public function isValidContent() |
60
|
|
|
{ |
61
|
|
|
if ($this->isValidContent == null) { |
62
|
|
|
$this->doValidation(); |
63
|
|
|
$this->isValidContent = true; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $this->isValidContent; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return void |
71
|
|
|
*/ |
72
|
|
|
protected function doValidation() |
73
|
|
|
{ |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return AbstractScraper |
78
|
|
|
*/ |
79
|
|
|
public function getScraper() |
80
|
|
|
{ |
81
|
|
|
return $this->scraper; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param AbstractScraper $scraper |
86
|
|
|
*/ |
87
|
|
|
public function setScraper($scraper) |
88
|
|
|
{ |
89
|
|
|
$this->scraper = $scraper; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return Crawler |
94
|
|
|
*/ |
95
|
|
|
public function getCrawler(): Crawler |
96
|
|
|
{ |
97
|
|
|
return $this->crawler; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param Crawler $crawler |
102
|
|
|
*/ |
103
|
|
|
public function setCrawler(Crawler $crawler) |
104
|
|
|
{ |
105
|
|
|
$this->crawler = $crawler; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return array |
110
|
|
|
*/ |
111
|
|
|
public function getArray() |
112
|
|
|
{ |
113
|
|
|
return $this->getContent(); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return AbstractModel |
118
|
|
|
*/ |
119
|
|
|
public function getModel() |
120
|
|
|
{ |
121
|
|
|
$model = $this->getNewModel(); |
122
|
|
|
$parameters = $this->getContent(); |
123
|
|
|
$model->setParameters($parameters); |
|
|
|
|
124
|
|
|
|
125
|
|
|
return $model; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @return AbstractModel |
130
|
|
|
*/ |
131
|
|
|
public function getNewModel() |
132
|
|
|
{ |
133
|
|
|
$className = $this->getModelClassName(); |
134
|
|
|
$model = new $className(); |
135
|
|
|
|
136
|
|
|
return $model; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
abstract public function getModelClassName(); |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @return string |
143
|
|
|
*/ |
144
|
|
|
protected function getContentClassName() |
145
|
|
|
{ |
146
|
|
|
return GenericContent::class; |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
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..