| Conditions | 16 |
| Paths | 17 |
| Total 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 |
||
| 42 | public function init($filters = array(), $filterFile = '', $exclusive = array()) |
||
| 43 | { |
||
| 44 | if (count($exclusive) > 0 && (count($filters) > 0 || $filterFile !== '')) { |
||
| 45 | throw new \RuntimeException("It's not possible to define filter lists and an exclusive list at the same time [Extension: " . get_class($this) . '].'); |
||
| 46 | } |
||
| 47 | |||
| 48 | if ($filterFile !== '') { |
||
| 49 | if (!file_exists($filterFile)) { |
||
| 50 | throw new \RuntimeException('Filter file not found: ' . $filterFile); |
||
| 51 | } |
||
| 52 | |||
| 53 | $filterElements = EnvAwareYaml::parse(file_get_contents($filterFile)); |
||
| 54 | |||
| 55 | foreach ($filterElements['filters'] as $rule => $uris) { |
||
| 56 | foreach ($uris as $uri) { |
||
| 57 | $this->filters[] = array('rule' => $rule, 'uri' => $uri); |
||
| 58 | } |
||
| 59 | } |
||
| 60 | } elseif (!is_null($filters)) { |
||
| 61 | foreach ($filters as $rule => $filteredUrls) { |
||
| 62 | if (!is_null($filteredUrls)) { |
||
| 63 | foreach ($filteredUrls as $uri) { |
||
| 64 | $this->filters[] = array('rule' => $rule, 'uri' => $uri); |
||
| 65 | } |
||
| 66 | } |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | if (count($exclusive) > 0) { |
||
| 71 | foreach ($exclusive as $rule => $urls) { |
||
| 72 | if (is_array($urls)) { |
||
| 73 | foreach ($urls as $url) { |
||
| 74 | $uri = new Uri($url); |
||
| 75 | $this->exclusives[$rule][] = (string)$uri; |
||
| 76 | } |
||
| 77 | } |
||
| 78 | } |
||
| 79 | $this->currentModus = self::MODUS_EXCLUSIVE; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 137 |