| Conditions | 3 |
| Paths | 7 |
| Total Lines | 23 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 3 |
| Changes | 0 | ||
| 1 | <?php |
||
| 35 | 7 | public function signRequest(RequestInterface $request, $forceNew = false) |
|
| 36 | { |
||
| 37 | try { |
||
| 38 | // force-get a new token if it was requested, if not, the regular |
||
| 39 | // caching mechanism will be used so the call is not necessary here. |
||
| 40 | 7 | if (true === $forceNew) { |
|
| 41 | 5 | $this->pool->getToken($forceNew); |
|
| 42 | 3 | } |
|
| 43 | |||
| 44 | // create a new request with the new uri and the token added to the headers |
||
| 45 | 6 | $uri = Uri::resolve( |
|
| 46 | 6 | new Uri($this->pool->getEndpointUrl()), |
|
| 47 | 6 | $request->getUri() |
|
| 48 | 6 | ); |
|
| 49 | |||
| 50 | return $request |
||
| 51 | 6 | ->withUri($uri) |
|
| 52 | 6 | ->withHeader('X-Auth-Token', $this->pool->getTokenId()) |
|
| 53 | 6 | ; |
|
| 54 | 2 | } catch (TokenException $e) { |
|
| 55 | 2 | throw new ClientException('Could not obtain token', $request, null, $e); |
|
| 56 | } |
||
| 57 | } |
||
| 58 | } |
||
| 59 |