Responder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 0
dl 0
loc 65
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A toResponse() 0 4 1
respond() 0 1 ?
A withPayload() 0 6 1
A withRequest() 0 6 1
1
<?php
2
3
namespace PerfectOblivion\Responder;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Contracts\Support\Responsable;
7
8
abstract class Responder implements Responsable
9
{
10
    /** @var mixed */
11
    protected $payload;
12
13
    /** @var \Illuminate\Http\Request */
14
    protected $request;
15
16
    /**
17
     * Construct a new base Responder.
18
     *
19
     * @param  \Illuminate\Http\Request  $request
20
     */
21
    public function __construct(Request $request)
0 ignored issues
show
Bug introduced by
You have injected the Request via parameter $request. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest().
Loading history...
22
    {
23
        $this->request = $request;
24
    }
25
26
    /**
27
     * Create an HTTP response that represents the object.
28
     *
29
     * @param  \Illuminate\Http\Request  $request
30
     *
31
     * @return \Illuminate\Http\Response
32
     */
33
    public function toResponse($request)
34
    {
35
        return $this->respond();
36
    }
37
38
    /**
39
     * Send a response.
40
     *
41
     * @return mixed
42
     */
43
    abstract public function respond();
44
45
    /**
46
     * Add the payload to the response.
47
     *
48
     * @param  mixed  $payload
49
     *
50
     * @return $this
51
     */
52
    public function withPayload($payload)
53
    {
54
        $this->payload = $payload;
55
56
        return $this;
57
    }
58
59
    /**
60
     * Add the request to the response. Allows FormRequest objects to be added to the responder.
61
     *
62
     * @param  \Illuminate\Http\Request  $request
63
     *
64
     * @return $this
65
     */
66
    public function withRequest(Request $request)
0 ignored issues
show
Bug introduced by
You have injected the Request via parameter $request. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest().
Loading history...
67
    {
68
        $this->request = $request;
69
70
        return $this;
71
    }
72
}
73