Test Failed
Push — master ( 2fa9b0...1565e2 )
by
unknown
01:50
created

ClassCommandMakerSubscriber::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 14
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: thales
5
 * Date: 17/01/2019
6
 * Time: 20:18
7
 */
8
9
namespace Saci\Console\Infrastructure\Domain\Services;
10
11
12
use Saci\Console\Domain\Events\CommandWasCreated;
13
use Saci\Console\Infrastructure\Domain\Services\PhpClass\Command;
14
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
15
use Symfony\Component\Filesystem\Filesystem;
16
17
class ClassCommandMakerSubscriber implements \Saci\Console\Domain\Services\ClassCommandMakerSubscriber, EventSubscriberInterface
18
{
19
20
    public function create(CommandWasCreated $commandWasCreated)
21
    {
22
        $classMaker = new CommandClassMaker($commandWasCreated->getCommand());
23
        $generateable = $classMaker->generate(new Command());
24
        $stringClass = GeneratorClassFactory::create()->generate($generateable);
25
26
        $stringClass = "<?php\n" . $stringClass;
27
28
        (new Filesystem())->dumpFile(
29
            $commandWasCreated->getCommand()->getLocalFileCommand(),
30
            $stringClass
31
        );
32
33
        return true;
34
    }
35
36
    public static function getSubscribedEvents()
37
    {
38
        return [CommandWasCreated::NAME => 'create'];
39
    }
40
}