Conditions | 5 |
Paths | 5 |
Total Lines | 80 |
Code Lines | 45 |
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 |
||
48 | public function getNewAccessToken() |
||
49 | { |
||
50 | $url = $this->getOAuth2TokenEndPoint(); |
||
51 | |||
52 | $data = array( |
||
53 | 'grant_type' => 'client_credentials', |
||
54 | 'client_id' => $this->clientId, |
||
55 | 'client_secret' => $this->clientSecret, |
||
56 | 'scope' => 'epc.api', |
||
57 | ); |
||
58 | |||
59 | $postData = http_build_query($data); |
||
60 | |||
61 | $httpHeader = 'Content-Type: application/x-www-form-urlencoded' . static::CRLF; |
||
62 | $httpHeader .= 'Accept: application/json; charset=utf-8' . static::CRLF; |
||
63 | $httpHeader .= 'Content-Length: ' . mb_strlen($postData, '8bit') . static::CRLF; |
||
64 | |||
65 | $options = array( |
||
66 | 'http' => array( |
||
67 | 'ignore_errors' => true, |
||
68 | 'method' => 'POST', |
||
69 | 'header' => $httpHeader, |
||
70 | 'content' => $postData, |
||
71 | ), |
||
72 | ); |
||
73 | |||
74 | $context = stream_context_create($options); |
||
75 | |||
76 | $httpResponse = $this->getHttpResponseFromUrl($url, $context); |
||
77 | $http_response_header = $httpResponse['header']; |
||
78 | $contents = $httpResponse['contents']; |
||
79 | |||
80 | $headers = $this->mapHttpHeaders($http_response_header); |
||
81 | |||
82 | if ($this->handleResponse($headers)) { |
||
83 | $jsonResponse = $this->decodeJsonFromResponse($headers, $contents, true); |
||
84 | |||
85 | if (!isset($jsonResponse['access_token'])) { |
||
86 | $statusCode = $this->getStatusCodeFromResponse($headers); |
||
87 | |||
88 | throw new EasyPdfCloudApiException( |
||
|
|||
89 | $statusCode, |
||
90 | 'Response from server does not contain access token' |
||
91 | ); |
||
92 | } |
||
93 | |||
94 | $accessToken = $jsonResponse['access_token']; |
||
95 | |||
96 | if (!isset($jsonResponse['expires_in'])) { |
||
97 | $statusCode = $this->getStatusCodeFromResponse($headers); |
||
98 | |||
99 | throw new EasyPdfCloudApiException( |
||
100 | $statusCode, |
||
101 | 'Response from server does not contain access token expiration' |
||
102 | ); |
||
103 | } |
||
104 | |||
105 | $expiresIn = $jsonResponse['expires_in']; |
||
106 | |||
107 | if ($expiresIn > 120) { |
||
108 | // we'll try to refresh a bit earlier |
||
109 | $expiresIn -= 60; |
||
110 | } |
||
111 | |||
112 | $expirationTime = time() + $expiresIn; |
||
113 | |||
114 | $tokenInfo = array( |
||
115 | 'access_token' => $accessToken, |
||
116 | 'expiration_time' => $expirationTime, |
||
117 | ); |
||
118 | |||
119 | $this->tokenManager->saveTokenInfo($tokenInfo); |
||
120 | |||
121 | return $accessToken; |
||
122 | } |
||
123 | |||
124 | // This should raise an exception |
||
125 | $this->checkWwwAuthenticateResponseHeader($headers); |
||
126 | |||
127 | return null; |
||
128 | } |
||
162 |
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