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

CreateEntityCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 2
cbo 3
dl 0
loc 44
ccs 0
cts 29
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 9 1
B execute() 0 25 1
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