Test Setup Failed
Push — master ( 251f8c...20fe9d )
by Gabriel
05:53
created

CommandFactory::createFromForwardExecption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Nip\Dispatcher\Commands;
4
5
use Nip\Dispatcher\Exceptions\ForwardException;
6
use Psr\Http\Message\ServerRequestInterface;
7
8
/**
9
 * Class CommandFactory
10
 * @package Nip\Dispatcher\Commands
11
 */
12
class CommandFactory
13
{
14
    /**
15
     * @param $action
16
     * @return Command
17
     */
18
    public static function createFromAction($action): Command
19
    {
20
        $command = new Command();
21
        $command->setAction($action);
22
        return $command;
23
    }
24
25
    /**
26
     * @param ServerRequestInterface|null $request
27
     * @return Command
28
     */
29
    public static function createFromRequest(ServerRequestInterface $request = null): Command
30
    {
31
        $command = new Command();
32
        $command->setRequest($request);
0 ignored issues
show
Bug introduced by
It seems like $request defined by parameter $request on line 29 can be null; however, Nip\Http\Request\RequestAwareTrait::setRequest() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
33
        return $command;
34
    }
35
36
    /**
37
     * @param ForwardException $exception
38
     * @return Command
39
     */
40
    public static function createFromForwardExecption(ForwardException $exception)
0 ignored issues
show
Unused Code introduced by
The parameter $exception is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
41
    {
42
        $command = new Command();
43
        return $command;
44
    }
45
}
46