Request::response()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Http\Requests;
13
14
use Tinyissue\Form\FormInterface;
15
use Illuminate\Foundation\Http\FormRequest;
16
17
/**
18
 * Request is an abstract class for Form Request classes.
19
 *
20
 * @author Mohamed Alsharaf <[email protected]>
21
 */
22
abstract class Request extends FormRequest
23
{
24
    /**
25
     * An instance of Form.
26
     *
27
     * @var FormInterface
28
     */
29
    protected $form;
30
31
    /**
32
     * Class name of the form.
33
     *
34
     * @var string
35
     */
36
    protected $formClassName;
37
38
    /**
39
     * Set the instance of the form.
40
     *
41
     * @param FormInterface $form
42
     *
43
     * @return $this
44
     */
45 27
    public function setForm(FormInterface $form)
46
    {
47 27
        $this->form = $form;
48
49 27
        return $this;
50
    }
51
52
    /**
53
     * Returns an instance of the form.
54
     *
55
     * @return FormInterface
56
     */
57 27
    public function getForm()
58
    {
59 27
        return $this->form;
60
    }
61
62
    /**
63
     * Returns the class name of the form.
64
     *
65
     * @return string
66
     */
67 27
    public function getFormClassName()
68
    {
69 27
        return $this->formClassName;
70
    }
71
72
    /**
73
     * @return array
74
     */
75 27
    public function rules()
76
    {
77 27
        return $this->getForm()->rules();
78
    }
79
80
    /**
81
     * @return bool
82
     */
83 23
    public function authorize()
84
    {
85
        // Only allow logged in users
86 23
        return \Auth::check();
87
    }
88
89
    /**
90
     * @param array $errors
91
     *
92
     * @return mixed
93
     */
94 3
    public function response(array $errors)
95
    {
96 3
        return parent::response($errors)->with('notice-error', trans('tinyissue.we_have_some_errors'));
1 ignored issue
show
Bug introduced by
The method with does only exist in Illuminate\Http\RedirectResponse, but not in Illuminate\Http\JsonResponse.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
97
    }
98
99
    /**
100
     * @return string
101
     */
102 1
    protected function getRedirectUrl()
103
    {
104 1
        return $this->getForm()->getRedirectUrl();
105
    }
106
}
107