DummyHttpClient::createEndpoint()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 4
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace TomPHP\HalClient\HttpClient;
4
5
use TomPHP\HalClient\HttpClient;
6
use Zend\Diactoros\Response;
7
8
final class DummyHttpClient implements HttpClient
9
{
10
    const METHOD_GET = 'GET';
11
12
    /** @var array */
13
    private $endpoints = [
14
        self::METHOD_GET => [],
15
    ];
16
17
    /**
18
     * @param string $method
19
     * @param string $url
20
     * @param string $contentType
21
     * @param string $body
22
     */
23
    public function createEndpoint($method, $url, $contentType, $body)
24
    {
25
        $this->endpoints[$method][$url] = new Response(
26
            "data://text/plain,$body",
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $body instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
27
            200,
28
            ['content-type' => $contentType]
29
        );
30
    }
31
32
    public function get($url)
33
    {
34
        return $this->endpoints[self::METHOD_GET][$url];
35
    }
36
}
37