Code Duplication    Length = 32-33 lines in 3 locations

src/Console/Configuration.php 3 locations

@@ 192-223 (lines=32) @@
189
        return $finders;
190
    }
191
192
    private static function retrievePatchers(array $config): array
193
    {
194
        if (false === array_key_exists(self::PATCHERS_KEYWORD, $config)) {
195
            return [];
196
        }
197
198
        $patchers = $config[self::PATCHERS_KEYWORD];
199
200
        if (false === is_array($patchers)) {
201
            throw new InvalidArgumentException(
202
                sprintf(
203
                    'Expected patchers to be an array of callables, found "%s" instead.',
204
                    gettype($patchers)
205
                )
206
            );
207
        }
208
209
        foreach ($patchers as $index => $patcher) {
210
            if (is_callable($patcher)) {
211
                continue;
212
            }
213
214
            throw new InvalidArgumentException(
215
                sprintf(
216
                    'Expected patchers to be an array of callables, the "%d" element is not.',
217
                    $index
218
                )
219
            );
220
        }
221
222
        return $patchers;
223
    }
224
225
    private static function retrieveWhitelist(array $config): array
226
    {
@@ 225-256 (lines=32) @@
222
        return $patchers;
223
    }
224
225
    private static function retrieveWhitelist(array $config): array
226
    {
227
        if (false === array_key_exists(self::WHITELIST_KEYWORD, $config)) {
228
            return [];
229
        }
230
231
        $whitelist = $config[self::WHITELIST_KEYWORD];
232
233
        if (false === is_array($whitelist)) {
234
            throw new InvalidArgumentException(
235
                sprintf(
236
                    'Expected whitelist to be an array of strings, found "%s" instead.',
237
                    gettype($whitelist)
238
                )
239
            );
240
        }
241
242
        foreach ($whitelist as $index => $className) {
243
            if (is_string($className)) {
244
                continue;
245
            }
246
247
            throw new InvalidArgumentException(
248
                sprintf(
249
                    'Expected whitelist to be an array of string, the "%d" element is not.',
250
                    $index
251
                )
252
            );
253
        }
254
255
        return $whitelist;
256
    }
257
258
    private static function retrieveGlobalNamespaceWhitelisters(array $config): array
259
    {
@@ 258-290 (lines=33) @@
255
        return $whitelist;
256
    }
257
258
    private static function retrieveGlobalNamespaceWhitelisters(array $config): array
259
    {
260
        if (false === array_key_exists(self::GLOBAL_NAMESPACE_KEYWORD, $config)) {
261
            return [];
262
        }
263
264
        $globalNamespace = $config[self::GLOBAL_NAMESPACE_KEYWORD];
265
266
        if (false === is_array($globalNamespace)) {
267
            throw new InvalidArgumentException(
268
                sprintf(
269
                    'Expected "global_namespace" to be an array, found "%s" instead.',
270
                    gettype($globalNamespace)
271
                )
272
            );
273
        }
274
275
        foreach ($globalNamespace as $index => $className) {
276
            if (is_string($className) || is_callable($className)) {
277
                continue;
278
            }
279
280
            throw new InvalidArgumentException(
281
                sprintf(
282
                    'Expected "global_namespace" to be an array of callables or strings, the "%d" element '
283
                    .'is not.',
284
                    $index
285
                )
286
            );
287
        }
288
289
        return $globalNamespace;
290
    }
291
}
292