Completed
Push — master ( 67c7d1...f02869 )
by Nicolas
02:52
created

Composer   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 84
Duplicated Lines 32.14 %

Coupling/Cohesion

Components 1
Dependencies 2
Metric Value
wmc 10
lcom 1
cbo 2
dl 27
loc 84
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A disableOutput() 0 4 1
A enableOutput() 0 10 2
A update() 9 9 2
A install() 9 9 2
A dumpAutoload() 0 6 1
A remove() 9 9 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 namespace Modules\Core\Services;
2
3
use Symfony\Component\Process\Process;
4
5
class Composer extends \Illuminate\Foundation\Composer
6
{
7
    protected $outputHandler = null;
8
    private $output;
9
10
    /**
11
     * Enable real time output of all commands.
12
     *
13
     * @param $command
14
     * @return void
15
     */
16
    public function enableOutput($command)
17
    {
18
        $this->output = function ($type, $buffer) use ($command) {
19
            if (Process::ERR === $type) {
20
                $command->info(trim('[ERR] > ' . $buffer));
21
            } else {
22
                $command->info(trim('> ' . $buffer));
23
            }
24
        };
25
    }
26
27
    /**
28
     * Disable real time output of all commands.
29
     *
30
     * @return void
31
     */
32
    public function disableOutput()
33
    {
34
        $this->output = null;
35
    }
36
37
    /**
38
     * Update all composer packages.
39
     *
40
     * @param  string $package
41
     * @return void
42
     */
43 View Code Duplication
    public function update($package = null)
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...
44
    {
45
        if (!is_null($package)) {
46
            $package = '"' . $package . '"';
47
        }
48
        $process = $this->getProcess();
49
        $process->setCommandLine(trim($this->findComposer() . ' update ' . $package));
50
        $process->run($this->output);
51
    }
52
53
    /**
54
     * Require a new composer package.
55
     *
56
     * @param  string $package
57
     * @return void
58
     */
59 View Code Duplication
    public function install($package)
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...
60
    {
61
        if (!is_null($package)) {
62
            $package = '"' . $package . '"';
63
        }
64
        $process = $this->getProcess();
65
        $process->setCommandLine(trim($this->findComposer() . ' require ' . $package));
66
        $process->run($this->output);
67
    }
68
69
    /**
70
     * @return void
71
     */
72
    public function dumpAutoload()
73
    {
74
        $process = $this->getProcess();
75
        $process->setCommandLine(trim($this->findComposer() . ' dump-autoload -o'));
76
        $process->run($this->output);
77
    }
78
79 View Code Duplication
    public function remove($package)
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...
80
    {
81
        if (!is_null($package)) {
82
            $package = '"' . $package . '"';
83
        }
84
        $process = $this->getProcess();
85
        $process->setCommandLine(trim($this->findComposer() . ' remove ' . $package));
86
        $process->run($this->output);
87
    }
88
}
89