Conditions | 10 |
Paths | 512 |
Total Lines | 41 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Tests | 19 |
CRAP Score | 14.9309 |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
1 | <?php |
||
58 | 3 | public function sendSimpleRequest($method, $uri |
|
59 | , array $getParams=[], array $postParams=[] |
||
60 | , $user="", $password="" |
||
61 | , array $jsonParams=[] |
||
62 | , $requesTimeout=0, $SSLVerify=true |
||
63 | , array $customHeaders=[], $accept="", $protocolVersion="" |
||
64 | ) |
||
65 | { |
||
66 | |||
67 | 3 | if(!empty($getParams)) { |
|
68 | $this->requestHelper->setQuery($getParams); |
||
69 | } |
||
70 | 3 | if(!empty($postParams)) { |
|
71 | $this->requestHelper->setFormParams($postParams); |
||
72 | } |
||
73 | 3 | if(!empty($user)) { |
|
74 | 3 | $this->requestHelper->setAuth($user,$password); |
|
75 | 3 | } |
|
76 | 3 | if(!empty($requesTimeout)) { |
|
77 | $this->requestHelper->setTimeout($requesTimeout); |
||
78 | } |
||
79 | 3 | if(!empty($SSLVerify)) { |
|
80 | 3 | $this->requestHelper->setVerify($SSLVerify); |
|
81 | 3 | } |
|
82 | 3 | if(!empty($accept)) { |
|
83 | $this->requestHelper['accept'] = $accept; |
||
84 | } |
||
85 | 3 | if(!empty($customHeaders)) { |
|
86 | $this->requestHelper->setHeaders($customHeaders); |
||
87 | } |
||
88 | 3 | if(!empty($protocolVersion)) { |
|
89 | $this->requestHelper->setVerify($protocolVersion); |
||
90 | 3 | } |
|
91 | 3 | if(!empty($jsonParams)) { |
|
92 | 3 | $this->requestHelper->setJson($jsonParams); |
|
93 | 3 | } |
|
94 | |||
95 | 3 | $this->response = $this->httpclient->sendRequest($method, $uri); |
|
96 | |||
97 | 3 | return $this->response; |
|
98 | } |
||
99 | |||
168 |
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.