Passed
Pull Request — master (#9)
by Volodymyr
17:33 queued 09:33
created

TokenGenerator::generateToken()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 0
dl 0
loc 14
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Service\Braintree\Model\TokenGenerator;
9
10
use Braintree\ClientToken;
11
use Braintree\Configuration;
12
use SprykerEco\Service\Braintree\BraintreeConfig;
13
14
class TokenGenerator implements TokenGeneratorInterface
15
{
16
    /**
17
     * @var \SprykerEco\Service\Braintree\BraintreeConfig
18
     */
19
    protected $config;
20
21
    /**
22
     * @var
23
     */
24
    protected static $clientToken;
25
26
    /**
27
     * @param \SprykerEco\Service\Braintree\BraintreeConfig $config
28
     */
29
    public function __construct(BraintreeConfig $config)
30
    {
31
        $this->config = $config;
32
    }
33
34
    /**
35
     * @return string
36
     */
37
    public function generateToken(): string
38
    {
39
        if (static::$clientToken) {
40
            return static::$clientToken;
41
        }
42
43
        Configuration::environment($this->config->getEnvironment());
44
        Configuration::merchantId($this->config->getMerchantId());
45
        Configuration::publicKey($this->config->getPublicKey());
46
        Configuration::privateKey($this->config->getPrivateKey());
47
48
        static::$clientToken = ClientToken::generate();
49
50
        return static::$clientToken;
51
    }
52
}
53