Passed
Push — master ( 124f11...2f6734 )
by Anthony
02:33
created

ImportModuleCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
namespace PiouPiou\RibsAdminBundle\Command;
4
5
use Doctrine\ORM\EntityManagerInterface;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\EntityManagerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use PiouPiou\RibsAdminBundle\Entity\Module;
7
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
8
use Symfony\Component\Console\Input\InputArgument;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputArgument was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Symfony\Component\Console\Input\InputInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Symfony\Component\Console\Output\OutputInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Output\OutputInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Symfony\Component\Process\Exception\ProcessFailedException;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Proces...\ProcessFailedException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Symfony\Component\Process\Process;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Process\Process was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
14
class ImportModuleCommand extends ContainerAwareCommand
15
{
16
    private $em;
17
18
    /**
19
     * ImportModuleCommand constructor.
20
     * @param EntityManagerInterface $em
21
     * @param string|null $name
22
     */
23
    public function __construct(EntityManagerInterface $em, string $name = null)
24
    {
25
        parent::__construct($name);
26
        $this->em = $em;
27
    }
28
29
    protected function configure()
30
    {
31
        $this
32
            ->setName('ribsadmin:import-module')
33
            ->setDescription('Import a module in ribs admin')
34
            ->addArgument(
35
                'package-name',
36
                InputArgument::REQUIRED,
37
                'Name of composer package to import'
38
            )
39
            ->addArgument(
40
                'module-name',
41
                InputArgument::REQUIRED,
42
                'Name of package to display in app'
43
            )
44
        ;
45
    }
46
47
    protected function execute(InputInterface $input, OutputInterface $output)
48
    {
49
        $pacakge_name = $input->getArgument('package-name');
50
        $output->writeln("Start composer require " . $pacakge_name);
51
52
        $process = new Process("composer require " . $pacakge_name);
53
        $process->run(function ($type, $buffer) {
54
            echo $buffer;
55
        });
56
57
        if (!$process->isSuccessful()) {
58
            throw new ProcessFailedException($process);
59
        }
60
61
        $output->writeln("End composer require " . $pacakge_name);
62
        $output->writeln("Start insertion of module in database " . $pacakge_name);
63
64
        $module = new Module();
65
        $module->setPackageName($pacakge_name);
66
        $module->setTitle($input->getArgument('module-name'));
67
        $module->setActive(false);
68
        $module->setDisplayed(true);
69
        $this->em->persist($module);
70
        $this->em->flush();
71
72
        $output->writeln("Installation of " . $pacakge_name . " is finished. You have now to configure this module in your administration interface");
73
    }
74
}
75