| Conditions | 12 |
| Paths | 2880 |
| Total Lines | 89 |
| Code Lines | 59 |
| 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 |
||
| 58 | public static function sendCall(string $method, string $uri, array $options = []): mixed |
||
| 59 | { |
||
| 60 | $config = []; |
||
| 61 | if ($uri !== '' && $uri !== '0') { |
||
| 62 | $config['base_url'] = $uri; |
||
| 63 | } |
||
| 64 | |||
| 65 | if (isset($options['query'])) { |
||
| 66 | $config['query'] = $options['query']; |
||
| 67 | } |
||
| 68 | |||
| 69 | // create the params for the base64_enclose |
||
| 70 | $params = ''; |
||
| 71 | if (isset($config['base_url'])) { |
||
| 72 | $params = parse_url($config['base_url'], PHP_URL_QUERY) ?? ''; |
||
| 73 | } |
||
| 74 | |||
| 75 | if (isset($config['query'])) { |
||
| 76 | if ($params) { |
||
| 77 | $params .= '&'; |
||
| 78 | } |
||
| 79 | |||
| 80 | $params .= urldecode(http_build_query($config['query'])); |
||
| 81 | } |
||
| 82 | |||
| 83 | // add the headers |
||
| 84 | $config['headers'] = [ |
||
| 85 | 'Content-Type' => 'application/json', |
||
| 86 | 'Accept' => 'application/json', |
||
| 87 | 'api-auth-id' => static::config()->get('id'), |
||
| 88 | 'api-auth-signature' => base64_encode(hash_hmac('sha256', $params, (string) static::config()->get('key'), true)) |
||
| 89 | ]; |
||
| 90 | |||
| 91 | if (static::config()->get('client_type')) { |
||
| 92 | $config['headers']['client-type'] = static::config()->get('client_type'); |
||
| 93 | } |
||
| 94 | |||
| 95 | // finish params for the base64_enclose |
||
| 96 | |||
| 97 | $client = new Client($config); |
||
| 98 | |||
| 99 | if (static::config()->get('debug')) { |
||
| 100 | $options['debug'] = true; |
||
| 101 | } |
||
| 102 | |||
| 103 | try { |
||
| 104 | $response = $client->request($method, $uri, $options); |
||
| 105 | if (static::config()->get('logsuccessfulcalls')) { |
||
| 106 | $line_formatter = new LineFormatter( |
||
| 107 | null, // Format of message in log, default [%datetime%] %channel%.%level_name%: %message% %context% %extra%\n |
||
| 108 | null, // Datetime format |
||
| 109 | true, // allowInlineLineBreaks option, default false |
||
| 110 | true // discard empty Square brackets in the end, default false |
||
| 111 | ); |
||
| 112 | $logger = new Logger(_t('UnleashedAPI.UnleashedSuccessful', 'unleashed-successful')); |
||
| 113 | $stream_handler = new StreamHandler(_t('UnleashedAPI.UnleashedSuccessfulFilename', './z_unleashed-successful.log'), Level::Info); |
||
| 114 | $stream_handler->setFormatter($line_formatter); |
||
| 115 | $logger->pushHandler($stream_handler); |
||
| 116 | $logger->info(_t('UnleashedAPI.RequestSuccessTitle', 'Request successful') . '\n'); |
||
| 117 | $logger->info(_t('UnleashedAPI.Method', 'Request method: ') . $method); |
||
| 118 | $logger->info(_t('UnleashedAPI.Uri', 'Request uri: ') . $uri); |
||
| 119 | $logger->info(_t('UnleashedAPI.Options', 'Request options: ')); |
||
| 120 | $logger->info(print_r($options, true)); |
||
| 121 | $logger->info(_t('UnleashedAPI.ResponseContent', 'Response Content: ')); |
||
| 122 | $logger->info(print_r($response->getBody()->getContents(), true)); |
||
| 123 | } |
||
| 124 | |||
| 125 | return $response; |
||
| 126 | |||
| 127 | } catch (ClientException $clientException) { |
||
| 128 | if (static::config()->get('logfailedcalls')) { |
||
| 129 | $line_formatter = new LineFormatter( |
||
| 130 | null, // Format of message in log, default [%datetime%] %channel%.%level_name%: %message% %context% %extra%\n |
||
| 131 | null, // Datetime format |
||
| 132 | true, // allowInlineLineBreaks option, default false |
||
| 133 | true // discard empty Square brackets in the end, default false |
||
| 134 | ); |
||
| 135 | $logger = new Logger(_t('UnleashedAPI.UnleashedClientException', 'unleashed-client-exception')); |
||
| 136 | $stream_handler = new StreamHandler(_t('UnleashedAPI.UnleashedClientExceptionFilename', './z_unleashed-client-exception.log'), Level::Info); |
||
| 137 | $stream_handler->setFormatter($line_formatter); |
||
| 138 | $logger->pushHandler($stream_handler); |
||
| 139 | $logger->info(_t('UnleashedAPI.ClientExceptionTitle', 'Request failed'). '\n'); |
||
| 140 | $logger->info($clientException->getMessage()); |
||
| 141 | $logger->info(print_r($clientException->getResponse()->getBody()->getContents(), true)); |
||
| 142 | $logger->info($clientException->getRequest()->getMethod()); |
||
| 143 | $logger->info(print_r($clientException->getRequest()->getHeaders(), true)); |
||
| 144 | } |
||
| 145 | |||
| 146 | return $clientException; |
||
| 147 | } |
||
| 150 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths