StoreBlockerRequest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 63
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A authorize() 0 7 2
A blockedFillData() 0 12 2
A messages() 0 5 1
A rules() 0 9 1
1
<?php
2
3
namespace jeremykenedy\LaravelBlocker\App\Http\Requests;
4
5
use Illuminate\Foundation\Http\FormRequest;
0 ignored issues
show
Bug introduced by
The type Illuminate\Foundation\Http\FormRequest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Illuminate\Http\Request;
7
use jeremykenedy\LaravelBlocker\App\Rules\UniqueBlockerItemValueEmail;
8
9
class StoreBlockerRequest extends FormRequest
10
{
11
    /**
12
     * Determine if the user is authorized to make this request.
13
     *
14
     * @return bool
15
     */
16
    public function authorize()
17
    {
18
        if (config('laravelblocker.rolesEnabled')) {
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

18
        if (/** @scrutinizer ignore-call */ config('laravelblocker.rolesEnabled')) {
Loading history...
19
            return config('laravelblocker.rolesMiddlware');
20
        }
21
22
        return true;
23
    }
24
25
    /**
26
     * Get the validation rules that apply to the request.
27
     *
28
     * @return array
29
     */
30
    public function rules()
31
    {
32
        $id = $this->route('blocker');
33
34
        return [
35
            'typeId' => 'required|max:255|integer',
36
            'value'  => ['required', 'max:255', 'string', 'unique:laravel_blocker,value,'.$id.',id', new UniqueBlockerItemValueEmail(Request::input('typeId'))],
37
            'note'   => 'nullable|max:500|string',
38
            'userId' => 'nullable|max:255|integer',
39
        ];
40
    }
41
42
    /**
43
     * Get the error messages for the defined validation rules.
44
     *
45
     * @return array
46
     */
47
    public function messages()
48
    {
49
        return [
50
            'typeId.required'   => trans('laravelblocker::laravelblocker.validation.blockedTypeRequired'),
0 ignored issues
show
Bug introduced by
The function trans was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
            'typeId.required'   => /** @scrutinizer ignore-call */ trans('laravelblocker::laravelblocker.validation.blockedTypeRequired'),
Loading history...
51
            'value.required'    => trans('laravelblocker::laravelblocker.validation.blockedValueRequired'),
52
        ];
53
    }
54
55
    /**
56
     * Return the fields and values for a Blocked Item.
57
     *
58
     * @return array
59
     */
60
    public function blockedFillData()
61
    {
62
        $userId = null;
63
        if ($this->userId) {
64
            $userId = $this->userId;
65
        }
66
67
        return [
68
            'typeId'    => $this->typeId,
69
            'value'     => $this->value,
70
            'note'      => $this->note,
71
            'userId'    => $userId,
72
        ];
73
    }
74
}
75