| Conditions | 8 |
| Paths | 17 |
| Total Lines | 97 |
| Code Lines | 64 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 72 | protected function login(string $username, string $password): array |
||
| 73 | { |
||
| 74 | $encryption = $this->ldapConfig->getOptionalString('encryption', 'ssl'); |
||
| 75 | Assert::oneOf($encryption, ['none', 'ssl', 'tls']); |
||
| 76 | |||
| 77 | $version = $this->ldapConfig->getOptionalInteger('version', 3); |
||
| 78 | Assert::positiveInteger($version); |
||
| 79 | |||
| 80 | $timeout = $this->ldapConfig->getOptionalInteger('timeout', 3); |
||
| 81 | Assert::positiveInteger($timeout); |
||
| 82 | |||
| 83 | $ldapUtils = new Utils\Ldap(); |
||
|
|
|||
| 84 | $ldapObject = $ldapUtils->create( |
||
| 85 | $this->ldapConfig->getString('connection_string'), |
||
| 86 | $encryption, |
||
| 87 | $version, |
||
| 88 | $this->ldapConfig->getOptionalString('extension', 'ext_ldap'), |
||
| 89 | $this->ldapConfig->getOptionalBoolean('debug', false), |
||
| 90 | $this->ldapConfig->getOptionalArray('options', []), |
||
| 91 | ); |
||
| 92 | |||
| 93 | $searchScope = $this->ldapConfig->getOptionalString('search.scope', Query::SCOPE_SUB); |
||
| 94 | Assert::oneOf($searchScope, [Query::SCOPE_BASE, Query::SCOPE_ONE, Query::SCOPE_SUB]); |
||
| 95 | |||
| 96 | $timeout = $this->ldapConfig->getOptionalInteger('timeout', 3); |
||
| 97 | $searchBase = $this->ldapConfig->getArray('search.base'); |
||
| 98 | $options = [ |
||
| 99 | 'scope' => $searchScope, |
||
| 100 | 'timeout' => $timeout, |
||
| 101 | ]; |
||
| 102 | |||
| 103 | $searchEnable = $this->ldapConfig->getOptionalBoolean('search.enable', false); |
||
| 104 | if ($searchEnable === false) { |
||
| 105 | $dnPattern = $this->ldapConfig->getString('dnpattern'); |
||
| 106 | $dn = str_replace('%username%', $username, $dnPattern); |
||
| 107 | } else { |
||
| 108 | $searchUsername = $this->ldapConfig->getString('search.username'); |
||
| 109 | Assert::notWhitespaceOnly($searchUsername); |
||
| 110 | |||
| 111 | $searchPassword = $this->ldapConfig->getOptionalString('search.password', null); |
||
| 112 | Assert::nullOrnotWhitespaceOnly($searchPassword); |
||
| 113 | |||
| 114 | $searchAttributes = $this->ldapConfig->getArray('search.attributes'); |
||
| 115 | $searchFilter = $this->ldapConfig->getOptionalString('search.filter', null); |
||
| 116 | |||
| 117 | try { |
||
| 118 | $this->connector->bind($searchUsername, $searchPassword); |
||
| 119 | } catch (Error\Error $e) { |
||
| 120 | throw new Error\Exception("Unable to bind using the configured search.username and search.password."); |
||
| 121 | } |
||
| 122 | |||
| 123 | $filter = ''; |
||
| 124 | foreach ($searchAttributes as $attr) { |
||
| 125 | $filter .= '(' . $attr . '=' . $username . ')'; |
||
| 126 | } |
||
| 127 | $filter = '(|' . $filter . ')'; |
||
| 128 | |||
| 129 | // Append LDAP filters if defined |
||
| 130 | if ($searchFilter !== null) { |
||
| 131 | $filter = "(&" . $filter . $searchFilter . ")"; |
||
| 132 | } |
||
| 133 | |||
| 134 | try { |
||
| 135 | /** @psalm-var \Symfony\Component\Ldap\Entry $entry */ |
||
| 136 | $entry = $this->connector->search($searchBase, $filter, $options, false); |
||
| 137 | $dn = $entry->getDn(); |
||
| 138 | } catch (Error\Exception $e) { |
||
| 139 | throw new Error\Error('WRONGUSERPASS'); |
||
| 140 | } |
||
| 141 | } |
||
| 142 | |||
| 143 | $this->connector->bind($dn, $password); |
||
| 144 | $filter = sprintf('(distinguishedName=%s)', $dn); |
||
| 145 | |||
| 146 | /** @psalm-var \Symfony\Component\Ldap\Entry $entry */ |
||
| 147 | $entry = $this->connector->search($searchBase, $filter, $options, false); |
||
| 148 | |||
| 149 | $attributes = $this->ldapConfig->getOptionalValue('attributes', []); |
||
| 150 | if ($attributes === null) { |
||
| 151 | $result = $entry->getAttributes(); |
||
| 152 | } else { |
||
| 153 | Assert::isArray($attributes); |
||
| 154 | $result = array_intersect_key( |
||
| 155 | $entry->getAttributes(), |
||
| 156 | array_fill_keys(array_values($attributes), null) |
||
| 157 | ); |
||
| 158 | } |
||
| 159 | |||
| 160 | $binaries = array_intersect( |
||
| 161 | array_keys($result), |
||
| 162 | $this->ldapConfig->getOptionalArray('attributes.binary', []), |
||
| 163 | ); |
||
| 164 | foreach ($binaries as $binary) { |
||
| 165 | $result[$binary] = array_map('base64_encode', $result[$binary]); |
||
| 166 | } |
||
| 167 | |||
| 168 | return $result; |
||
| 169 | } |
||
| 203 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths