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

CreateUuidIdCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 100 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 9 9 1
A execute() 17 17 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 CreateUuidIdCommand 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-uuid-id')
20
            ->setDescription('Creates a UUID-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('uuid_id.php.twig', [
40
            'namespace' => $namespace,
41
            'idClassName' => $idClassName
42
        ]);
43
44
        file_put_contents($path . '/' . $idClassName . '.php', $id);
45
    }
46
}
47