SessionStorage::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace Baguette\Mastodon\Service;
4
5
use Baguette\Mastodon;
6
use Baguette\Mastodon\Service;
7
8
/**
9
 * Mastodon Anthorization object factory
10
 *
11
 * @author    USAMI Kenta <[email protected]>
12
 * @copyright 2017 Baguette HQ
13
 * @license   https://www.gnu.org/licenses/gpl-3.0.html GPL-3.0
14
 */
15
class SessionStorage
16
{
17
    use \Teto\Object\PrivateGetter;
18
19
    /** @var AuthFactory */
20
    private $auth_factory;
21
    /** @var Scope */
22
    private $scope;
23
    /** @var Authorization */
24
    private $authorization;
25
26
    /**
27
     * @param AuthFactory $auth_factory
28
     * @param Scope       $scope
29
     */
30 2
    public function __construct(AuthFactory $auth_factory, Scope $scope)
31
    {
32 2
        $this->auth_factory = $auth_factory;
33 2
        $this->scope = $scope;
34 2
    }
35
36
    /**
37
     * @return string
38
     */
39 1
    public function getAccessToken()
40
    {
41 1
        $this->authorize();
42
43 1
        return $this->authorization->access_token;
44
    }
45
46
    /**
47
     * @param  bool $force
48
     * @return Authorization
49
     */
50 1
    public function authorize($force = false)
51
    {
52 1
        if ($force || $this->authorization === null) {
53
            $this->authorization = $this->auth_factory->authorize($this->scope);
54
        }
55
56 1
        return $this->authorization;
57
    }
58
59
    /**
60
     * @param  Authorization $authorization
61
     * @return void
62
     */
63 2
    public function setAuthorization(Authorization $authorization)
64
    {
65 2
        $this->authorization = $authorization;
66 2
    }
67
}
68