CommandMessage::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 4 Features 0
Metric Value
c 5
b 4
f 0
dl 0
loc 9
rs 9.6666
cc 3
eloc 4
nc 2
nop 2
1
<?php
2
3
namespace PEIP\Message;
4
5
/*
6
 * This file is part of the PEIP package.
7
 * (c) 2009-2016 Timo Michna <timomichna/yahoo.de>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
use PEIP\Data\ArrayAccess;
14
15
/**
16
 * CommandMessage.
17
 *
18
 * @author Timo Michna <timomichna/yahoo.de>
19
 * @extends \PEIP\Message\GenericMessage
20
 * @implements \PEIP\INF\Base\Buildable, \PEIP\INF\Message\Message, \PEIP\INF\Base\Container, \PEIP\INF\Command\Command
21
 */
22
class CommandMessage extends \PEIP\Message\GenericMessage implements \PEIP\INF\Command\Command
23
{
24
    /**
25
     * @param $content
26
     * @param $headers
27
     *
28
     * @return
29
     */
30
    public function __construct($content, ArrayAccess $headers = null)
31
    {
32
        if (!($content instanceof \PEIP\INF\Command\Command) && !is_callable($content)) {
33
            throw new \BadArgumentException('Argument 1 for CommandMessage::__construct must be callable or implment \PEIP\INF\Command\Command');
34
        }
35
36
37
        parent::__construct($content, $headers);
0 ignored issues
show
Documentation introduced by
$headers is of type null|object<PEIP\Data\ArrayAccess>, but the function expects a array|object<PEIP\Message\ArrayAccess>.

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...
38
    }
39
40
    /**
41
     * @return
42
     */
43
    public function execute()
44
    {
45
        if (is_callable($this->getContent())) {
46
            return call_user_func($this->getContent());
47
        } else {
48
            return $this->getContent()->execute();
49
        }
50
    }
51
}
52