ConfigProviderBuilder::setRedirectUrl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * Copyright © Thomas Klein, All rights reserved.
4
 * See LICENSE bundled with this library for license details.
5
 */
6
declare(strict_types=1);
7
8
namespace Zoho\Desk\Client;
9
10
use Zoho\OAuth\Utility\ZohoOAuthConstants;
11
use Zoho\Desk\Api\Metadata;
12
13
/**
14
 * @api
15
 */
16
final class ConfigProviderBuilder
17
{
18
    /**
19
     * @var string[]
20
     */
21
    private array $settings;
22
23
    private static ?ConfigProviderBuilder $instance = null;
24
25
    private function __construct()
26
    {
27
        $this->settings = [];
28
    }
29
30
    public static function getInstance(): self
31
    {
32
        return self::$instance ?? self::$instance = new self();
33
    }
34
35
    public function setClientId(string $clientId): self
36
    {
37
        $this->settings[ZohoOAuthConstants::CLIENT_ID] = $clientId;
38
39
        return $this;
40
    }
41
42
    public function setClientSecret(string $clientSecret): self
43
    {
44
        $this->settings[ZohoOAuthConstants::CLIENT_SECRET] = $clientSecret;
45
46
        return $this;
47
    }
48
49
    public function setRedirectUrl(string $redirectUrl): self
50
    {
51
        $this->settings[ZohoOAuthConstants::REDIRECT_URL] = $redirectUrl;
52
53
        return $this;
54
    }
55
56
    public function setCurrentUserEmail(string $userEmail): self
57
    {
58
        $this->settings[Metadata::API_FIELD_CURRENT_USER_EMAIL] = $userEmail;
59
60
        return $this;
61
    }
62
63
    public function setApiBaseUrl(string $apiBaseUrl): self
64
    {
65
        $this->settings[Metadata::API_FIELD_BASE_URL] = $apiBaseUrl;
66
67
        return $this;
68
    }
69
70
    public function setApiVersion(string $apiVersion): self
71
    {
72
        $this->settings[Metadata::API_FIELD_VERSION] = $apiVersion;
73
74
        return $this;
75
    }
76
77
    public function setOrgId(int $orgId): self
78
    {
79
        $this->settings[Metadata::ORG_ID] = $orgId;
80
81
        return $this;
82
    }
83
84
    public function setIsSandbox(bool $isSandbox): self
85
    {
86
        $this->settings[ZohoOAuthConstants::SANDBOX] = $isSandbox;
87
88
        return $this;
89
    }
90
91
    public function setAccountsUrl(string $accountsUrl): self
92
    {
93
        $this->settings[ZohoOAuthConstants::IAM_URL] = $accountsUrl;
94
95
        return $this;
96
    }
97
98
    public function setTokenPersistencePath(string $directoryPath): self
99
    {
100
        $this->settings[ZohoOAuthConstants::TOKEN_PERSISTENCE_PATH] = $directoryPath;
101
102
        return $this;
103
    }
104
105
    public function create(): ConfigProviderInterface
106
    {
107
        $configProvider = new ConfigProvider($this->settings);
108
109
        $this->settings = [];
110
111
        return $configProvider;
112
    }
113
}
114