Conditions | 10 |
Paths | 6 |
Total Lines | 34 |
Lines | 0 |
Ratio | 0 % |
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:
1 | <?php |
||
60 | public function setUrl($method, $arguments = NULL) { |
||
61 | |||
62 | if (!is_string($method)) { |
||
63 | throw new InvalidArgumentException('The method variable must be a string.'); |
||
64 | } |
||
65 | if (($arguments != NULL) && !is_array($arguments)) { |
||
66 | throw new InvalidArgumentException('The arguments variable must be an array.'); |
||
67 | } |
||
68 | |||
69 | // Set a new array |
||
70 | $arguments_list = array(); |
||
71 | |||
72 | // Check if a token is set through the arguments |
||
73 | $token_is_set = FALSE; |
||
74 | |||
75 | if ($arguments != NULL) { |
||
76 | foreach ($arguments as $key => $value) { |
||
77 | $arguments_list[] = $key . "=" . $value; |
||
78 | |||
79 | if(strcmp($key, "token") == 0) { |
||
80 | $token_is_set = TRUE; |
||
81 | } |
||
82 | } |
||
83 | } |
||
84 | |||
85 | // If the token has not been set, add it to the list |
||
86 | if(!$token_is_set && isset($this->token) && is_string($this->token)) { |
||
87 | $arguments_list[] = "token=".$this->token; |
||
88 | } |
||
89 | |||
90 | $this->url = self::SLACK_API_URL . $method . "?" . implode("&", $arguments_list); |
||
91 | |||
92 | return $this; |
||
93 | } |
||
94 | |||
103 |