getSubscribedEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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\Domain\Services\ClassCommandHandlerMakerSubscriber as ClassCommandHandlerMakerSubscriberInterface;
14
use Saci\Console\Infrastructure\Domain\Services\PhpClass\CommandHandler;
15
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
16
use Symfony\Component\Filesystem\Filesystem;
17
18
class ClassCommandHandlerMakerSubscriber implements ClassCommandHandlerMakerSubscriberInterface, EventSubscriberInterface
19
{
20
21 2
    public function create(CommandWasCreated $commandWasCreated)
22
    {
23 2
        $classMaker = new CommandHandlerClassMaker($commandWasCreated->getCommand());
24 2
        $generateable = $classMaker->generate(new CommandHandler());
25 2
        $stringClass = GeneratorClassFactory::create()->generate($generateable);
26
27 2
        $stringClass = "<?php\n" . $stringClass;
28
29 2
        (new Filesystem())->dumpFile(
30 2
            $commandWasCreated->getCommand()->getLocalFileCommandHandler(),
31 2
            $stringClass
32
        );
33
34 2
        return true;
35
    }
36
37 2
    public static function getSubscribedEvents()
38
    {
39 2
        return [CommandWasCreated::NAME => 'create'];
40
    }
41
}