| Conditions | 24 | 
| Paths | 3121 | 
| Total Lines | 157 | 
| Code Lines | 99 | 
| Lines | 27 | 
| Ratio | 17.2 % | 
| 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  | 
            ||
| 82 | public function call($name, $arguments, $expected_class = null)  | 
            ||
| 83 |   { | 
            ||
| 84 |     if (! isset($this->methods[$name])) { | 
            ||
| 85 | $this->client->getLogger()->error(  | 
            ||
| 86 | 'Service method unknown',  | 
            ||
| 87 | array(  | 
            ||
| 88 | 'service' => $this->serviceName,  | 
            ||
| 89 | 'resource' => $this->resourceName,  | 
            ||
| 90 | 'method' => $name  | 
            ||
| 91 | )  | 
            ||
| 92 | );  | 
            ||
| 93 | |||
| 94 | throw new Google_Exception(  | 
            ||
| 95 | "Unknown function: " .  | 
            ||
| 96 |           "{$this->serviceName}->{$this->resourceName}->{$name}()" | 
            ||
| 97 | );  | 
            ||
| 98 | }  | 
            ||
| 99 | $method = $this->methods[$name];  | 
            ||
| 100 | $parameters = $arguments[0];  | 
            ||
| 101 | |||
| 102 | // postBody is a special case since it's not defined in the discovery  | 
            ||
| 103 | // document as parameter, but we abuse the param entry for storing it.  | 
            ||
| 104 | $postBody = null;  | 
            ||
| 105 |     if (isset($parameters['postBody'])) { | 
            ||
| 106 |       if ($parameters['postBody'] instanceof Google_Model) { | 
            ||
| 107 | // In the cases the post body is an existing object, we want  | 
            ||
| 108 | // to use the smart method to create a simple object for  | 
            ||
| 109 | // for JSONification.  | 
            ||
| 110 | $parameters['postBody'] = $parameters['postBody']->toSimpleObject();  | 
            ||
| 111 |       } else if (is_object($parameters['postBody'])) { | 
            ||
| 112 | // If the post body is another kind of object, we will try and  | 
            ||
| 113 | // wrangle it into a sensible format.  | 
            ||
| 114 | $parameters['postBody'] =  | 
            ||
| 115 | $this->convertToArrayAndStripNulls($parameters['postBody']);  | 
            ||
| 116 | }  | 
            ||
| 117 | $postBody = json_encode($parameters['postBody']);  | 
            ||
| 118 | unset($parameters['postBody']);  | 
            ||
| 119 | }  | 
            ||
| 120 | |||
| 121 | // TODO: optParams here probably should have been  | 
            ||
| 122 | // handled already - this may well be redundant code.  | 
            ||
| 123 |     if (isset($parameters['optParams'])) { | 
            ||
| 124 | $optParams = $parameters['optParams'];  | 
            ||
| 125 | unset($parameters['optParams']);  | 
            ||
| 126 | $parameters = array_merge($parameters, $optParams);  | 
            ||
| 127 | }  | 
            ||
| 128 | |||
| 129 |     if (!isset($method['parameters'])) { | 
            ||
| 130 | $method['parameters'] = array();  | 
            ||
| 131 | }  | 
            ||
| 132 | |||
| 133 | $method['parameters'] = array_merge(  | 
            ||
| 134 | $method['parameters'],  | 
            ||
| 135 | $this->stackParameters  | 
            ||
| 136 | );  | 
            ||
| 137 |     foreach ($parameters as $key => $val) { | 
            ||
| 138 | View Code Duplication |       if ($key != 'postBody' && ! isset($method['parameters'][$key])) { | 
            |
| 139 | $this->client->getLogger()->error(  | 
            ||
| 140 | 'Service parameter unknown',  | 
            ||
| 141 | array(  | 
            ||
| 142 | 'service' => $this->serviceName,  | 
            ||
| 143 | 'resource' => $this->resourceName,  | 
            ||
| 144 | 'method' => $name,  | 
            ||
| 145 | 'parameter' => $key  | 
            ||
| 146 | )  | 
            ||
| 147 | );  | 
            ||
| 148 |         throw new Google_Exception("($name) unknown parameter: '$key'"); | 
            ||
| 149 | }  | 
            ||
| 150 | }  | 
            ||
| 151 | |||
| 152 |     foreach ($method['parameters'] as $paramName => $paramSpec) { | 
            ||
| 153 | View Code Duplication | if (isset($paramSpec['required']) &&  | 
            |
| 154 | $paramSpec['required'] &&  | 
            ||
| 155 | ! isset($parameters[$paramName])  | 
            ||
| 156 |       ) { | 
            ||
| 157 | $this->client->getLogger()->error(  | 
            ||
| 158 | 'Service parameter missing',  | 
            ||
| 159 | array(  | 
            ||
| 160 | 'service' => $this->serviceName,  | 
            ||
| 161 | 'resource' => $this->resourceName,  | 
            ||
| 162 | 'method' => $name,  | 
            ||
| 163 | 'parameter' => $paramName  | 
            ||
| 164 | )  | 
            ||
| 165 | );  | 
            ||
| 166 |         throw new Google_Exception("($name) missing required param: '$paramName'"); | 
            ||
| 167 | }  | 
            ||
| 168 |       if (isset($parameters[$paramName])) { | 
            ||
| 169 | $value = $parameters[$paramName];  | 
            ||
| 170 | $parameters[$paramName] = $paramSpec;  | 
            ||
| 171 | $parameters[$paramName]['value'] = $value;  | 
            ||
| 172 | unset($parameters[$paramName]['required']);  | 
            ||
| 173 |       } else { | 
            ||
| 174 | // Ensure we don't pass nulls.  | 
            ||
| 175 | unset($parameters[$paramName]);  | 
            ||
| 176 | }  | 
            ||
| 177 | }  | 
            ||
| 178 | |||
| 179 | $this->client->getLogger()->info(  | 
            ||
| 180 | 'Service Call',  | 
            ||
| 181 | array(  | 
            ||
| 182 | 'service' => $this->serviceName,  | 
            ||
| 183 | 'resource' => $this->resourceName,  | 
            ||
| 184 | 'method' => $name,  | 
            ||
| 185 | 'arguments' => $parameters,  | 
            ||
| 186 | )  | 
            ||
| 187 | );  | 
            ||
| 188 | |||
| 189 | $url = Google_Http_REST::createRequestUri(  | 
            ||
| 190 | $this->servicePath,  | 
            ||
| 191 | $method['path'],  | 
            ||
| 192 | $parameters  | 
            ||
| 193 | );  | 
            ||
| 194 | $httpRequest = new Google_Http_Request(  | 
            ||
| 195 | $url,  | 
            ||
| 196 | $method['httpMethod'],  | 
            ||
| 197 | null,  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 198 | $postBody  | 
            ||
| 199 | );  | 
            ||
| 200 | |||
| 201 |     if ($this->rootUrl) { | 
            ||
| 202 | $httpRequest->setBaseComponent($this->rootUrl);  | 
            ||
| 203 |     } else { | 
            ||
| 204 | $httpRequest->setBaseComponent($this->client->getBasePath());  | 
            ||
| 205 | }  | 
            ||
| 206 | |||
| 207 |     if ($postBody) { | 
            ||
| 208 | $contentTypeHeader = array();  | 
            ||
| 209 | $contentTypeHeader['content-type'] = 'application/json; charset=UTF-8';  | 
            ||
| 210 | $httpRequest->setRequestHeaders($contentTypeHeader);  | 
            ||
| 211 | $httpRequest->setPostBody($postBody);  | 
            ||
| 212 | }  | 
            ||
| 213 | |||
| 214 | $httpRequest = $this->client->getAuth()->sign($httpRequest);  | 
            ||
| 215 | $httpRequest->setExpectedClass($expected_class);  | 
            ||
| 216 | |||
| 217 | if (isset($parameters['data']) &&  | 
            ||
| 218 |         ($parameters['uploadType']['value'] == 'media' || $parameters['uploadType']['value'] == 'multipart')) { | 
            ||
| 219 | // If we are doing a simple media upload, trigger that as a convenience.  | 
            ||
| 220 | $mfu = new Google_Http_MediaFileUpload(  | 
            ||
| 221 | $this->client,  | 
            ||
| 222 | $httpRequest,  | 
            ||
| 223 | isset($parameters['mimeType']) ? $parameters['mimeType']['value'] : 'application/octet-stream',  | 
            ||
| 224 | $parameters['data']['value']  | 
            ||
| 225 | );  | 
            ||
| 226 | }  | 
            ||
| 227 | |||
| 228 |     if (isset($parameters['alt']) && $parameters['alt']['value'] == 'media') { | 
            ||
| 229 | $httpRequest->enableExpectedRaw();  | 
            ||
| 230 | }  | 
            ||
| 231 | |||
| 232 |     if ($this->client->shouldDefer()) { | 
            ||
| 233 | // If we are in batch or upload mode, return the raw request.  | 
            ||
| 234 | return $httpRequest;  | 
            ||
| 235 | }  | 
            ||
| 236 | |||
| 237 | return $this->client->execute($httpRequest);  | 
            ||
| 238 | }  | 
            ||
| 239 | |||
| 253 | 
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: