Conditions | 12 |
Paths | 528 |
Total Lines | 70 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Changes | 6 | ||
Bugs | 1 | 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 |
||
104 | public function __construct($config, $reserved) |
||
105 | { |
||
106 | /** |
||
107 | * Remove annotation + assert as soon as this method can be typehinted (SSP 2.0) |
||
108 | * @psalm-suppress RedundantConditionGivenDocblockType |
||
109 | */ |
||
110 | assert(is_array($config)); |
||
111 | parent::__construct($config, $reserved); |
||
112 | |||
113 | try { |
||
114 | $this->store = Store::parseStoreConfig($config['store']); |
||
115 | } catch (\Exception $e) { |
||
116 | Logger::error( |
||
117 | 'webauthn: Could not create storage: ' . |
||
118 | $e->getMessage() |
||
119 | ); |
||
120 | } |
||
121 | |||
122 | // Set the optional scope if set by configuration |
||
123 | if (array_key_exists('scope', $config)) { |
||
124 | $this->scope = $config['scope']; |
||
125 | } |
||
126 | |||
127 | // Set the derived scope so we can compare it to the sent host at a later point |
||
128 | $baseurl = Utils\HTTP::getSelfHost(); |
||
129 | $hostname = parse_url($baseurl, PHP_URL_HOST); |
||
130 | if ($hostname !== null) { |
||
131 | $this->derivedScope = $hostname; |
||
132 | } |
||
133 | |||
134 | if (array_key_exists('attrib_username', $config)) { |
||
135 | $this->usernameAttrib = $config['attrib_username']; |
||
136 | } else { |
||
137 | throw new Error\CriticalConfigurationError('webauthn: it is required to set attrib_username in config.'); |
||
138 | } |
||
139 | |||
140 | if (array_key_exists('attrib_displayname', $config)) { |
||
141 | $this->displaynameAttrib = $config['attrib_displayname']; |
||
142 | } else { |
||
143 | throw new Error\CriticalConfigurationError('webauthn: it is required to set attrib_displayname in config.'); |
||
144 | } |
||
145 | |||
146 | if (array_key_exists('request_tokenmodel', $config)) { |
||
147 | $this->requestTokenModel = $config['request_tokenmodel']; |
||
148 | } else { |
||
149 | $this->requestTokenModel = false; |
||
150 | } |
||
151 | if (array_key_exists('default_enable', $config)) { |
||
152 | $this->defaultEnabled = $config['default_enable']; |
||
153 | } else { |
||
154 | $this->defaultEnabled = false; |
||
155 | } |
||
156 | |||
157 | if (array_key_exists('force', $config)) { |
||
158 | $this->force = $config['force']; |
||
159 | } else { |
||
160 | $this->force = true; |
||
161 | } |
||
162 | if (array_key_exists('attrib_toggle', $config)) { |
||
163 | $this->toggleAttrib = $config['attrib_toggle']; |
||
164 | } else { |
||
165 | $this->toggleAttrib = 'toggle'; |
||
|
|||
166 | } |
||
167 | if (array_key_exists('use_database', $config)) { |
||
168 | $this->useDatabase = $config['use_database']; |
||
169 | } else { |
||
170 | $this->useDatabase = true; |
||
171 | } |
||
172 | if (array_key_exists('authnContextClassRef', $config)) { |
||
173 | $this->authnContextClassRef = $config['authnContextClassRef']; |
||
174 | |||
245 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.