FormbuilderRequest::rules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 10
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace MedianetDev\BackpackForm\Http\Requests;
4
5
use Illuminate\Foundation\Http\FormRequest;
6
7
class FormbuilderRequest extends FormRequest
8
{
9
    /**
10
     * Determine if the user is authorized to make this request.
11
     *
12
     * @return bool
13
     */
14
    public function authorize()
15
    {
16
        // only allow updates if the user is logged in
17
        return backpack_auth()->check();
18
    }
19
20
    /**
21
     * Get the validation rules that apply to the request.
22
     *
23
     * @return array
24
     */
25
    public function rules()
26
    {
27
        $locale = locale();
0 ignored issues
show
Bug introduced by
The function locale 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

27
        $locale = /** @scrutinizer ignore-call */ locale();
Loading history...
28
        return [
29
            $locale .'.title'       => 'required|min:3|max:255',
30
            $locale .'.text_button'       => 'required|min:1|max:255',
31
            'intro'       => 'nullable',
32
            'form'        => 'nullable',
33
            'mail_to'     => 'required_if:by_mail,1|max:255',
34
            'field_mail_name'     => 'required_if:copy_user,1|max:255',
35
        ];
36
    }
37
38
    /**
39
     * Get the validation attributes that apply to the request.
40
     *
41
     * @return array
42
     */
43
    public function attributes()
44
    {
45
        $language = default_language();
0 ignored issues
show
Bug introduced by
The function default_language 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

45
        $language = /** @scrutinizer ignore-call */ default_language();
Loading history...
46
        $attributes[$language . '.title'] = __('medianet-dev.backpack-form::formbuilder.labels.title') . ' ' . trans('medianet-dev.backpack-form::formbuilder.common.in_langue') . ' ' . trans('medianet-dev.backpack-form::formbuilder.languages.' . $language);
0 ignored issues
show
Bug introduced by
Are you sure trans('medianet-dev.back...lder.common.in_langue') of type array|string can be used in concatenation? ( Ignorable by Annotation )

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

46
        $attributes[$language . '.title'] = __('medianet-dev.backpack-form::formbuilder.labels.title') . ' ' . /** @scrutinizer ignore-type */ trans('medianet-dev.backpack-form::formbuilder.common.in_langue') . ' ' . trans('medianet-dev.backpack-form::formbuilder.languages.' . $language);
Loading history...
Comprehensibility Best Practice introduced by
$attributes was never initialized. Although not strictly required by PHP, it is generally a good practice to add $attributes = array(); before regardless.
Loading history...
Bug introduced by
Are you sure __('medianet-dev.backpac...mbuilder.labels.title') of type array|string can be used in concatenation? ( Ignorable by Annotation )

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

46
        $attributes[$language . '.title'] = /** @scrutinizer ignore-type */ __('medianet-dev.backpack-form::formbuilder.labels.title') . ' ' . trans('medianet-dev.backpack-form::formbuilder.common.in_langue') . ' ' . trans('medianet-dev.backpack-form::formbuilder.languages.' . $language);
Loading history...
Bug introduced by
Are you sure trans('medianet-dev.back...anguages.' . $language) of type array|string can be used in concatenation? ( Ignorable by Annotation )

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

46
        $attributes[$language . '.title'] = __('medianet-dev.backpack-form::formbuilder.labels.title') . ' ' . trans('medianet-dev.backpack-form::formbuilder.common.in_langue') . ' ' . /** @scrutinizer ignore-type */ trans('medianet-dev.backpack-form::formbuilder.languages.' . $language);
Loading history...
47
        $attributes['intro'] =__('medianet-dev.backpack-form::formbuilder.labels.intro');
48
        $attributes['form'] =  __('medianet-dev.backpack-form::formbuilder.labels.form');
49
        $attributes['text_button'] =   __('medianet-dev.backpack-form::formbuilder.labels.text_button');
50
        $attributes['mail_to'] =  __('medianet-dev.backpack-form::formbuilder.labels.mail_to');
51
        $attributes['by_mail'] =  __('medianet-dev.backpack-form::formbuilder.labels.by_mail');
52
        return $attributes;
53
    }
54
55
    /**
56
     * Get the validation messages that apply to the request.
57
     *
58
     * @return array
59
     */
60
    public function messages()
61
    {
62
63
        return [
64
            'mail_to.required_if'         => __('medianet-dev.backpack-form::formbuilder.validations.mail_to'),
65
            'field_mail_name.required_if' => __('medianet-dev.backpack-form::formbuilder.validations.field_mail_name'),
66
        ];
67
    }
68
}
69