Completed
Push — master ( a25c09...65bfb1 )
by Jakub
03:37
created

CreateDirectoriesStep   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 39
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 6 2
A createDirectory() 0 14 4
1
<?php
2
3
namespace Zalas\Symfify\Composer\SymfifyStep;
4
5
use Symfony\Component\Console\Output\OutputInterface;
6
use Zalas\Symfify\Composer\SymfifyStep;
7
8
class CreateDirectoriesStep implements SymfifyStep
9
{
10
    /**
11
     * @var OutputInterface
12
     */
13
    private $output;
14
15
    private $dirs = ['var/cache', 'var/logs', 'web', 'src'];
16
17 6
    public function __construct(OutputInterface $output)
18
    {
19 6
        $this->output = $output;
20 6
    }
21
22 4
    public function __invoke()
23
    {
24 4
        foreach ($this->dirs as $dir) {
25 4
            $this->createDirectory($dir);
26
        }
27 3
    }
28
29
    /**
30
     * @param string $path
31
     */
32 4
    private function createDirectory($path)
33
    {
34 4
        if (is_dir($path)) {
35 1
            $this->output->writeln(sprintf('The <comment>%s</comment> directory already exists', $path));
36
37 1
            return;
38
        }
39
40 4
        $this->output->writeln(sprintf('Creating the <comment>%s</comment> directory', $path));
41
42 4
        if (!@mkdir($path, 0777, true) && !@is_dir($path)) {
43 1
            throw new \RuntimeException(sprintf('Failed to create the "%s" directory.', $path));
44
        }
45
    }
46
}