Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
7 / 7
CRAP
100.00% covered (success)
100.00%
13 / 13
GoogleApiWrapper
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
7 / 7
9
100.00% covered (success)
100.00%
13 / 13
 withUser
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
4 / 4
 service
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
4 / 4
 getAccessToken
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getOption
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setOption
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getSubject
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
1<?php
2
3namespace Qmp\Laravel\GoogleApiWrapper;
4
5use Illuminate\Support\Collection;
6use Qmp\Laravel\GoogleApiWrapper\Client\GoogleClientWrapper;
7use Qmp\Laravel\GoogleApiWrapper\Factory\GoogleServiceFactory;
8use Qmp\Laravel\GoogleApiWrapper\Services\GoogleBaseService;
9
10class GoogleApiWrapper
11{
12    /**
13     * Undocumented variable
14     *
15     * @var GoogleClientWrapper
16     */
17    protected $client;
18
19    /**
20     * Undocumented variable
21     *
22     * @var Collection
23     */
24    protected $services;
25
26    /**
27     * Undocumented variable
28     *
29     * @var Collection
30     */
31    protected $options;
32
33
34    /**
35     * Undocumented function
36     *
37     * @param string|null $subject
38     * @param array|null $authConfig
39     * @return self
40     */
41    public static function withUser(string $subject = null, array $authConfig = null): self
42    {
43        return new Self($subject, $authConfig);
44    }
45
46
47    /**
48     * Undocumented function
49     *
50     * @param string|null $subject
51     * @param array|null $authConfig
52     */
53    public function __construct(string $subject = null, array $authConfig = null)
54    {
55        $this->services = collect();
56        $this->options = collect();
57        $this->client = GoogleClientWrapper::make($subject, $authConfig);
58    }
59
60    /**
61     * Getter for the google service.
62     *
63     * @param string $service
64     * @throws \Exception
65     * @return GoogleBaseService
66     */
67    public function service($serviceName): GoogleBaseService
68    {
69        if (!$this->services->has($serviceName)) {
70
71            if ($service = GoogleServiceFactory::make($serviceName, $this->client, $this)) {
72                $this->services->put($serviceName, $service);
73            }
74        }
75
76        return $this->services->get($serviceName);
77    }
78
79    /**
80     * Undocumented function
81     *
82     * @return array|null
83     */
84    public function getAccessToken() {
85        return $this->client->getAccessToken();
86    }
87
88
89    /**
90     * Undocumented function
91     *
92     * @param string $key
93     * @return void
94     */
95    public function getOption($key) {
96        return $this->options->get($key) ?? null;
97    }
98
99    /**
100     * Undocumented function
101     *
102     * @param string $key
103     * @param mixed $value
104     * @return void
105     */
106    public function setOption($key, $value) {
107        return $this->options->put($key, $value);
108    }
109
110     /**
111     * Undocumented function
112     *
113     * @return string
114     */
115    public function getSubject(): string
116    {
117        return $this->client->getSubject();
118    }
119}