AsyncActionFormatter::format()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 1
1
<?php
2
namespace Workana\AsyncJobs\Formatter;
3
4
use Workana\AsyncJobs\AsyncAction;
5
6
class AsyncActionFormatter extends AggregateFormatterAware
7
{
8
    /**
9
     * {@inheritdoc}
10
     */
11
    public function canFormat($target)
12
    {
13
        return ($target instanceof AsyncAction);
14
    }
15
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function format($target)
20
    {
21
        $formattedParameters = array_map(function($value) {
22
            return '    ' . $this->aggregate->format($value);
23
        }, $target->getParameterValues());
24
25
        array_unshift($formattedParameters, '[');
26
        array_push($formattedParameters, ']');
27
28
        $paramDescription = implode(PHP_EOL, $formattedParameters);
29
30
        return strtr(':jobName :jobGroup with parameters :parametersDescription', [
31
            ':jobName' => $target->getName(),
32
            ':jobGroup' => (string) $target,
33
            ':parametersDescription' => $paramDescription,
34
        ]);
35
    }
36
}