RoboFile::runCpd()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 9
c 2
b 0
f 0
dl 0
loc 15
rs 9.9666
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * RoboFile.php
5
 *
6
 * PHP version 7
7
 *
8
 * @author    Tim Wagner <[email protected]>
9
 * @copyright 2021 TechDivision GmbH <[email protected]>
10
 * @license   https://opensource.org/licenses/MIT
11
 * @link      https://github.com/techdivision/import-serializer-csv
12
 * @link      http://www.techdivision.com
13
 */
14
15
use Lurker\Event\FilesystemEvent;
0 ignored issues
show
Bug introduced by
The type Lurker\Event\FilesystemEvent was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
17
use Symfony\Component\Finder\Finder;
18
19
/**
20
 * Defines the available build tasks.
21
 *
22
 * @author    Tim Wagner <[email protected]>
23
 * @copyright 2021 TechDivision GmbH <[email protected]>
24
 * @license   https://opensource.org/licenses/MIT
25
 * @link      https://github.com/techdivision/import-serializer-csv
26
 * @link      http://www.techdivision.com
27
 *
28
 * @SuppressWarnings(PHPMD)
29
 */
30
class RoboFile extends \Robo\Tasks
31
{
32
33
    /**
34
     * The build properties.
35
     *
36
     * @var array
37
     */
38
    protected $properties = array(
39
        'base.dir' => __DIR__,
40
        'src.dir' => __DIR__ . '/src',
41
        'dist.dir' => __DIR__ . '/dist',
42
        'vendor.dir' => __DIR__ . '/vendor',
43
        'target.dir' => __DIR__ . '/target'
44
    );
45
46
    /**
47
     * Run's the composer install command.
48
     *
49
     * @return \Robo\Result The result
50
     */
51
    public function composerInstall()
52
    {
53
        // optimize autoloader with custom path
54
        return $this->taskComposerInstall()
55
             ->preferDist()
56
             ->optimizeAutoloader()
57
             ->run();
58
    }
59
60
    /**
61
     * Run's the composer update command.
62
     *
63
     * @return \Robo\Result The result
64
     */
65
    public function composerUpdate()
66
    {
67
        // optimize autoloader with custom path
68
        return $this->taskComposerUpdate()
69
             ->preferDist()
70
             ->optimizeAutoloader()
71
             ->run();
72
    }
73
74
    /**
75
     * Clean up the environment for a new build.
76
     *
77
     * @return \Robo\Result The result
78
     */
79
    public function clean()
80
    {
81
        return $this->taskDeleteDir($this->properties['target.dir'])->run();
82
    }
83
84
    /**
85
     * Prepare's the environment for a new build.
86
     *
87
     * @return \Robo\Result The result
88
     */
89
    public function prepare()
90
    {
91
        return $this->taskFileSystemStack()
92
             ->mkdir($this->properties['dist.dir'])
93
             ->mkdir($this->properties['target.dir'])
94
             ->mkdir(sprintf('%s/reports', $this->properties['target.dir']))
95
             ->run();
96
    }
97
98
    /**
99
     * Run's the PHPMD.
100
     *
101
     * @return \Robo\Result The result
102
     */
103
    public function runMd()
104
    {
105
106
        // run the mess detector
107
        return $this->_exec(
108
            sprintf(
109
                '%s/bin/phpmd %s xml phpmd.xml --reportfile %s/reports/pmd.xml --ignore-violations-on-exit',
110
                $this->properties['vendor.dir'],
111
                $this->properties['src.dir'],
112
                $this->properties['target.dir']
113
            )
114
        );
115
    }
116
117
    /**
118
     * Run's the PHPCPD.
119
     *
120
     * @return \Robo\Result The result
121
     */
122
    public function runCpd()
123
    {
124
        // prepare the patterns for the files that has to be ignored
125
        $ignore = array(
126
            $this->properties['src.dir'].'/CategoryCsvSerializer.php',
127
        );
128
129
        // run the copy past detector
130
        return $this->_exec(
131
            sprintf(
132
                '%s/bin/phpcpd %s --exclude %s --log-pmd %s/reports/pmd-cpd.xml',
133
                $this->properties['vendor.dir'],
134
                $this->properties['src.dir'],
135
                implode(' --exclude ', $ignore),
136
                $this->properties['target.dir']
137
            )
138
        );
139
    }
140
141
    /**
142
     * Run's the PHPCodeSniffer.
143
     *
144
     * @return \Robo\Result The result
145
     */
146
    public function runCs()
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']))
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