Completed
Push — master ( a51466...8daf75 )
by Raffael
02:47
created

AbstractAdapter   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 100
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getAttributeSyncCache() 0 4 1
B setOptions() 0 20 5
A getIdentifier() 0 4 1
A getAttributeMap() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * Micro
6
 *
7
 * @author      Raffael Sahli <[email protected]>
8
 * @copyright   Copryright (c) 2012-2017 gyselroth GmbH (https://gyselroth.com)
9
 * @license     GPLv3 https://opensource.org/licenses/GPL-3.0
10
 */
11
12
namespace Micro\Auth\Adapter;
13
14
use \Psr\Log\LoggerInterface as Logger;
15
use \Micro\Auth\Adapter\AdapterInterface;
16
17
abstract class AbstractAdapter implements AdapterInterface
18
{
19
    /**
20
     * Identity
21
     *
22
     * @var string
23
     */
24
    protected $identifier;
25
26
27
    /**
28
     * attribute sync cache
29
     *
30
     * @var int
31
     */
32
    protected $attr_sync_cache = 0;
33
    
34
    
35
    /**
36
     * attribute map
37
     *
38
     * @var Iterable
39
     */
40
    protected $map = [];
41
   
42
43
    /**
44
     * Ldap connect
45
     *
46
     * @param   Iterable $config
47
     * @param   Logger $logger
48
     * @return  void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
49
     */
50
    public function __construct(?Iterable $config, Logger $logger)
51
    {
52
        $this->logger = $logger;
0 ignored issues
show
Bug introduced by
The property logger does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
53
        $this->setOptions($config);
54
    }
55
    
56
57
    /**
58
     * Get attribute sync cache
59
     *
60
     * @return int
61
     */
62
    public function getAttributeSyncCache(): int
63
    {
64
        return $this->attr_sync_cache;
65
    }
66
67
68
    /**
69
     * Set options
70
     *
71
     * @param   Iterable $config
72
     * @return  AdapterInterface
73
     */
74
    public function setOptions(?Iterable $config=null): AdapterInterface
75
    {
76
        if ($config === null) {
77
            return $this;
78
        }
79
        
80
        foreach ($config as $option => $value) {
81
            switch ($option) {
82
                case 'map':
83
                    $this->map = $value;
84
                break;
85
                
86
                case 'attr_sync_cache':
87
                    $this->attr_sync_cache = (int)$value;
88
                break;
89
            }
90
        }
91
        
92
        return $this;
93
    }
94
    
95
96
    /**
97
     * Get identifier
98
     *
99
     * @return string
100
     */
101
    public function getIdentifier(): string
102
    {
103
        return $this->identifier;
104
    }
105
106
    
107
    /**
108
     * Get attribute map
109
     *
110
     * @return Iterable
111
     */
112
    public function getAttributeMap(): Iterable
113
    {
114
        return $this->map;
115
    }
116
}
117