TaskManagerService   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 42
c 0
b 0
f 0
wmc 4
lcom 1
cbo 5
ccs 0
cts 22
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A onFullTicketBuilt() 0 5 1
A process() 0 8 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