ClassCommandHandlerMakerSubscriber   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 10
dl 0
loc 22
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 14 1
A getSubscribedEvents() 0 3 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
}