AsyncEventFormatter::format()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
cc 1
eloc 14
nc 1
nop 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
}