CustomRuleMakeCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 64
loc 64
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getStub() 4 4 1
A getDefaultNamespace() 6 6 2
A getNameInput() 11 11 2

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
3
namespace PerfectOblivion\Valid\Commands;
4
5
use Illuminate\Support\Facades\Config;
6
use Illuminate\Console\GeneratorCommand;
7
8 View Code Duplication
class CustomRuleMakeCommand extends GeneratorCommand
0 ignored issues
show
Duplication introduced by
This class 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...
9
{
10
    /**
11
     * The console command signature.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'adr:rule {name}';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Create a new Custom Rule';
23
24
    /**
25
     * The type of class being generated.
26
     *
27
     * @var string
28
     */
29
    protected $type = 'Custom Rule';
30
31
    /**
32
     * Get the stub file for the generator.
33
     *
34
     * @return string
35
     */
36
    protected function getStub()
37
    {
38
        return __DIR__.'/stubs/custom-rule.stub';
39
    }
40
41
    /**
42
     * Get the default namespace for the class.
43
     *
44
     * @param  string  $rootNamespace
45
     *
46
     * @return string
47
     */
48
    protected function getDefaultNamespace($rootNamespace)
49
    {
50
        $namespace = studly_case(trim(Config::get('valid.rules.namespace')));
51
52
        return $namespace ? $rootNamespace.'\\'.$namespace : $rootNamespace;
53
    }
54
55
    /**
56
     * Get the desired class name from the input.
57
     *
58
     * @return string
59
     */
60
    protected function getNameInput()
61
    {
62
        $input = studly_case(trim($this->argument('name')));
63
        $ruleSuffix = Config::get('valid.rules.suffix');
64
65
        if (Config::get('valid.rules.override_duplicate_suffix')) {
66
            return str_finish($input, $ruleSuffix);
67
        }
68
69
        return $input.$ruleSuffix;
70
    }
71
}
72