1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SteamMarketProviders\ParserManager\Http; |
6
|
|
|
|
7
|
|
|
use Exception; |
8
|
|
|
use stdClass; |
9
|
|
|
use SteamMarketProviders\ParserManager\Contract\Http\HttpExceptionInterface; |
10
|
|
|
use SteamMarketProviders\ParserManager\Contract\StrategyInterface; |
11
|
|
|
use SteamMarketProviders\ParserManager\Exception\Http\URLNotSetException; |
|
|
|
|
12
|
|
|
use SteamMarketProviders\ParserManager\Exception\HttpException; |
13
|
|
|
use SteamMarketProviders\ParserManager\Exception\InvalidArgumentException; |
14
|
|
|
use SteamMarketProviders\ParserManager\Http\Strategy\GuzzleStrategy; |
15
|
|
|
|
16
|
|
|
final class Http |
17
|
|
|
{ |
18
|
|
|
private string $url; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param StrategyInterface|null $strategy |
22
|
|
|
*/ |
23
|
8 |
|
public function __construct(private null|StrategyInterface $strategy = null) |
24
|
|
|
{ |
25
|
8 |
|
if (!$this->strategy) { |
26
|
8 |
|
$this->strategy = new GuzzleStrategy(); |
27
|
|
|
} |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param string $url |
32
|
|
|
* @return $this |
33
|
|
|
* @throws InvalidArgumentException |
34
|
|
|
*/ |
35
|
2 |
|
public function setUrl(string $url): Http |
36
|
|
|
{ |
37
|
2 |
|
if (!filter_var($url, FILTER_VALIDATE_URL)) { |
38
|
1 |
|
throw new InvalidArgumentException( |
39
|
1 |
|
sprintf('The url: "%s" is not in a valid format', $url) |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
1 |
|
$this->url = $url; |
44
|
|
|
|
45
|
1 |
|
return $this; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return string |
50
|
|
|
*/ |
51
|
|
|
public function getUrl(): string |
52
|
|
|
{ |
53
|
|
|
return $this->url; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param StrategyInterface $strategy |
58
|
|
|
* @return $this |
59
|
|
|
*/ |
60
|
1 |
|
public function setStrategy(StrategyInterface $strategy): Http |
61
|
|
|
{ |
62
|
1 |
|
$this->strategy = $strategy; |
63
|
|
|
|
64
|
1 |
|
return $this; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return StrategyInterface |
69
|
|
|
*/ |
70
|
2 |
|
public function getStrategy(): StrategyInterface |
71
|
|
|
{ |
72
|
2 |
|
return $this->strategy; |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return stdClass |
77
|
|
|
* @throws HttpException |
78
|
|
|
* @throws HttpExceptionInterface |
79
|
|
|
* @throws URLNotSetException |
80
|
|
|
*/ |
81
|
1 |
|
public function sendRequest(): stdClass |
82
|
|
|
{ |
83
|
|
|
try { |
84
|
1 |
|
$response = $this->strategy->sendRequest($this->url); |
|
|
|
|
85
|
|
|
|
86
|
|
|
$code = $response->getStatus(); |
87
|
|
|
if ($code !== 200) { |
88
|
|
|
throw new HttpException(""); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
$response = json_decode($response->getBody()); |
|
|
|
|
92
|
|
|
|
93
|
|
|
if (!$response->success) { |
94
|
|
|
throw new HttpException(""); |
95
|
|
|
} |
96
|
1 |
|
} catch (HttpExceptionInterface $httpException) { |
97
|
|
|
throw new $httpException(); |
98
|
1 |
|
} catch (Exception $e) { |
99
|
|
|
throw new HttpException($e->getMessage()); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return $response; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths