Completed
Push — master ( 6c8381...e53e0e )
by Pascal
02:44
created

Endpoint   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 3
Metric Value
wmc 6
c 4
b 0
f 3
lcom 2
cbo 2
dl 0
loc 67
ccs 16
cts 16
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getModel() 0 4 1
A getEndpointUrl() 0 10 2
A respond() 0 9 2
1
<?php namespace Atog\Api;
2
3
use Symfony\Component\HttpFoundation\Response;
4
5
/**
6
 * Abstract Class Endpoint
7
 * @package Atog\Api
8
 */
9
abstract class Endpoint
10
{
11
    /**
12
     * @var \Atog\Api\Client
13
     */
14
    protected $client;
15
    
16
    /**
17
     * @var \Atog\Api\Model
18
     */
19
    protected $model;
20
    
21
    /**
22
     * @var string
23
     */
24
    protected $endpoint;
25
    
26
    /**
27
     * Endpoint constructor.
28
     * @param \Atog\Api\Client $client
29
     * @param \Atog\Api\Model  $model
30
     */
31 8
    public function __construct(Client $client, Model $model)
32
    {
33 8
        $this->client = $client;
34 8
        $this->model = $model;
35 8
    }
36
37
    /**
38
     * @return \Atog\Api\Model
39
     */
40 3
    public function getModel()
41
    {
42 3
        return $this->model;
43
    }
44
    
45
    /**
46
     * Get the endpoint url for the request
47
     * @param string $path
48
     * @param bool   $withTrailingSlash
49
     * @return string
50
     */
51 1
    public function getEndpointUrl($path, $withTrailingSlash)
52
    {
53 1
        $url = $this->endpoint . '/' . $path;
54
        
55 1
        if ($withTrailingSlash) {
56 1
            $url = $url . '/';
57 1
        }
58
        
59 1
        return $url;
60
    }
61
62
    /**
63
     * @param \Symfony\Component\HttpFoundation\Response $response
64
     * @return \Atog\Api\Model|null
65
     */
66 2
    public function respond(Response $response)
67
    {
68
        // return new model instance with fetched content if response is okay
69 2
        if ($response->isOk()) {
70 1
            return $this->model->newInstance($response->getContent());
0 ignored issues
show
Documentation introduced by
$response->getContent() is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
71
        }
72
73 1
        return null;
74
    }
75
}
76