CallbackTaskRunner::supports()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Zenstruck\ScheduleBundle\Schedule\Task\Runner;
4
5
use Zenstruck\ScheduleBundle\Schedule\Task;
6
use Zenstruck\ScheduleBundle\Schedule\Task\CallbackTask;
7
use Zenstruck\ScheduleBundle\Schedule\Task\Result;
8
use Zenstruck\ScheduleBundle\Schedule\Task\TaskRunner;
9
10
/**
11
 * @author Kevin Bond <[email protected]>
12
 */
13
final class CallbackTaskRunner implements TaskRunner
14
{
15
    /**
16
     * @param CallbackTask $task
17
     */
18 8
    public function __invoke(Task $task): Result
19
    {
20 8
        $output = $task->getCallback()();
0 ignored issues
show
Bug introduced by
The method getCallback() does not exist on Zenstruck\ScheduleBundle\Schedule\Task. It seems like you code against a sub-type of Zenstruck\ScheduleBundle\Schedule\Task such as Zenstruck\ScheduleBundle...edule\Task\CallbackTask. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

20
        $output = $task->/** @scrutinizer ignore-call */ getCallback()();
Loading history...
21
22 8
        return Result::successful($task, self::stringify($output));
23
    }
24
25 1
    public function supports(Task $task): bool
26
    {
27 1
        return $task instanceof CallbackTask;
28
    }
29
30
    /**
31
     * @param mixed $value
32
     */
33 8
    private static function stringify($value): ?string
34
    {
35 8
        if (null === $value) {
36 2
            return null;
37
        }
38
39 6
        if (\is_scalar($value)) {
40 3
            return (string) $value;
41
        }
42
43 3
        if (\is_object($value) && \method_exists($value, '__toString')) {
44 1
            return $value;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $value returns the type object which is incompatible with the type-hinted return null|string.
Loading history...
45
        }
46
47 2
        if (\is_object($value)) {
48 1
            return '[object] '.\get_class($value);
49
        }
50
51 1
        return '('.\gettype($value).')';
52
    }
53
}
54