|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace InShore\Bookwhen\ValueObjects\Transporter; |
|
6
|
|
|
|
|
7
|
|
|
use Http\Discovery\Psr17Factory; |
|
8
|
|
|
use InShore\Bookwhen\Contracts\Request; |
|
|
|
|
|
|
9
|
|
|
use InShore\Bookwhen\Enums\Transporter\ContentType; |
|
|
|
|
|
|
10
|
|
|
use InShore\Bookwhen\Enums\Transporter\Method; |
|
11
|
|
|
use InShore\Bookwhen\ValueObjects\ResourceUri; |
|
12
|
|
|
use Psr\Http\Message\RequestInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @internal |
|
16
|
|
|
*/ |
|
17
|
|
|
final class Payload |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Creates a new Request value object. |
|
21
|
|
|
* |
|
22
|
|
|
* @param array<string, mixed> $parameters |
|
23
|
|
|
*/ |
|
24
|
|
|
private function __construct( |
|
25
|
|
|
//private readonly ContentType $contentType, |
|
26
|
11 |
|
private readonly Method $method, |
|
27
|
|
|
private readonly ResourceUri $uri, |
|
28
|
|
|
private readonly array $parameters = [], |
|
29
|
|
|
) { |
|
30
|
|
|
// .. |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
11 |
|
/** |
|
34
|
|
|
* Creates a new Payload value object from the given parameters. |
|
35
|
|
|
*/ |
|
36
|
|
|
public static function list(string $resource, array $parameters = []): self |
|
37
|
|
|
{ |
|
38
|
5 |
|
//var_export($parameters); |
|
39
|
|
|
//$contentType = ContentType::JSON; |
|
40
|
|
|
$method = Method::GET; |
|
41
|
|
|
$uri = ResourceUri::list($resource); |
|
42
|
5 |
|
|
|
43
|
5 |
|
return new self($method, $uri, $parameters); |
|
44
|
|
|
} |
|
45
|
5 |
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Creates a new Payload value object from the given parameters. |
|
48
|
|
|
*/ |
|
49
|
|
|
public static function retrieve(string $resource, string $id, array $parameters = []): self |
|
50
|
|
|
{ |
|
51
|
6 |
|
// $contentType = ContentType::JSON; |
|
52
|
|
|
$method = Method::GET; |
|
53
|
|
|
$uri = ResourceUri::retrieve($resource, $id); |
|
54
|
6 |
|
|
|
55
|
6 |
|
return new self($method, $uri, $parameters); |
|
56
|
|
|
} |
|
57
|
6 |
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Creates a new Psr 7 Request instance. |
|
60
|
|
|
*/ |
|
61
|
|
|
public function toRequest(BaseUri $baseUri, Headers $headers, QueryParams $queryParams): RequestInterface |
|
|
|
|
|
|
62
|
|
|
{ |
|
63
|
11 |
|
$psr17Factory = new Psr17Factory(); |
|
64
|
|
|
|
|
65
|
11 |
|
$uri = $baseUri->toString() . $this->uri->toString(); |
|
66
|
|
|
|
|
67
|
11 |
|
if (!empty($this->parameters)) { |
|
68
|
|
|
$uri .= '?' . http_build_query($this->parameters); |
|
69
|
11 |
|
} |
|
70
|
6 |
|
|
|
71
|
|
|
$request = $psr17Factory->createRequest($this->method->value, $uri); |
|
72
|
|
|
|
|
73
|
11 |
|
foreach ($headers->toArray() as $name => $value) { |
|
74
|
|
|
$request = $request->withHeader($name, $value); |
|
75
|
11 |
|
} |
|
76
|
11 |
|
return $request; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
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