Completed
Pull Request — master (#34)
by Fèvre
11:36 queued 08:46
created

DiscussConversationValidator::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
dl 15
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 2
1
<?php
2
namespace Xetaravel\Models\Validators;
3
4
use Illuminate\Support\Facades\Validator as FacadeValidator;
5
use Illuminate\Validation\Rule;
6
use Illuminate\Validation\Validator;
7
use Xetaravel\Models\DiscussCategory;
8
9
class DiscussConversationValidator
10
{
11
    /**
12
     * Get a validator for an incoming create request.
13
     *
14
     * @param array $data The data to validate.
15
     *
16
     * @return \Illuminate\Validation\Validator
17
     */
18 View Code Duplication
    public static function create(array $data): Validator
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
    {
20
        $categories = DiscussCategory::pluckLocked('id');
21
22
        $rules = [
23
            'title' => 'required|min:5',
24
            'category_id' => [
25
                'required',
26
                'integer',
27
                Rule::in($categories->toArray())
28
            ],
29
            'content' => 'required|min:10'
30
        ];
31
32
        return FacadeValidator::make($data, $rules);
33
    }
34
35
    /**
36
     * Get a validator for an incoming update request.
37
     *
38
     * @param array $data The data to validate.
39
     * @param int $id The actual article id to ignore the slug rule.
40
     *
41
     * @return \Illuminate\Validation\Validator
42
     */
43 View Code Duplication
    public static function update(array $data, int $id): Validator
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
    {
45
        $categories = DiscussCategory::pluckLocked('id');
46
47
        $rules = [
48
            'title' => 'required|min:5',
49
            'category_id' => [
50
                'required',
51
                'integer',
52
                Rule::in($categories->toArray())
53
            ]
54
        ];
55
56
        return FacadeValidator::make($data, $rules);
57
    }
58
}
59