RequestTrait::getModule()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
namespace Fwlib\Web;
3
4
use Fwlib\Base\SingletonTrait;
5
use Fwlib\Util\UtilContainer;
6
7
/**
8
 * Request content holder
9
 *
10
 * Content are cached as property. They can also be modified via setter, to
11
 * implement default module/action etc.
12
 *
13
 * @see         \Fwlib\Web\RequestInterface
14
 *
15
 * @property    string $actionParameter
16
 * @property    string $moduleParameter
17
 *
18
 * @copyright   Copyright 2015 Fwolf
19
 * @license     http://www.gnu.org/licenses/lgpl.html LGPL-3.0+
20
 */
21
trait RequestTrait
22
{
23
    use SingletonTrait;
24
25
26
    /**
27
     * @var string
28
     */
29
    protected $action = null;
30
31
    /**
32
     * @var string
33
     */
34
    protected $module = null;
35
36
37
    /**
38
     * @see RequestInterface::getAction()
39
     *
40
     * @return  string
41
     */
42
    public function getAction()
43
    {
44
        if (is_null($this->action)) {
45
            $this->action = UtilContainer::getInstance()->getHttp()
0 ignored issues
show
Documentation Bug introduced by
It seems like \Fwlib\Util\UtilContaine...$this->actionParameter) can also be of type integer. However, the property $action is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
46
                ->getGet($this->actionParameter);
47
        }
48
49
        return $this->action;
50
    }
51
52
53
    /**
54
     * @see RequestInterface::getActionParameter()
55
     *
56
     * @return  string
57
     */
58
    public function getActionParameter()
59
    {
60
        return $this->actionParameter;
61
    }
62
63
64
    /**
65
     * @see RequestInterface::getModule()
66
     *
67
     * @return  string
68
     */
69
    public function getModule()
70
    {
71
        if (is_null($this->module)) {
72
            $this->module = UtilContainer::getInstance()->getHttp()
0 ignored issues
show
Documentation Bug introduced by
It seems like \Fwlib\Util\UtilContaine...$this->moduleParameter) can also be of type integer. However, the property $module is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
73
                ->getGet($this->moduleParameter);
74
        }
75
76
        return $this->module;
77
    }
78
79
80
    /**
81
     * @see RequestInterface::getModuleParameter()
82
     *
83
     * @return  string
84
     */
85
    public function getModuleParameter()
86
    {
87
        return $this->moduleParameter;
88
    }
89
90
91
    /**
92
     * @see RequestInterface::setAction()
93
     *
94
     * @param   string $action
95
     * @return  $this
96
     */
97
    public function setAction($action)
98
    {
99
        $this->action = $action;
100
101
        return $this;
102
    }
103
104
105
    /**
106
     * @see RequestInterface::setActionParameter()
107
     *
108
     * @param   string $param
109
     * @return  $this
110
     */
111
    public function setActionParameter($param)
112
    {
113
        $this->actionParameter = $param;
114
115
        return $this;
116
    }
117
118
119
    /**
120
     * @see RequestInterface::setModule()
121
     *
122
     * @param   string $module
123
     * @return  $this
124
     */
125
    public function setModule($module)
126
    {
127
        $this->module = $module;
128
129
        return $this;
130
    }
131
132
133
    /**
134
     * @see RequestInterface::setModuleParameter()
135
     *
136
     * @param   string $param
137
     * @return  $this
138
     */
139
    public function setModuleParameter($param)
140
    {
141
        $this->moduleParameter = $param;
142
143
        return $this;
144
    }
145
}
146