LaravelHttpOAuthHelperServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
dl 0
loc 32
ccs 21
cts 21
cp 1
rs 10
c 1
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A boot() 0 30 4
1
<?php
2
3
namespace Pelmered\LaravelHttpOAuthHelper;
4
5
use Illuminate\Http\Client\Factory;
6
use Illuminate\Http\Client\PendingRequest;
7
use Illuminate\Support\Facades\Http;
8
use Illuminate\Support\ServiceProvider;
9
10
class LaravelHttpOAuthHelperServiceProvider extends ServiceProvider
11
{
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);
0 ignored issues
show
introduced by
$options is never a sub-type of Pelmered\LaravelHttpOAuthHelper\Options.
Loading history...
25 5
            $credentials = $credentials instanceof Credentials ? $credentials : new Credentials($credentials);
0 ignored issues
show
introduced by
$credentials is never a sub-type of Pelmered\LaravelHttpOAuthHelper\Credentials.
Loading history...
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
        });
43
    }
44
}
45