Completed
Push — master ( 08375c...9f214f )
by Mohamed
11:05
created

StoreFormRequest::attributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Microboard\Http\Requests\Setting;
4
5
use Microboard\Models\Setting;
6
use Illuminate\Foundation\Http\FormRequest;
7
8
class StoreFormRequest extends FormRequest
9
{
10
    /**
11
     * Determine if the user is authorized to make this request.
12
     *
13
     * @return bool
14
     */
15
    public function authorize()
16
    {
17
        return auth()->user()->can('create', new Setting);
0 ignored issues
show
Bug introduced by
The method user does only exist in Illuminate\Contracts\Auth\Guard, but not in Illuminate\Contracts\Auth\Factory.

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...
18
    }
19
20
    /**
21
     * Get the validation rules that apply to the request.
22
     *
23
     * @return array
24
     */
25
    public function rules()
26
    {
27
        return [
28
			'key' => ['required', 'string', 'unique:settings'],
29
			'name' => ['required', 'string'],
30
			'value' => ['nullable', 'string'],
31
			'cast' => ['required', 'string']
32
        ];
33
    }
34
35
    /**
36
     * Get custom attributes for validator errors.
37
     *
38
     * @return array
39
     */
40
    public function attributes()
41
    {
42
        return trans('microboard::settings.fields');
43
    }
44
}
45