| 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 |
||
| 88 | public function __construct(array &$config, $reserved) |
||
| 89 | { |
||
| 90 | parent::__construct($config, $reserved); |
||
| 91 | |||
| 92 | // Change the class $title to match it's true name |
||
| 93 | // This way if the class is extended the proper name is used |
||
| 94 | $classname = explode('_', get_class($this)); |
||
| 95 | $classname = end($classname); |
||
| 96 | $this->title = 'ldap:' . $classname; |
||
| 97 | |||
| 98 | // Log the construction |
||
| 99 | Logger::debug(sprintf('%s : Creating and configuring the filter.', $this->title)); |
||
| 100 | |||
| 101 | // If an authsource was defined (an not empty string)... |
||
| 102 | if (isset($config['authsource']) && $config['authsource'] !== '') { |
||
| 103 | $authconfig = $this->parseAuthSourceConfig($config['authsource']); |
||
| 104 | |||
| 105 | // Merge the authsource config with the filter config, |
||
| 106 | // but have the filter config override the authsource config |
||
| 107 | $config = array_merge($authconfig, $config); |
||
| 108 | |||
| 109 | // Authsource complete |
||
| 110 | Logger::debug(sprintf( |
||
| 111 | '%s : Retrieved authsource [%s] configuration values: %s', |
||
| 112 | $this->title, |
||
| 113 | $config['authsource'], |
||
| 114 | $this->varExport($authconfig), |
||
| 115 | )); |
||
| 116 | } |
||
| 117 | |||
| 118 | // Convert the config array to a config class, |
||
| 119 | // that way we can verify type and define defaults. |
||
| 120 | // Store in the instance in-case needed later, by a child class. |
||
| 121 | $this->config = Configuration::loadFromArray($config, 'ldap:AuthProcess'); |
||
| 122 | |||
| 123 | // Initialize the Ldap-object |
||
| 124 | $this->connector = ConnectorFactory::fromAuthSource($config['authsource']); |
||
| 125 | |||
| 126 | // Set all the filter values, setting defaults if needed |
||
| 127 | $this->searchBase = $this->config->getOptionalArray('search.base', []); |
||
| 128 | |||
| 129 | // Log the member values retrieved above |
||
| 130 | Logger::debug(sprintf( |
||
| 131 | '%s : Configuration values retrieved; BaseDN: %s', |
||
| 132 | $this->title, |
||
| 133 | $this->varExport($this->searchBase), |
||
| 134 | )); |
||
| 135 | |||
| 136 | // Setup the attribute map which will be used to search LDAP |
||
| 137 | $this->attribute_map = [ |
||
| 138 | 'dn' => $this->config->getOptionalString('attribute.dn', 'distinguishedName'), |
||
| 139 | 'groups' => $this->config->getOptionalString('attribute.groups', 'groups'), |
||
| 140 | 'member' => $this->config->getOptionalString('attribute.member', 'member'), |
||
| 141 | 'memberOf' => $this->config->getOptionalString('attribute.memberOf', 'memberOf'), |
||
| 142 | 'name' => $this->config->getOptionalString('attribute.groupname', 'name'), |
||
| 143 | 'return' => $this->config->getOptionalString('attribute.return', 'distinguishedName'), |
||
| 144 | 'type' => $this->config->getOptionalString('attribute.type', 'objectClass'), |
||
| 145 | 'username' => $this->config->getOptionalString('attribute.username', 'sAMAccountName'), |
||
| 146 | ]; |
||
| 147 | |||
| 148 | // Log the attribute map |
||
| 149 | Logger::debug(sprintf( |
||
| 150 | '%s : Attribute map created: %s', |
||
| 151 | $this->title, |
||
| 152 | $this->varExport($this->attribute_map), |
||
| 153 | )); |
||
| 154 | |||
| 155 | // Setup the object type map which is used to determine a DNs' type |
||
| 156 | $this->type_map = [ |
||
| 157 | 'group' => $this->config->getOptionalString('type.group', 'group'), |
||
| 158 | 'user' => $this->config->getOptionalString('type.user', 'user'), |
||
| 159 | ]; |
||
| 160 | |||
| 161 | // Log the type map |
||
| 162 | Logger::debug(sprintf( |
||
| 163 | '%s : Type map created: %s', |
||
| 164 | $this->title, |
||
| 165 | $this->varExport($this->type_map), |
||
| 166 | )); |
||
| 299 |