1 | <?php |
||
17 | class Parser implements \Xparse\ParserInterface\ParserInterface { |
||
18 | |||
19 | /** |
||
20 | * |
||
21 | * @var null|\Xparse\ElementFinder\ElementFinder |
||
22 | */ |
||
23 | protected $lastPage = null; |
||
24 | |||
25 | /** |
||
26 | * @var ClientInterface |
||
27 | */ |
||
28 | protected $client = null; |
||
29 | |||
30 | /** |
||
31 | * @var ElementFinderFactory |
||
32 | */ |
||
33 | protected $elementFinderFactory = null; |
||
34 | |||
35 | /** |
||
36 | * @var null|ResponseInterface |
||
37 | */ |
||
38 | protected $lastResponse = null; |
||
39 | |||
40 | |||
41 | /** |
||
42 | * @param ClientInterface|null $client |
||
43 | * @param ElementFinderFactory|null $elementFinderFactory |
||
44 | */ |
||
45 | 7 | public function __construct(ClientInterface $client = null, ElementFinderFactory $elementFinderFactory = null) { |
|
46 | 7 | if (empty($client)) { |
|
47 | 1 | $client = new \GuzzleHttp\Client([ |
|
48 | 1 | \GuzzleHttp\RequestOptions::ALLOW_REDIRECTS => true, |
|
49 | 1 | ]); |
|
50 | |||
51 | 1 | } |
|
52 | |||
53 | 7 | if ($elementFinderFactory === null) { |
|
54 | 7 | $this->elementFinderFactory = new ElementFinderFactory(); |
|
55 | 7 | } else { |
|
56 | $this->elementFinderFactory = $elementFinderFactory; |
||
57 | } |
||
58 | |||
59 | 7 | $this->client = $client; |
|
60 | 7 | } |
|
61 | |||
62 | |||
63 | /** |
||
64 | * @param string $url |
||
65 | * @return \Xparse\ElementFinder\ElementFinder |
||
66 | * @throws \InvalidArgumentException |
||
67 | */ |
||
68 | 4 | public function get($url) { |
|
69 | 4 | if (empty($url) or !is_string($url)) { |
|
70 | 1 | throw new \InvalidArgumentException('Url must be not empty and string.'); |
|
71 | } |
||
72 | |||
73 | 3 | $request = new \GuzzleHttp\Psr7\Request('GET', $url); |
|
74 | 3 | return $this->send($request); |
|
75 | } |
||
76 | |||
77 | |||
78 | /** |
||
79 | * @param string $url |
||
80 | * @param array $data |
||
81 | * @return \Xparse\ElementFinder\ElementFinder |
||
82 | * @throws \InvalidArgumentException |
||
83 | */ |
||
84 | 2 | public function post($url, $data) { |
|
85 | |||
86 | 2 | if (empty($url) or !is_string($url)) { |
|
87 | 1 | throw new \InvalidArgumentException('Url must be not empty and string.'); |
|
88 | } |
||
89 | |||
90 | 1 | $request = new Request('POST', $url, [ |
|
91 | 1 | 'body' => $data, |
|
92 | 1 | ]); |
|
93 | |||
94 | 1 | return $this->send($request); |
|
95 | } |
||
96 | |||
97 | |||
98 | /** |
||
99 | * @return \Xparse\ElementFinder\ElementFinder |
||
100 | */ |
||
101 | 2 | public function getLastPage() { |
|
104 | |||
105 | |||
106 | /** |
||
107 | * @param \Xparse\ElementFinder\ElementFinder $lastPage |
||
108 | * @return $this |
||
109 | */ |
||
110 | 4 | public function setLastPage($lastPage) { |
|
114 | |||
115 | |||
116 | /** |
||
117 | * @return null|ResponseInterface |
||
118 | */ |
||
119 | 1 | public function getLastResponse() { |
|
122 | |||
123 | |||
124 | /** |
||
125 | * @return ClientInterface |
||
126 | */ |
||
127 | 3 | public function getClient() { |
|
130 | |||
131 | |||
132 | /** |
||
133 | * @param $request |
||
134 | * @param array $options |
||
135 | * @return \Xparse\ElementFinder\ElementFinder |
||
136 | * @throws \Exception |
||
137 | */ |
||
138 | 4 | public function send(RequestInterface $request, array $options = []) { |
|
158 | |||
159 | } |
||
160 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.