Passed
Push — master ( 89aa63...6044a8 )
by Raffael
02:46
created

AbstractAdapter::getIdentityAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Micro
7
 *
8
 * @copyright   Copryright (c) 2015-2018 gyselroth GmbH (https://gyselroth.com)
9
 * @license     MIT https://opensource.org/licenses/MIT
10
 */
11
12
namespace Micro\Auth\Adapter;
13
14
use InvalidArgumentException;
15
16
abstract class AbstractAdapter implements AdapterInterface
17
{
18
    /**
19
     * Identity.
20
     *
21
     * @var string
22
     */
23
    protected $identifier;
24
25
    /**
26
     * attribute sync cache.
27
     *
28
     * @var int
29
     */
30
    protected $attr_sync_cache = 0;
31
32
    /**
33
     * attribute map.
34
     *
35
     * @var iterable
36
     */
37
    protected $map = [];
38
39
    /**
40
     * Identity attribute.
41
     *
42
     * @var string
43
     */
44
    protected $identity_attribute = 'uid';
45
46
    /**
47
     * Get attribute sync cache.
48
     *
49
     * @return int
50
     */
51
    public function getAttributeSyncCache(): int
52
    {
53
        return $this->attr_sync_cache;
54
    }
55
56
    /**
57
     * Set options.
58
     *
59
     * @param iterable $config
60
     *
61
     * @return AdapterInterface
62
     */
63
    public function setOptions(? Iterable $config = null): AdapterInterface
64
    {
65
        if (null === $config) {
66
            return $this;
67
        }
68
69
        foreach ($config as $option => $value) {
70
            switch ($option) {
71
                case 'map':
72
                    $this->map = $value;
73
74
                break;
75
                case 'attr_sync_cache':
76
                    $this->attr_sync_cache = (int) $value;
77
78
                break;
79
                case 'identity_attribute':
80
                    $this->identity_attribute = (int) $value;
81
82
                break;
83
                default:
84
                    throw new InvalidArgumentException('unknown option '.$option.' given');
85
            }
86
        }
87
88
        return $this;
89
    }
90
91
    /**
92
     * Get identifier.
93
     *
94
     * @return string
95
     */
96
    public function getIdentityAttribute(): string
97
    {
98
        return $this->identity_attribute;
99
    }
100
101
    /**
102
     * Get identifier.
103
     *
104
     * @return string
105
     */
106
    public function getIdentifier(): string
107
    {
108
        return $this->identifier;
109
    }
110
111
    /**
112
     * Get attribute map.
113
     *
114
     * @return iterable
115
     */
116
    public function getAttributeMap(): Iterable
117
    {
118
        return $this->map;
119
    }
120
}
121