Responder   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 3
cbo 1
dl 0
loc 86
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A toResponse() 0 4 1
respond() 0 1 ?
A withPayload() 0 6 1
A withRequest() 0 6 1
A flash() 0 4 1
1
<?php
2
3
namespace BrightComponents\Responder;
4
5
use Illuminate\Http\Request;
6
use DevMarketer\LaraFlash\LaraFlash;
7
use Illuminate\Contracts\Support\Responsable;
8
9
abstract class Responder implements Responsable
10
{
11
    /**
12
     * The response payload.
13
     *
14
     * @var mixed
15
     */
16
    protected $payload;
17
18
    /**
19
     * Laraflash for flashing to session.
20
     *
21
     * @var \DevMarketer\LaraFlash\LaraFlash
22
     */
23
    protected $flash;
24
25
    /**
26
     * Construct a new base Responder.
27
     *
28
     * @param  \Illuminate\Http\Request  $request
29
     * @param  \DevMarketer\LaraFlash\LaraFlash  $flash
30
     */
31
    public function __construct(Request $request, LaraFlash $flash)
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...
32
    {
33
        $this->request = $request;
0 ignored issues
show
Bug introduced by
The property request does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
34
        $this->flash = $flash;
35
    }
36
37
    /**
38
     * Create an HTTP response that represents the object.
39
     *
40
     * @param  \Illuminate\Http\Request  $request
41
     *
42
     * @return \Illuminate\Http\Response
43
     */
44
    public function toResponse($request)
45
    {
46
        return $this->respond();
47
    }
48
49
    /**
50
     * Send a response.
51
     *
52
     * @return mixed
53
     */
54
    abstract public function respond();
55
56
    /**
57
     * Add the payload to the response.
58
     *
59
     * @param  mixed  $payload
60
     *
61
     * @return $this
62
     */
63
    public function withPayload($payload)
64
    {
65
        $this->payload = $payload;
66
67
        return $this;
68
    }
69
70
    /**
71
     * Add the request to the response.
72
     *
73
     * @param  \Illuminate\Http\Request  $request
74
     *
75
     * @return $this
76
     */
77
    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...
78
    {
79
        $this->request = $request;
80
81
        return $this;
82
    }
83
84
    /**
85
     * Flash data to the session.
86
     *
87
     * @param  string $key
0 ignored issues
show
Bug introduced by
There is no parameter named $key. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
88
     * @param  mixed  $value
0 ignored issues
show
Bug introduced by
There is no parameter named $value. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
89
     */
90
    protected function flash($message, array $options = [])
91
    {
92
        return $this->flash->add($message, $options);
93
    }
94
}
95