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