Passed
Pull Request — master (#8)
by Kevin
15:42
created

MissingDependency   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
eloc 10
c 1
b 0
f 1
dl 0
loc 27
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A noExtensionHandler() 0 11 3
A noTaskRunner() 0 7 2
A __construct() 0 3 1
1
<?php
2
3
namespace Zenstruck\ScheduleBundle\Schedule\Exception;
4
5
use Zenstruck\ScheduleBundle\Schedule\HasMissingDependencyMessage;
6
use Zenstruck\ScheduleBundle\Schedule\Task;
7
8
/**
9
 * @author Kevin Bond <[email protected]>
10
 */
11
final class MissingDependency extends \LogicException
12
{
13
    public function __construct(string $message)
14
    {
15
        parent::__construct($message);
16
    }
17
18
    public static function noTaskRunner(Task $task): self
19
    {
20
        if ($task instanceof HasMissingDependencyMessage) {
21
            return new self($task::getMissingDependencyMessage());
22
        }
23
24
        return new self(\sprintf('No task runner registered for "%s".', $task));
25
    }
26
27
    public static function noExtensionHandler(object $extension): self
28
    {
29
        if ($extension instanceof HasMissingDependencyMessage) {
30
            return new self($extension::getMissingDependencyMessage());
31
        }
32
33
        if (\method_exists($extension, '__toString')) {
34
            return new self(\sprintf('No extension handler registered for "%s: %s".', \get_class($extension), $extension));
0 ignored issues
show
Bug introduced by
$extension of type object is incompatible with the type string expected by parameter $args of sprintf(). ( Ignorable by Annotation )

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

34
            return new self(\sprintf('No extension handler registered for "%s: %s".', \get_class($extension), /** @scrutinizer ignore-type */ $extension));
Loading history...
35
        }
36
37
        return new self(\sprintf('No extension handler registered for "%s".', \get_class($extension)));
38
    }
39
}
40