AsyncEventFormatter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 35
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A format() 0 21 1
A canFormat() 0 4 1
1
<?php
2
namespace Workana\AsyncJobs\Formatter;
3
4
use Workana\AsyncJobs\AsyncEvent;
5
6
/**
7
 * @author Carlos Frutos <[email protected]>
8
 */
9
class AsyncEventFormatter extends AggregateFormatterAware
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14
    public function format($target)
15
    {
16
        $event = $target->getEvent();
17
18
        $formattedParameters = array_map(function($value) {
19
            return '    ' . $this->aggregate->format($value);
20
        }, $event->getAll());
21
22
        array_unshift($formattedParameters, '[');
23
        array_push($formattedParameters, ']');
24
        $parametersDescription = implode(PHP_EOL, $formattedParameters);
25
26
        $eventClass = current(array_reverse(explode('\\', get_class($event))));
27
28
        return strtr(':jobName :jobGroup of type :eventClass with parameters :parametersDescription', [
29
            ':jobName' => $target->getName(),
30
            ':jobGroup' => (string) $target,
31
            ':eventClass' => $eventClass,
32
            ':parametersDescription' => $parametersDescription
33
        ]);
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function canFormat($target)
40
    {
41
        return ($target instanceof AsyncEvent);
42
    }
43
}