TaskManagerService::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 9
cp 0
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 3
crap 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace AppBuilder\Application\Module\TaskManager;
6
7
use AppBuilder\Application\Module\TaskManager\Factory\TaskFactory;
8
use AppBuilder\Application\Module\TaskManager\Task\Task;
9
use AppBuilder\Event\Application\FullTicketBuiltEvent;
10
use AppBuilder\Event\Application\FullTicketBuiltEventAware;
11
use Psr\Log\LoggerInterface;
12
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
13
use Symfony\Component\Filesystem\Exception\IOException;
14
15
class TaskManagerService implements FullTicketBuiltEventAware
16
{
17
    /** @var LoggerInterface */
18
    private $logger;
19
20
    /** @var EventDispatcherInterface */
21
    private $dispatcher;
22
23
    /** @var TaskFactory */
24
    private $taskFactory;
25
26
    public function __construct(
27
        TaskFactory $taskFactory,
28
        LoggerInterface $logger,
29
        EventDispatcherInterface $dispatcher
30
    ) {
31
        $this->taskFactory = $taskFactory;
32
        $this->logger      = $logger;
33
        $this->dispatcher  = $dispatcher;
34
    }
35
36
    /**
37
     * Creates proper task for given ticket and passes it to process.
38
     */
39
    public function onFullTicketBuilt(FullTicketBuiltEvent $event) : void
40
    {
41
        $task = $this->taskFactory->create($event->ticket());
42
        $this->process($task);
43
    }
44
45
    /**
46
     * Processes passed task with ticket.
47
     */
48
    private function process(Task $task) : void
49
    {
50
        try {
51
            $task->execute();
52
        } catch (IOException $exception) {
53
            $this->logger->warning($exception->getMessage(), [$exception]);
54
        }
55
    }
56
}
57