| Conditions | 11 |
| Paths | 17 |
| Total Lines | 43 |
| Code Lines | 27 |
| 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 |
||
| 132 | public function exec(string $action, int $part, string $key, string $type = IRegistry::REG_NONE, $content = ''): bool |
||
| 133 | { |
||
| 134 | if (empty($key)) { |
||
| 135 | return false; |
||
| 136 | } |
||
| 137 | |||
| 138 | if (!isset(static::$allowedParts[$part])) { |
||
| 139 | throw new MapperException('You must set correct part of registry tree!'); |
||
| 140 | } |
||
| 141 | |||
| 142 | if (!isset(static::$allowedTypes[$type])) { |
||
| 143 | throw new MapperException(sprintf('Problematic type *%s*', strval($key))); |
||
| 144 | } |
||
| 145 | |||
| 146 | $this->connect(); |
||
| 147 | |||
| 148 | // ends without slash - got value |
||
| 149 | $path = sprintf('%s\\%s', static::$allowedParts[$part], $this->dropSlash($key)); |
||
| 150 | $path .= (IRegistry::REG_NONE == $type) ? '\\' : ''; // none type = it's "dir", not "entry" |
||
| 151 | |||
| 152 | if (IDriverSources::ACTION_INSERT == $action) { |
||
| 153 | try{ |
||
| 154 | $this->connection->RegWrite($path, $content, static::$allowedTypes[$type]); |
||
| 155 | } catch (\Exception $e) { |
||
| 156 | throw new MapperException('Cannot write into registry', 0, $e); |
||
| 157 | } |
||
| 158 | } elseif (IDriverSources::ACTION_UPDATE == $action) { |
||
| 159 | try{ |
||
| 160 | $this->connection->RegWrite($path, $content, static::$allowedTypes[$type]); |
||
| 161 | } catch (\Exception $e) { |
||
| 162 | throw new MapperException('Cannot write into registry', 0, $e); |
||
| 163 | } |
||
| 164 | } elseif (IDriverSources::ACTION_DELETE == $action) { |
||
| 165 | try{ |
||
| 166 | $this->connection->RegDelete($path); |
||
| 167 | } catch(\Exception $e) { |
||
| 168 | throw new MapperException('Cannot delete from registry', 0, $e); |
||
| 169 | } |
||
| 170 | } else { |
||
| 171 | return false; |
||
| 172 | } |
||
| 173 | |||
| 174 | return true; |
||
| 175 | } |
||
| 189 |