Completed
Push — master ( b4619a...ab6ee6 )
by Kamil
12:06 queued 06:35
created

ApiPlatformIriClient::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sylius\Behat\Client;
15
16
use Sylius\Behat\Service\SharedStorageInterface;
17
use Symfony\Component\BrowserKit\AbstractBrowser;
18
use Symfony\Component\HttpFoundation\Response;
19
20
final class ApiPlatformIriClient implements ApiIriClientInterface
21
{
22
    /** @var AbstractBrowser */
23
    private $client;
24
25
    /** @var SharedStorageInterface */
26
    private $sharedStorage;
27
28
    public function __construct(AbstractBrowser $client, SharedStorageInterface $sharedStorage)
29
    {
30
        $this->client = $client;
31
        $this->sharedStorage = $sharedStorage;
32
    }
33
34
    public function showByIri(string $iri): Response
35
    {
36
        return $this->request(Request::custom($iri, 'GET', $this->sharedStorage->get('token')));
37
    }
38
39
    private function request(RequestInterface $request): Response
40
    {
41
        $this->client->request(
42
            $request->method(),
43
            $request->url(),
44
            $request->parameters(),
45
            $request->files(),
46
            $request->headers(),
47
            $request->content() ?? null
48
        );
49
50
        return $this->client->getResponse();
51
    }
52
}
53