Completed
Push — master ( d233b4...9019d9 )
by Tim
01:41
created

RoboFile::runTests()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
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-product-media
18
 * @link      http://www.techdivision.com
19
 */
20
21
use Lurker\Event\FilesystemEvent;
22
23
use Symfony\Component\Finder\Finder;
24
25
/**
26
 * Defines the available build tasks.
27
 *
28
 * @author    Tim Wagner <[email protected]>
29
 * @copyright 2016 TechDivision GmbH <[email protected]>
30
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
 * @link      https://github.com/techdivision/import-product-media
32
 * @link      http://www.techdivision.com
33
 *
34
 * @SuppressWarnings(PHPMD)
35
 */
36
class RoboFile extends \Robo\Tasks
37
{
38
39
    /**
40
     * The build properties.
41
     *
42
     * @var array
43
     */
44
    protected $properties = array(
45
        'base.dir' => __DIR__,
46
        'src.dir' => __DIR__ . '/src',
47
        'dist.dir' => __DIR__ . '/dist',
48
        'vendor.dir' => __DIR__ . '/vendor',
49
        'target.dir' => __DIR__ . '/target',
50
        'webapp.name' => 'import-cli-simple',
51
        'webapp.version' => '1.0.0-alpha5'
52
    );
53
54
    /**
55
     * Run's the composer install command.
56
     *
57
     * @return \Robo\Result The result
58
     */
59
    public function composerInstall()
60
    {
61
        // optimize autoloader with custom path
62
        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...
63
             ->preferDist()
64
             ->optimizeAutoloader()
65
             ->run();
66
    }
67
68
    /**
69
     * Run's the composer update command.
70
     *
71
     * @return \Robo\Result The result
72
     */
73
    public function composerUpdate()
74
    {
75
        // optimize autoloader with custom path
76
        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...
77
             ->preferDist()
78
             ->optimizeAutoloader()
79
             ->run();
80
    }
81
82
    /**
83
     * Clean up the environment for a new build.
84
     *
85
     * @return \Robo\Result The result
86
     */
87
    public function clean()
88
    {
89
        return $this->taskDeleteDir($this->properties['target.dir'])->run();
90
    }
91
92
    /**
93
     * Prepare's the environment for a new build.
94
     *
95
     * @return \Robo\Result The result
96
     */
97
    public function prepare()
98
    {
99
        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...
100
             ->mkdir($this->properties['dist.dir'])
101
             ->mkdir($this->properties['target.dir'])
102
             ->mkdir(sprintf('%s/reports', $this->properties['target.dir']))
103
             ->run();
104
    }
105
106
    /**
107
     * Run's the PHPMD.
108
     *
109
     * @return \Robo\Result The result
110
     */
111 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...
112
    {
113
114
        // run the mess detector
115
        return $this->_exec(
116
            sprintf(
117
                '%s/bin/phpmd %s xml phpmd.xml --reportfile %s/reports/pmd.xml --ignore-violations-on-exit',
118
                $this->properties['vendor.dir'],
119
                $this->properties['src.dir'],
120
                $this->properties['target.dir']
121
            )
122
        );
123
    }
124
125
    /**
126
     * Run's the PHPCPD.
127
     *
128
     * @return \Robo\Result The result
129
     */
130 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...
131
    {
132
133
        // run the copy past detector
134
        return $this->_exec(
135
            sprintf(
136
                '%s/bin/phpcpd %s --log-pmd %s/reports/pmd-cpd.xml',
137
                $this->properties['vendor.dir'],
138
                $this->properties['src.dir'],
139
                $this->properties['target.dir']
140
            )
141
        );
142
    }
143
144
    /**
145
     * Run's the PHPCodeSniffer.
146
     *
147
     * @return \Robo\Result The result
148
     */
149 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...
150
    {
151
152
        // run the code sniffer
153
        return $this->_exec(
154
            sprintf(
155
                '%s/bin/phpcs -n --report-full --extensions=php --standard=phpcs.xml --report-checkstyle=%s/reports/phpcs.xml %s',
156
                $this->properties['vendor.dir'],
157
                $this->properties['target.dir'],
158
                $this->properties['src.dir']
159
            )
160
        );
161
    }
162
163
    /**
164
     * Run's the PHPUnit tests.
165
     *
166
     * @return \Robo\Result The result
167
     */
168
    public function runTests()
169
    {
170
171
        // run PHPUnit
172
        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...
173
             ->configFile('phpunit.xml')
174
             ->run();
175
    }
176
177
    /**
178
     * The complete build process.
179
     *
180
     * @return void
181
     */
182
    public function build()
183
    {
184
185
        // stop the build on first failure of a task
186
        $this->stopOnFail(true);
187
188
        // process the build
189
        $this->clean();
190
        $this->prepare();
191
        $this->runCs();
192
        $this->runCpd();
193
        $this->runMd();
194
        $this->runTests();
195
    }
196
}
197