| Conditions | 20 | 
| Paths | 613 | 
| Total Lines | 109 | 
| Code Lines | 66 | 
| 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 | ||
| 85 | public function call($name, $arguments, $expected_class = null) | ||
| 86 |     { | ||
| 87 |         if (!isset($this->methods[$name])) { | ||
| 88 | throw new Google_Exception( | ||
| 89 | 'Unknown function: '. | ||
| 90 |                 "{$this->serviceName}->{$this->resourceName}->{$name}()" | ||
| 91 | ); | ||
| 92 | } | ||
| 93 | $method = $this->methods[$name]; | ||
| 94 | $parameters = $arguments[0]; | ||
| 95 | |||
| 96 | // postBody is a special case since it's not defined in the discovery | ||
| 97 | // document as parameter, but we abuse the param entry for storing it. | ||
| 98 | $postBody = null; | ||
| 99 |         if (isset($parameters['postBody'])) { | ||
| 100 |             if (is_object($parameters['postBody'])) { | ||
| 101 | $parameters['postBody'] = | ||
| 102 | $this->convertToArrayAndStripNulls($parameters['postBody']); | ||
| 103 | } | ||
| 104 | |||
| 105 | $postBody = json_encode($parameters['postBody']); | ||
| 106 | unset($parameters['postBody']); | ||
| 107 | } | ||
| 108 | |||
| 109 | // TODO(ianbarber): optParams here probably should have been | ||
| 110 | // handled already - this may well be redundant code. | ||
| 111 |         if (isset($parameters['optParams'])) { | ||
| 112 | $optParams = $parameters['optParams']; | ||
| 113 | unset($parameters['optParams']); | ||
| 114 | $parameters = array_merge($parameters, $optParams); | ||
| 115 | } | ||
| 116 | |||
| 117 |         if (!isset($method['parameters'])) { | ||
| 118 | $method['parameters'] = []; | ||
| 119 | } | ||
| 120 | |||
| 121 | $method['parameters'] = array_merge( | ||
| 122 | $method['parameters'], | ||
| 123 | $this->stackParameters | ||
| 124 | ); | ||
| 125 |         foreach ($parameters as $key => $val) { | ||
| 126 |             if ($key != 'postBody' && !isset($method['parameters'][$key])) { | ||
| 127 |                 throw new Google_Exception("($name) unknown parameter: '$key'"); | ||
| 128 | } | ||
| 129 | } | ||
| 130 | |||
| 131 |         foreach ($method['parameters'] as $paramName => $paramSpec) { | ||
| 132 | if (isset($paramSpec['required']) && | ||
| 133 | $paramSpec['required'] && | ||
| 134 | !isset($parameters[$paramName]) | ||
| 135 |             ) { | ||
| 136 |                 throw new Google_Exception("($name) missing required param: '$paramName'"); | ||
| 137 | } | ||
| 138 |             if (isset($parameters[$paramName])) { | ||
| 139 | $value = $parameters[$paramName]; | ||
| 140 | $parameters[$paramName] = $paramSpec; | ||
| 141 | $parameters[$paramName]['value'] = $value; | ||
| 142 | unset($parameters[$paramName]['required']); | ||
| 143 |             } else { | ||
| 144 | // Ensure we don't pass nulls. | ||
| 145 | unset($parameters[$paramName]); | ||
| 146 | } | ||
| 147 | } | ||
| 148 | |||
| 149 | $servicePath = $this->service->servicePath; | ||
| 150 | |||
| 151 | $url = Google_Http_REST::createRequestUri( | ||
| 152 | $servicePath, | ||
| 153 | $method['path'], | ||
| 154 | $parameters | ||
| 155 | ); | ||
| 156 | |||
| 157 | $httpRequest = new Google_Http_Request( | ||
| 158 | $this->client, | ||
| 159 | $url, | ||
| 160 | $method['httpMethod'], | ||
| 161 | null, | ||
|  | |||
| 162 | $postBody | ||
| 163 | ); | ||
| 164 | |||
| 165 |         if ($postBody) { | ||
| 166 | $contentTypeHeader = []; | ||
| 167 | $contentTypeHeader['content-type'] = 'application/json; charset=UTF-8'; | ||
| 168 | $httpRequest->setRequestHeaders($contentTypeHeader); | ||
| 169 | $httpRequest->setPostBody($postBody); | ||
| 170 | } | ||
| 171 | |||
| 172 | $httpRequest = $this->client->getAuth()->sign($httpRequest); | ||
| 173 | $httpRequest->setExpectedClass($expected_class); | ||
| 174 | |||
| 175 | if (isset($parameters['data']) && | ||
| 176 | ($parameters['uploadType']['value'] == 'media' || $parameters['uploadType']['value'] == 'multipart') | ||
| 177 |         ) { | ||
| 178 | // If we are doing a simple media upload, trigger that as a convenience. | ||
| 179 | $mfu = new Google_Http_MediaFileUpload( | ||
| 180 | $this->client, | ||
| 181 | $httpRequest, | ||
| 182 | isset($parameters['mimeType']) ? $parameters['mimeType']['value'] : 'application/octet-stream', | ||
| 183 | $parameters['data']['value'] | ||
| 184 | ); | ||
| 185 | } | ||
| 186 | |||
| 187 |         if ($this->client->shouldDefer()) { | ||
| 188 | // If we are in batch or upload mode, return the raw request. | ||
| 189 | return $httpRequest; | ||
| 190 | } | ||
| 191 | |||
| 192 | return $httpRequest->execute(); | ||
| 193 | } | ||
| 194 | |||
| 209 | 
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: