CreateDirectoriesStep   A
last analyzed

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
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 39
ccs 12
cts 12
cp 1
rs 10

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