Completed
Pull Request — master (#34)
by Fèvre
04:53 queued 02:28
created

DiscussConversationValidator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 50
Duplicated Lines 62 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 31
loc 50
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 16 16 1
A update() 15 15 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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