CreateDirectoriesStep::createDirectory()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
ccs 7
cts 7
cp 1
rs 9.7998
cc 4
nc 3
nop 1
crap 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