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

CreateEntityCommand::execute()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 0
cts 20
cp 0
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 16
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
class CreateEntityCommand extends AbstractCommand
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    protected function configure()
17
    {
18
        $this
19
            ->setName('lej-ddd:create-entity')
20
            ->setDescription('Creates an entity.')
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 entity.');
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
        $entityClassName = $input->getArgument('name');
38
        $idClassName = $entityClassName . 'Id';
39
40
        $entity = $twig->render('entity.php.twig', [
41
            'namespace' => $namespace,
42
            'entityClassName' => $entityClassName,
43
            'idClassName' => $idClassName
44
        ]);
45
46
        $id = $twig->render('uuid_id.php.twig', [
47
            'namespace' => $namespace,
48
            'idClassName' => $idClassName
49
        ]);
50
51
        file_put_contents($path . '/' . $entityClassName . '.php', $entity);
52
        file_put_contents($path . '/' . $idClassName . '.php', $id);
53
    }
54
}
55