HttpClient   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A request() 0 12 2
1
<?php
2
declare(strict_types=1);
3
4
/*
5
 * This file is part of the package neoblack/free-at-home-api.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE file that was distributed with this source code.
9
 */
10
11
namespace NeoBlack\FreeAtHomeApi\Test\Unit\Fixtures;
12
13
use GuzzleHttp\Client;
14
use GuzzleHttp\Psr7\Response;
15
use Psr\Http\Message\ResponseInterface;
16
17
class HttpClient extends Client
18
{
19
    /**
20
     * Create and send an HTTP request.
21
     *
22
     * Use an absolute path to override the base path of the client, or a
23
     * relative path to append to the base path of the client. The URL can
24
     * contain the query string as well.
25
     *
26
     * @param string $method HTTP method.
27
     * @param string $uri URI object or string.
28
     * @param array $options Request options to apply.
29
     *
30
     * @return ResponseInterface
31
     */
32
    public function request($method, $uri = '', array $options = []): ResponseInterface
33
    {
34
        $allowedMethods = [
35
            '/devices' => ['GET'],
36
            '/device/4711-foo-bar' => ['GET', 'PUT', 'DELETE'],
37
        ];
38
        if (\in_array($method, $allowedMethods[$uri], true)) {
39
            $jsonFile = __DIR__ . '/../Fixtures/json' . $uri . '-' . $method . '.json';
40
            $json = file_get_contents($jsonFile);
41
            return new Response(200, [], $json);
42
        }
43
        return new Response(500);
44
    }
45
}
46