InstallerContract   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 67
Duplicated Lines 28.36 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 0
dl 19
loc 67
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
scaffold() 0 1 ?
A installPackage() 0 7 2
A runCommands() 0 6 2
A terminal() 19 33 5

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 Lacasera\ApiJwtScaffold\Installers;
4
5
abstract class InstallerContract
6
{
7
8
    abstract public function scaffold();
9
10
    /**
11
     * install laravel-passport package using composer
12
     * @param $package
13
     * @return array|bool
14
     */
15
    public function installPackage($package)
16
    {
17
        if (!class_exists("Laravel\Passport\Client")) {
18
            return $this->terminal("composer require ${package}");
19
        }
20
        return true;
21
    }
22
23
    /**
24
     * run additional commands needed by passport
25
     * @param array $commands
26
     */
27
    public function runCommands(array $commands)
28
    {
29
        foreach ($commands as $cmd) {
30
            $this->terminal("php artisan $cmd -q");
31
        }
32
    }
33
34
    /**
35
     * @param $command
36
     * @return array
37
     */
38
    public function terminal($command)
39
    {
40 View Code Duplication
        if (function_exists('system')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
41
            ob_start();
42
            system($command, $status);
43
            $output = ob_get_contents();
44
            ob_end_clean();
45
46
            return compact('output', 'status');
47
        }
48
49 View Code Duplication
        if (function_exists('passthru')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
50
            ob_start();
51
            passthru($command, $status);
52
            $output = ob_get_contents();
53
            ob_end_clean();
54
55
            return compact('output', 'status');
56
        }
57
58
        if (function_exists('exec')) {
59
            exec($command, $output, $status);
60
            $output = implode("&quot;n&quot;", $output);
61
62
            return compact('output', 'status');
63
        }
64
65
        if (function_exists('shell_exec')) {
66
            $output = shell_exec($command) ;
67
        }
68
69
        return compact('output', 'status');
70
    }
71
}
72