| Conditions | 10 |
| Paths | 97 |
| Total Lines | 44 |
| 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 |
||
| 98 | final public function call($type, array $parameters, $responseClass) |
||
| 99 | { |
||
| 100 | if (!in_array(ResponseInterface::class, class_implements($responseClass))) { |
||
| 101 | throw new \InvalidArgumentException('The response class must implement '.ResponseInterface::class.'.'); |
||
| 102 | } |
||
| 103 | |||
| 104 | $bodyParams = array_merge($parameters, $this->baseParameters); |
||
| 105 | $bodyParams['TYPE'] = $type; |
||
| 106 | $bodyParams['NUMQUESTION'] = $this->questionNumber; |
||
| 107 | $bodyParams['DATEQ'] = null !== $parameters['DATEQ'] ? $parameters['DATEQ'] : date('dmYHis'); |
||
| 108 | // Restore default_currency from parameters if given |
||
| 109 | if (array_key_exists('DEVISE', $parameters)) { |
||
| 110 | $bodyParams['DEVISE'] = null !== $parameters['DEVISE'] ? $parameters['DEVISE'] : $this->defaultCurrency; |
||
| 111 | } |
||
| 112 | if (!array_key_exists('ACTIVITE', $parameters) && $this->defaultActivity) { |
||
| 113 | $bodyParams['ACTIVITE'] = $this->defaultActivity; |
||
| 114 | } |
||
| 115 | |||
| 116 | // `ACTIVITE` must be a string of 3 numbers to get it working with Paybox API. |
||
| 117 | if (array_key_exists('ACTIVITE', $bodyParams)) { |
||
| 118 | $bodyParams['ACTIVITE'] = str_pad($bodyParams['ACTIVITE'], 3, '0', STR_PAD_LEFT); |
||
| 119 | } |
||
| 120 | |||
| 121 | $response = $this->request($bodyParams); |
||
| 122 | |||
| 123 | // Generate results array |
||
| 124 | $results = []; |
||
| 125 | foreach (explode('&', $response) as $element) { |
||
| 126 | list($key, $value) = explode('=', $element); |
||
| 127 | $value = utf8_encode(trim($value)); |
||
| 128 | $results[$key] = $value; |
||
| 129 | } |
||
| 130 | |||
| 131 | $this->questionNumber = (int) $results['NUMQUESTION'] + 1; |
||
| 132 | |||
| 133 | /** @var ResponseInterface $response */ |
||
| 134 | $response = new $responseClass($results); |
||
| 135 | |||
| 136 | if (!$response->isSuccessful()) { |
||
| 137 | throw new PayboxException($response); |
||
| 138 | } |
||
| 139 | |||
| 140 | return $response; |
||
| 141 | } |
||
| 142 | |||
| 157 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..