CreateFilesStep   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
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 47
ccs 15
cts 15
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A __invoke() 0 6 2
A createFile() 0 18 3
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 CreateFilesStep implements SymfifyStep
11
{
12
    /**
13
     * @var OutputInterface
14
     */
15
    private $output;
16
17
    /**
18
     * @var array
19
     */
20
    private $files = ['src/AppKernel.php', 'web/index.php'];
21
22 6
    public function __construct(OutputInterface $output, array $files = [])
23
    {
24 6
        $this->files = $files ?: $this->files;
25 6
        $this->output = $output;
26
    }
27
28 4
    public function __invoke()
29
    {
30 4
        foreach ($this->files as $file) {
31 4
            $this->createFile($file);
32
        }
33
    }
34
35
    /**
36
     * @param string $file
37
     */
38 4
    private function createFile($file)
39
    {
40 4
        if (\file_exists($file)) {
41 1
            $this->output->writeln(\sprintf('The file already exists: <comment>%s</comment>', $file));
42
43 1
            return;
44
        }
45
46 4
        $templateFile = __DIR__ . '/../../templates/' . $file;
47
48 4
        if (!\file_exists($templateFile)) {
49 1
            throw new \InvalidArgumentException(\sprintf('The template file not found: "%s".', $templateFile));
50
        }
51
52 3
        $this->output->writeln(\sprintf('Creating <comment>%s</comment>', $file));
53
54 3
        \file_put_contents($file, \file_get_contents($templateFile));
55
    }
56
}
57