Completed
Push — master ( fc3d6f...f7b1d9 )
by Sergi Tur
28:05
created

Route   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 77
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 2
dl 77
loc 77
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A getReplacements() 4 4 1
A setReplacements() 4 4 1
A code() 7 7 1
getStubPath() 1 1 ?
obtainReplacements() 1 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
3
namespace Acacha\AdminLTETemplateLaravel\Console\Routes;
4
5
use Acacha\Filesystem\Compiler\StubFileCompiler;
6
use Acacha\Filesystem\Filesystem;
7
8
/**
9
 * Class Route.
10
 *
11
 * @package Acacha\AdminLTETemplateLaravel\Console\Routes
12
 */
13 View Code Duplication
abstract class Route implements GeneratesCode
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...
14
{
15
16
    /**
17
     * Compiler for stub file.
18
     *
19
     * @var StubFileCompiler
20
     */
21
    protected $compiler;
22
23
    /**
24
     * Compiler for stub file.
25
     *
26
     * @var Filesystem
27
     */
28
    protected $filesystem;
29
30
    /**
31
     * Replacements.
32
     *
33
     * @var array
34
     */
35
    protected $replacements;
36
37
    /**
38
     * Route constructor.
39
     *
40
     * @param StubFileCompiler $compiler
41
     * @param Filesystem $filesystem
42
     */
43
    public function __construct(StubFileCompiler $compiler, Filesystem $filesystem)
44
    {
45
        $this->compiler = $compiler;
46
        $this->filesystem = $filesystem;
47
    }
48
49
    /**
50
     * @return array
51
     */
52
    public function getReplacements()
53
    {
54
        return $this->replacements;
55
    }
56
57
    /**
58
     * @param array $replacements
59
     */
60
    public function setReplacements($replacements)
61
    {
62
        $this->replacements = $replacements;
63
    }
64
65
    /**
66
     * Generate route code.
67
     */
68
    public function code()
69
    {
70
        return $this->compiler->compile(
71
            $this->filesystem->get($this->getStubPath()),
72
            $this->obtainReplacements()
73
        );
74
    }
75
76
    /**
77
     * Get stub path.
78
     *
79
     * @return mixed
80
     */
81
    abstract protected function getStubPath();
82
83
    /**
84
     * Obtain replacements for stub.
85
     *
86
     * @return mixed
87
     */
88
    abstract protected function obtainReplacements();
89
}
90