Completed
Push — master ( eb45ad...71bd0c )
by Marcus
12s
created

RoboFile   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 159
Duplicated Lines 24.53 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

9 Methods

Rating   Name   Duplication   Size   Complexity  
A composerInstall() 0 8 1
A composerUpdate() 0 8 1
A clean() 0 4 1
A prepare() 0 8 1
A runMd() 13 13 1
A runCpd() 13 13 1
A runCs() 13 13 1
A build() 0 14 1
A runTests() 0 8 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
/**
4
 * RoboFile.php
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2016 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import-attribute
18
 * @link      http://www.techdivision.com
19
 */
20
21
use Lurker\Event\FilesystemEvent;
22
use Symfony\Component\Finder\Finder;
23
24
/**
25
 * Defines the available build tasks.
26
 *
27
 * @author    Tim Wagner <[email protected]>
28
 * @copyright 2016 TechDivision GmbH <[email protected]>
29
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
 * @link      https://github.com/techdivision/import-attribute
31
 * @link      http://www.techdivision.com
32
 *
33
 * @SuppressWarnings(PHPMD)
34
 */
35
class RoboFile extends \Robo\Tasks
36
{
37
38
    /**
39
     * The build properties.
40
     *
41
     * @var array
42
     */
43
    protected $properties = array(
44
        'base.dir' => __DIR__,
45
        'src.dir' => __DIR__ . '/src',
46
        'dist.dir' => __DIR__ . '/dist',
47
        'vendor.dir' => __DIR__ . '/vendor',
48
        'target.dir' => __DIR__ . '/target'
49
    );
50
51
    /**
52
     * Run's the composer install command.
53
     *
54
     * @return \Robo\Result The result
55
     */
56
    public function composerInstall()
57
    {
58
        // optimize autoloader with custom path
59
        return $this->taskComposerInstall()
0 ignored issues
show
Bug introduced by
The method preferDist does only exist in Robo\Task\Composer\Install, but not in Robo\Collection\CollectionBuilder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
60
             ->preferDist()
61
             ->optimizeAutoloader()
62
             ->run();
63
    }
64
65
    /**
66
     * Run's the composer update command.
67
     *
68
     * @return \Robo\Result The result
69
     */
70
    public function composerUpdate()
71
    {
72
        // optimize autoloader with custom path
73
        return $this->taskComposerUpdate()
0 ignored issues
show
Bug introduced by
The method preferDist does only exist in Robo\Task\Composer\Update, but not in Robo\Collection\CollectionBuilder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
74
             ->preferDist()
75
             ->optimizeAutoloader()
76
             ->run();
77
    }
78
79
    /**
80
     * Clean up the environment for a new build.
81
     *
82
     * @return \Robo\Result The result
83
     */
84
    public function clean()
85
    {
86
        return $this->taskDeleteDir($this->properties['target.dir'])->run();
87
    }
88
89
    /**
90
     * Prepare's the environment for a new build.
91
     *
92
     * @return \Robo\Result The result
93
     */
94
    public function prepare()
95
    {
96
        return $this->taskFileSystemStack()
0 ignored issues
show
Bug introduced by
The method mkdir does only exist in Robo\Task\Filesystem\FilesystemStack, but not in Robo\Collection\CollectionBuilder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
97
             ->mkdir($this->properties['dist.dir'])
98
             ->mkdir($this->properties['target.dir'])
99
             ->mkdir(sprintf('%s/reports', $this->properties['target.dir']))
100
             ->run();
101
    }
102
103
    /**
104
     * Run's the PHPMD.
105
     *
106
     * @return \Robo\Result The result
107
     */
108 View Code Duplication
    public function runMd()
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...
109
    {
110
111
        // run the mess detector
112
        return $this->_exec(
113
            sprintf(
114
                '%s/bin/phpmd %s xml phpmd.xml --reportfile %s/reports/pmd.xml --ignore-violations-on-exit',
115
                $this->properties['vendor.dir'],
116
                $this->properties['src.dir'],
117
                $this->properties['target.dir']
118
            )
119
        );
120
    }
121
122
    /**
123
     * Run's the PHPCPD.
124
     *
125
     * @return \Robo\Result The result
126
     */
127 View Code Duplication
    public function runCpd()
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...
128
    {
129
130
        // run the copy past detector
131
        return $this->_exec(
132
            sprintf(
133
                '%s/bin/phpcpd %s --exclude Utils --log-pmd %s/reports/pmd-cpd.xml',
134
                $this->properties['vendor.dir'],
135
                $this->properties['src.dir'],
136
                $this->properties['target.dir']
137
            )
138
        );
139
    }
140
141
    /**
142
     * Run's the PHPCodeSniffer.
143
     *
144
     * @return \Robo\Result The result
145
     */
146 View Code Duplication
    public function runCs()
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...
147
    {
148
149
        // run the code sniffer
150
        return $this->_exec(
151
            sprintf(
152
                '%s/bin/phpcs -n --report-full --extensions=php --standard=phpcs.xml --report-checkstyle=%s/reports/phpcs.xml %s',
153
                $this->properties['vendor.dir'],
154
                $this->properties['target.dir'],
155
                $this->properties['src.dir']
156
            )
157
        );
158
    }
159
160
    /**
161
     * Run's the PHPUnit tests.
162
     *
163
     * @return \Robo\Result The result
164
     */
165
    public function runTests()
166
    {
167
168
        // run PHPUnit
169
        return $this->taskPHPUnit(sprintf('%s/bin/phpunit', $this->properties['vendor.dir']))
0 ignored issues
show
Bug introduced by
The method configFile does only exist in Robo\Task\Testing\PHPUnit, but not in Robo\Collection\CollectionBuilder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
170
             ->configFile('phpunit.xml')
171
             ->run();
172
    }
173
174
    /**
175
     * The complete build process.
176
     *
177
     * @return void
178
     */
179
    public function build()
180
    {
181
182
        // stop the build on first failure of a task
183
        $this->stopOnFail(true);
184
185
        // process the build
186
        $this->clean();
187
        $this->prepare();
188
        $this->runCs();
189
        $this->runCpd();
190
        $this->runMd();
191
        $this->runTests();
192
    }
193
}
194