Conditions | 7 |
Paths | 7 |
Total Lines | 66 |
Code Lines | 38 |
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 |
||
61 | private function retrieveExcludedNamespaces(array $config): array |
||
62 | { |
||
63 | $key = ConfigurationKeys::EXCLUDE_NAMESPACES_KEYWORD; |
||
64 | |||
65 | if (!array_key_exists($key, $config)) { |
||
66 | return [[], []]; |
||
67 | } |
||
68 | |||
69 | $regexesAndNamespaceNames = $config[$key]; |
||
70 | |||
71 | if (!is_array($regexesAndNamespaceNames)) { |
||
72 | throw new InvalidArgumentException( |
||
73 | sprintf( |
||
74 | 'Expected "%s" to be an array of strings, got "%s" instead.', |
||
75 | $key, |
||
76 | gettype($regexesAndNamespaceNames), |
||
77 | ), |
||
78 | ); |
||
79 | } |
||
80 | |||
81 | // Store the strings in the keys for avoiding a unique check later on |
||
82 | $regexes = []; |
||
83 | $namespaceNames = []; |
||
84 | |||
85 | foreach ($regexesAndNamespaceNames as $index => $regexOrNamespaceName) { |
||
86 | if (!is_string($regexOrNamespaceName)) { |
||
87 | throw new InvalidArgumentException( |
||
88 | sprintf( |
||
89 | 'Expected "%s" to be an array of strings, got "%s" for the element with the index "%s".', |
||
90 | $key, |
||
91 | gettype($regexOrNamespaceName), |
||
92 | $index, |
||
93 | ), |
||
94 | ); |
||
95 | } |
||
96 | |||
97 | if (!$this->regexChecker->isRegexLike($regexOrNamespaceName)) { |
||
98 | $namespaceNames[$regexOrNamespaceName] = null; |
||
99 | |||
100 | continue; |
||
101 | } |
||
102 | |||
103 | $excludeNamespaceRegex = $regexOrNamespaceName; |
||
104 | |||
105 | $errorMessage = $this->regexChecker->validateRegex($excludeNamespaceRegex); |
||
106 | |||
107 | if (null !== $errorMessage) { |
||
108 | throw new InvalidArgumentException( |
||
109 | sprintf( |
||
110 | 'Expected "%s" to be an array of valid regexes. The element "%s" with the index "%s" is not: %s.', |
||
111 | $key, |
||
112 | $excludeNamespaceRegex, |
||
113 | $index, |
||
114 | $errorMessage, |
||
115 | ), |
||
116 | ); |
||
117 | } |
||
118 | |||
119 | // Ensure namespace comparisons are always case-insensitive |
||
120 | $excludeNamespaceRegex .= 'i'; |
||
121 | $regexes[$excludeNamespaceRegex] = null; |
||
122 | } |
||
123 | |||
124 | return [ |
||
125 | array_keys($regexes), |
||
126 | array_keys($namespaceNames), |
||
127 | ]; |
||
190 |