Conditions | 3 |
Paths | 2 |
Total Lines | 78 |
Code Lines | 40 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
85 | public function __construct(array &$config, $reserved) |
||
86 | { |
||
87 | parent::__construct($config, $reserved); |
||
88 | |||
89 | // Change the class $title to match it's true name |
||
90 | // This way if the class is extended the proper name is used |
||
91 | $classname = explode('_', get_class($this)); |
||
92 | $classname = end($classname); |
||
93 | $this->title = 'ldap:' . $classname; |
||
94 | |||
95 | // Log the construction |
||
96 | Logger::debug(sprintf('%s : Creating and configuring the filter.', $this->title)); |
||
97 | |||
98 | // If an authsource was defined (an not empty string)... |
||
99 | if (isset($config['authsource']) && $config['authsource'] !== '') { |
||
100 | $authconfig = $this->parseAuthSourceConfig($config['authsource']); |
||
101 | |||
102 | // Merge the authsource config with the filter config, |
||
103 | // but have the filter config override the authsource config |
||
104 | $config = array_merge($authconfig, $config); |
||
105 | |||
106 | // Authsource complete |
||
107 | Logger::debug(sprintf( |
||
108 | '%s : Retrieved authsource [%s] configuration values: %s', |
||
109 | $this->title, |
||
110 | $config['authsource'], |
||
111 | $this->varExport($authconfig), |
||
112 | )); |
||
113 | } |
||
114 | |||
115 | // Convert the config array to a config class, |
||
116 | // that way we can verify type and define defaults. |
||
117 | // Store in the instance in-case needed later, by a child class. |
||
118 | $this->config = Configuration::loadFromArray($config, 'ldap:AuthProcess'); |
||
119 | |||
120 | // Initialize the Ldap-object |
||
121 | $this->connector = ConnectorFactory::fromAuthSource($config['authsource']); |
||
122 | |||
123 | // Set all the filter values, setting defaults if needed |
||
124 | $this->searchBase = $this->config->getOptionalArray('search.base', []); |
||
125 | |||
126 | // Log the member values retrieved above |
||
127 | Logger::debug(sprintf( |
||
128 | '%s : Configuration values retrieved; BaseDN: %s', |
||
129 | $this->title, |
||
130 | $this->varExport($this->searchBase), |
||
131 | )); |
||
132 | |||
133 | // Setup the attribute map which will be used to search LDAP |
||
134 | $this->attribute_map = [ |
||
135 | 'dn' => $this->config->getOptionalString('attribute.dn', 'distinguishedName'), |
||
136 | 'groups' => $this->config->getOptionalString('attribute.groups', 'groups'), |
||
137 | 'member' => $this->config->getOptionalString('attribute.member', 'member'), |
||
138 | 'memberOf' => $this->config->getOptionalString('attribute.memberOf', 'memberOf'), |
||
139 | 'name' => $this->config->getOptionalString('attribute.groupname', 'name'), |
||
140 | 'return' => $this->config->getOptionalString('attribute.return', 'distinguishedName'), |
||
141 | 'type' => $this->config->getOptionalString('attribute.type', 'objectClass'), |
||
142 | 'username' => $this->config->getOptionalString('attribute.username', 'sAMAccountName'), |
||
143 | ]; |
||
144 | |||
145 | // Log the attribute map |
||
146 | Logger::debug(sprintf( |
||
147 | '%s : Attribute map created: %s', |
||
148 | $this->title, |
||
149 | $this->varExport($this->attribute_map), |
||
150 | )); |
||
151 | |||
152 | // Setup the object type map which is used to determine a DNs' type |
||
153 | $this->type_map = [ |
||
154 | 'group' => $this->config->getOptionalString('type.group', 'group'), |
||
155 | 'user' => $this->config->getOptionalString('type.user', 'user'), |
||
156 | ]; |
||
157 | |||
158 | // Log the type map |
||
159 | Logger::debug(sprintf( |
||
160 | '%s : Type map created: %s', |
||
161 | $this->title, |
||
162 | $this->varExport($this->type_map), |
||
163 | )); |
||
296 |