Completed
Push — master ( 44f310...207ea5 )
by Torsten
03:42
created

CreateStringIdCommand::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 17
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 17
loc 17
ccs 0
cts 13
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lej\Command;
6
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11 View Code Duplication
class CreateStringIdCommand extends AbstractCommand
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    protected function configure()
17
    {
18
        $this
19
            ->setName('lej-ddd:create-string-id')
20
            ->setDescription('Creates a string-based identity.')
21
            ->addArgument('domain', InputArgument::REQUIRED, 'The name of the domain.')
22
            ->addArgument('context', InputArgument::REQUIRED, 'The name of the context.')
23
            ->addArgument('name', InputArgument::REQUIRED, 'The name of the identity.');
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    protected function execute(InputInterface $input, OutputInterface $output)
30
    {
31
        $twig = $this->twig();
32
33
        $path = $this->modelPath($input->getArgument('domain'), $input->getArgument('context'));
34
        $namespace = $this->modelNamespace($input->getArgument('domain'), $input->getArgument('context'));
35
        @mkdir($path, 0755, true);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
36
37
        $idClassName = $input->getArgument('name');
38
39
        $id = $twig->render('string_id.php.twig', [
40
            'namespace' => $namespace,
41
            'idClassName' => $idClassName
42
        ]);
43
44
        file_put_contents($path . '/' . $idClassName . '.php', $id);
45
    }
46
}
47