IsModuleExists   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 16
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 22 3
1
<?php
2
3
namespace HotRodCli\Jobs\Module;
4
5
use Symfony\Component\Console\Application;
6
use Symfony\Component\Filesystem\Filesystem;
7
use Symfony\Component\Console\Input\ArrayInput;
8
use HotRodCli\AppContainer;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class IsModuleExists
12
{
13
    protected $filesystem;
14
15
    protected $appContainer;
16
17
    public function __construct(Filesystem $filesystem, AppContainer $appContainer)
18
    {
19
        $this->filesystem = $filesystem;
20
        $this->appContainer = $appContainer;
21
    }
22
23
    public function handle(string $namespace, OutputInterface $output, $createNew = true)
24
    {
25
        $namespaceExp = explode('_', $namespace);
26
27
        $isExists = $this->filesystem->exists($this->appContainer->get('app_dir') . '/app/code/' . $namespaceExp[0] . '/' . $namespaceExp[1]);
28
29
        if (!$isExists && $createNew) {
30
            /** @var Application $application */
31
            $application = $this->appContainer->resolve(Application::class);
32
            $command = $application->find('module:create');
33
34
            $inputs = array(
35
                'namespace' => $namespace
36
            );
37
38
            $greetInput = new ArrayInput($inputs);
39
            $command->run($greetInput, $output);
40
41
            return true;
42
        }
43
44
        return $isExists;
45
    }
46
}
47