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