Passed
Push — 2.0 ( 6cb80b...404407 )
by Samuel
02:35
created

AbstractResponse::getStatus()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SMartins\Exceptions\Response;
4
5
use Illuminate\Http\JsonResponse;
6
7
abstract class AbstractResponse
8
{
9
    /**
10
     * The HTTP status code.
11
     *
12
     * @var int
13
     */
14
    protected $status;
15
16
    /**
17
     * The errors on response.
18
     *
19
     * @var \SMartins\Exceptions\JsonApi\ErrorCollection
20
     */
21
    protected $errors;
22
23
    /**
24
     * Create new JsonApi response passing the errors.
25
     *
26
     * @param \SMartins\Exceptions\JsonApi\ErrorCollection $errors
27
     *
28
     */
29
    public function __construct(ErrorHandledCollectionInterface $errors)
30
    {
31
        $this->errors = $errors;
0 ignored issues
show
Documentation Bug introduced by
$errors is of type SMartins\Exceptions\Resp...dledCollectionInterface, but the property $errors was declared to be of type SMartins\Exceptions\JsonApi\ErrorCollection. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
32
33
        $this->setStatus((int) $this->errors->getStatusCode());
34
    }
35
36
    /**
37
     * Get the HTTP status code.
38
     *
39
     * @return  int
40
     */
41
    public function getStatus()
42
    {
43
        return $this->status;
44
    }
45
46
    /**
47
     * Set the HTTP status code.
48
     *
49
     * @param  int  $status  The HTTP status code.
50
     *
51
     * @return  self
52
     */
53
    public function setStatus(int $status)
54
    {
55
        $this->status = $status;
56
57
        return $this;
58
    }
59
60
    /**
61
     * Get the errors on response.
62
     *
63
     * @return \SMartins\Exceptions\JsonApi\ErrorCollection
64
     */
65
    public function getErrors()
66
    {
67
        return $this->errors;
68
    }
69
70
    /**
71
     * Returns JSON response.
72
     *
73
     * @return \Illuminate\Http\JsonResponse
74
     */
75
    abstract public function json(): JsonResponse;
76
}
77