Completed
Pull Request — master (#9)
by Adam
04:10 queued 01:38
created

SimpleCommandFactory::make()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
ccs 0
cts 11
cp 0
rs 9.4285
cc 3
eloc 7
nc 3
nop 1
crap 12
1
<?php
2
3
namespace Equip\Queue\Command;
4
5
use Equip\Command\CommandInterface;
6
use Equip\Queue\Exception\CommandException;
7
use Equip\Queue\Exception\HandlerException;
8
9
class SimpleCommandFactory implements CommandFactoryInterface
10
{
11
    public function make($command)
12
    {
13
        if (!class_exists($command)) {
14
            throw CommandException::notFound($command);
15
        }
16
17
        $command = new $command;
18
19
        if (!($command instanceof CommandInterface)) {
20
            throw CommandException::invalidCommand($command);
0 ignored issues
show
Documentation introduced by
$command is of type object, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
21
        }
22
23
        return $command;
24
    }
25
}
26