Completed
Pull Request — master (#1)
by Clayton
05:31
created

Responder::withRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace BrightComponents\Responder;
4
5
use Illuminate\Http\Request;
6
use DevMarketer\LaraFlash\LaraFlash;
7
use BrightComponents\Common\Payloads\AbstractPayload;
8
9
abstract class Responder
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
     * Send a response.
39
     *
40
     * @return mixed
41
     */
42
    abstract public function respond();
43
44
    /**
45
     * Add the payload to the response.
46
     *
47
     * @param  mixed  $payload
48
     *
49
     * @return $this
50
     */
51
    public function withPayload($payload)
52
    {
53
        $this->payload = $payload instanceof AbstractPayload ? $payload->getData() : $payload;
0 ignored issues
show
Bug introduced by
The class BrightComponents\Common\Payloads\AbstractPayload does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
54
55
        return $this;
56
    }
57
58
    /**
59
     * Add the request to the response.
60
     *
61
     * @param  \Illuminate\Http\Request  $request
62
     *
63
     * @return $this
64
     */
65
    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...
66
    {
67
        $this->request = $request;
68
69
        return $this;
70
    }
71
72
    /**
73
     * Flash data to the session.
74
     *
75
     * @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...
76
     * @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...
77
     */
78
    protected function flash($message, array $options = [])
79
    {
80
        return $this->flash->add($message, $options);
81
    }
82
}
83