| Conditions | 4 |
| Paths | 1 |
| Total Lines | 30 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 21 |
| CRAP Score | 4 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | 46 | public function boot(): void |
|
| 13 | { |
||
| 14 | 46 | Http::macro('withRefreshToken', function ( |
|
| 15 | 46 | string $refreshUrl, |
|
| 16 | 46 | string|array|Credentials $credentials = [ |
|
| 17 | 46 | 'refresh_token' => '', |
|
| 18 | 46 | 'client_id' => '', |
|
| 19 | 46 | 'client_secret' => '', |
|
| 20 | 46 | ], |
|
| 21 | 46 | array|Options $options = [], |
|
| 22 | 46 | ): PendingRequest { |
|
| 23 | |||
| 24 | 5 | $options = $options instanceof Options ? $options : Options::make($options); |
|
|
|
|||
| 25 | 5 | $credentials = $credentials instanceof Credentials ? $credentials : new Credentials($credentials); |
|
| 26 | |||
| 27 | 5 | $accessToken = TokenStore::get( |
|
| 28 | 5 | refreshUrl: $refreshUrl, |
|
| 29 | 5 | credentials: $credentials->setOptions($options), |
|
| 30 | 5 | options: $options, |
|
| 31 | 5 | ); |
|
| 32 | |||
| 33 | /** @var PendingRequest|Factory $httpClient */ |
||
| 34 | 5 | $httpClient = $this; |
|
| 35 | |||
| 36 | // If we get a factory, we can create a new pending request |
||
| 37 | 5 | if ($httpClient instanceof Factory) { |
|
| 38 | 5 | $httpClient = $httpClient->createPendingRequest(); |
|
| 39 | } |
||
| 40 | |||
| 41 | 5 | return $accessToken->getHttpClient($httpClient); |
|
| 42 | 46 | }); |
|
| 45 |