Gulp   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 73
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A pluginName() 4 4 1
B __construct() 34 34 6
A execute() 17 17 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 Fabrica\Tools\Plugin;
4
5
use Fabrica\Tools\Builder;
6
use Fabrica\Models\Infra\Ci\Build;
7
use Fabrica\Tools\Plugin;
8
9
/**
10
 * Gulp Plugin - Provides access to gulp functionality.
11
 *
12
 * @author Dirk Heilig <[email protected]>
13
 */
14 View Code Duplication
class Gulp extends Plugin
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...
15
{
16
    protected $task;
17
    protected $preferDist;
18
    protected $gulpfile;
19
20
    /**
21
     * @return string
22
     */
23
    public static function pluginName()
24
    {
25
        return 'gulp';
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function __construct(Builder $builder, Build $build, array $options = [])
32
    {
33
        parent::__construct($builder, $build, $options);
34
35
        $this->task = null;
36
37
        // deprecated compatibility option
38
        if (isset($options['gulp']) && !isset($options['executable'])) {
39
            $options['executable'] = $options['gulp'];
40
        }
41
42
        /**
43
 * @deprecated Option "gulp" is deprecated and will be deleted in version 2.0. Use the option "binary_path" and "binary_name" instead. 
44
*/
45
        if (isset($options['gulp'])) {
46
            $this->builder->logWarning(
47
                '[DEPRECATED] Option "gulp" is deprecated and will be deleted in version 2.0. Use the option "binary_path" and "binary_name" instead.'
48
            );
49
50
            $this->executable = $options['gulp'];
51
        } else {
52
            $this->executable = $this->findBinary('gulp');
53
        }
54
55
        $this->gulpfile = 'gulpfile.js';
56
57
        if (isset($options['task'])) {
58
            $this->task = $options['task'];
59
        }
60
61
        if (isset($options['gulpfile'])) {
62
            $this->gulpfile = $options['gulpfile'];
63
        }
64
    }
65
66
    /**
67
     * Executes gulp and runs a specified command (e.g. install / update)
68
     */
69
    public function execute()
70
    {
71
        // if npm does not work, we cannot use gulp, so we return false
72
        $cmd = 'cd %s && npm install';
73
        if (!$this->builder->executeCommand($cmd, $this->directory)) {
74
            return false;
75
        }
76
77
        // build the gulp command
78
        $cmd = 'cd %s && ' . $this->executable;
79
        $cmd .= ' --no-color';
80
        $cmd .= ' --gulpfile %s';
81
        $cmd .= ' %s'; // the task that will be executed
82
83
        // and execute it
84
        return $this->builder->executeCommand($cmd, $this->directory, $this->gulpfile, $this->task);
85
    }
86
}
87