DummyHttpClient   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createEndpoint() 0 8 1
A get() 0 4 1
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