Completed
Push — master ( 1e4134...246601 )
by Christian
02:12 queued 11s
created

Configuration   A

Complexity

Total Complexity 25

Size/Duplication

Total Lines 480
Duplicated Lines 4.58 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 93%

Importance

Changes 0
Metric Value
wmc 25
lcom 1
cbo 4
dl 22
loc 480
ccs 372
cts 400
cp 0.93
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B getConfigTreeBuilder() 11 165 4
B addViewSection() 11 85 3
A addBodyListenerSection() 0 40 2
A addFormatListenerSection() 0 53 3
A addVersioningSection() 0 49 3
B addExceptionSection() 0 66 6
A testExceptionExists() 0 6 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * This file is part of the FOSRestBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\RestBundle\DependencyInjection;
13
14
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
15
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
16
use Symfony\Component\Config\Definition\ConfigurationInterface;
17
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
18
use Symfony\Component\HttpFoundation\Response;
19
use Symfony\Component\OptionsResolver\OptionsResolver;
20
use Symfony\Component\Serializer\Encoder\XmlEncoder;
21
22
/**
23
 * This class contains the configuration information for the bundle.
24
 *
25
 * This information is solely responsible for how the different configuration
26
 * sections are normalized, and merged.
27
 *
28
 * @author Lukas Kahwe Smith <[email protected]>
29
 *
30
 * @internal
31
 */
32
final class Configuration implements ConfigurationInterface
33
{
34
    private $debug;
35
36 19
    public function __construct(bool $debug)
37
    {
38 19
        $this->debug = $debug;
39 19
    }
40
41 18
    public function getConfigTreeBuilder(): TreeBuilder
42
    {
43 18
        $treeBuilder = new TreeBuilder('fos_rest');
44
45 18
        $rootNode = $treeBuilder->getRootNode();
46
47
        $rootNode
48 18
            ->children()
49 18
                ->scalarNode('disable_csrf_role')->defaultNull()->end()
50 18
                ->arrayNode('access_denied_listener')
51 18
                    ->canBeEnabled()
52 18
                    ->beforeNormalization()
53 View Code Duplication
                        ->ifArray()->then(function ($v) {
54
                            if (!empty($v) && empty($v['formats'])) {
55
                                unset($v['enabled']);
56
                                $v = ['enabled' => true, 'formats' => $v];
57
                            }
58
59
                            return $v;
60 18
                        })
61 18
                    ->end()
62 18
                    ->fixXmlConfig('format', 'formats')
63 18
                    ->children()
64 18
                        ->scalarNode('service')->defaultNull()->end()
65 18
                        ->arrayNode('formats')
66 18
                            ->useAttributeAsKey('name')
67 18
                            ->prototype('boolean')->end()
68 18
                        ->end()
69 18
                    ->end()
70 18
                ->end()
71 18
                ->scalarNode('unauthorized_challenge')->defaultNull()->end()
72 18
                ->arrayNode('param_fetcher_listener')
73 18
                    ->beforeNormalization()
74 18
                        ->ifString()
75 View Code Duplication
                        ->then(function ($v) {
76
                            return ['enabled' => in_array($v, ['force', 'true']), 'force' => 'force' === $v];
77 18
                        })
78 18
                    ->end()
79 18
                    ->canBeEnabled()
80 18
                    ->children()
81 18
                        ->booleanNode('force')->defaultFalse()->end()
82 18
                        ->scalarNode('service')->defaultNull()->end()
83 18
                    ->end()
84 18
                ->end()
85 18
                ->scalarNode('cache_dir')->cannotBeEmpty()->defaultValue('%kernel.cache_dir%/fos_rest')->end()
86 18
                ->arrayNode('allowed_methods_listener')
87 18
                    ->canBeEnabled()
88 18
                    ->children()
89 18
                        ->scalarNode('service')->defaultNull()->end()
90 18
                    ->end()
91 18
                ->end()
92 18
                ->arrayNode('routing_loader')
93 18
                    ->addDefaultsIfNotSet()
94 18
                    ->canBeDisabled()
95 18
                    ->beforeNormalization()
96
                        ->ifTrue(function ($v) { return false !== $v; })
97
                        ->then(function ($v) {
98
                            @trigger_error('Enabling the route generation feature is deprecated since FOSRestBundle 2.8.', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
99
100
                            return $v;
101 18
                        })
102 18
                    ->end()
103 18
                    ->beforeNormalization()
104
                        ->ifTrue(function ($v) { return is_bool($v); })
105
                        ->then(function ($v) {
106
                            return [
107
                                'enabled' => $v,
108
                            ];
109 18
                        })
110 18
                    ->end()
111 18
                    ->children()
112 18
                        ->scalarNode('default_format')->defaultNull()->end()
113 18
                        ->scalarNode('prefix_methods')->defaultTrue()->end()
114 18
                        ->scalarNode('include_format')->defaultTrue()->end()
115 18
                    ->end()
116 18
                ->end()
117 18
                ->arrayNode('body_converter')
118 18
                    ->canBeEnabled()
119 18
                    ->children()
120 18
                        ->scalarNode('validate')
121 18
                            ->defaultFalse()
122 18
                            ->beforeNormalization()
123 18
                                ->ifTrue()
124
                                ->then(function ($value) {
125
                                    if (!class_exists(OptionsResolver::class)) {
126
                                        throw new InvalidConfigurationException("'body_converter.validate: true' requires OptionsResolver component installation ( composer require symfony/options-resolver )");
127
                                    }
128
129
                                    return $value;
130 18
                                })
131 18
                            ->end()
132 18
                        ->end()
133 18
                        ->scalarNode('validation_errors_argument')->defaultValue('validationErrors')->end()
134 18
                    ->end()
135 18
                ->end()
136 18
                ->arrayNode('service')
137 18
                    ->addDefaultsIfNotSet()
138 18
                    ->children()
139 18
                        ->scalarNode('router')->defaultValue('router')->end()
140 18
                        ->scalarNode('templating')
141 18
                            ->defaultNull()
142 18
                            ->validate()
143 18
                                ->ifString()
144 18
                                ->thenInvalid('only null is supported')
145 18
                            ->end()
146 18
                        ->end()
147 18
                        ->scalarNode('serializer')->defaultNull()->end()
148 18
                        ->scalarNode('view_handler')->defaultValue('fos_rest.view_handler.default')->end()
149 18
                        ->scalarNode('inflector')
150
                            ->defaultValue(static function () {
151
                                @trigger_error('Not setting the "fos_rest.service.inflector" configuration option to "null" is deprecated since FOSRestBundle 2.8.', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
152
153
                                return 'fos_rest.inflector.doctrine';
154 18
                            })
155 18
                            ->defaultValue('fos_rest.inflector.doctrine')
156 18
                        ->end()
157 18
                        ->scalarNode('validator')->defaultValue('validator')->end()
158 18
                    ->end()
159 18
                ->end()
160 18
                ->arrayNode('serializer')
161 18
                    ->addDefaultsIfNotSet()
162 18
                    ->children()
163 18
                        ->scalarNode('version')->defaultNull()->end()
164 18
                        ->arrayNode('groups')
165 18
                            ->prototype('scalar')->end()
166 18
                        ->end()
167 18
                        ->booleanNode('serialize_null')->defaultFalse()->end()
168 18
                    ->end()
169 18
                ->end()
170 18
                ->arrayNode('zone')
171 18
                    ->cannotBeOverwritten()
172 18
                    ->prototype('array')
173 18
                    ->fixXmlConfig('ip')
174 18
                    ->children()
175 18
                        ->scalarNode('path')
176 18
                            ->defaultNull()
177 18
                            ->info('use the urldecoded format')
178 18
                            ->example('^/path to resource/')
179 18
                        ->end()
180 18
                        ->scalarNode('host')->defaultNull()->end()
181 18
                        ->arrayNode('methods')
182
                            ->beforeNormalization()->ifString()->then(function ($v) {
183
                                return preg_split('/\s*,\s*/', $v);
184 18
                            })->end()
185 18
                            ->prototype('scalar')->end()
186 18
                        ->end()
187 18
                        ->arrayNode('ips')
188
                            ->beforeNormalization()->ifString()->then(function ($v) {
189
                                return array($v);
190 18
                            })->end()
191 18
                            ->prototype('scalar')->end()
192 18
                        ->end()
193 18
                    ->end()
194 18
                ->end()
195 18
            ->end()
196 18
        ->end();
197
198 18
        $this->addViewSection($rootNode);
0 ignored issues
show
Compatibility introduced by
$rootNode of type object<Symfony\Component...Builder\NodeDefinition> is not a sub-type of object<Symfony\Component...er\ArrayNodeDefinition>. It seems like you assume a child class of the class Symfony\Component\Config...\Builder\NodeDefinition to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
199 18
        $this->addExceptionSection($rootNode);
0 ignored issues
show
Compatibility introduced by
$rootNode of type object<Symfony\Component...Builder\NodeDefinition> is not a sub-type of object<Symfony\Component...er\ArrayNodeDefinition>. It seems like you assume a child class of the class Symfony\Component\Config...\Builder\NodeDefinition to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
200 18
        $this->addBodyListenerSection($rootNode);
0 ignored issues
show
Compatibility introduced by
$rootNode of type object<Symfony\Component...Builder\NodeDefinition> is not a sub-type of object<Symfony\Component...er\ArrayNodeDefinition>. It seems like you assume a child class of the class Symfony\Component\Config...\Builder\NodeDefinition to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
201 18
        $this->addFormatListenerSection($rootNode);
0 ignored issues
show
Compatibility introduced by
$rootNode of type object<Symfony\Component...Builder\NodeDefinition> is not a sub-type of object<Symfony\Component...er\ArrayNodeDefinition>. It seems like you assume a child class of the class Symfony\Component\Config...\Builder\NodeDefinition to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
202 18
        $this->addVersioningSection($rootNode);
0 ignored issues
show
Compatibility introduced by
$rootNode of type object<Symfony\Component...Builder\NodeDefinition> is not a sub-type of object<Symfony\Component...er\ArrayNodeDefinition>. It seems like you assume a child class of the class Symfony\Component\Config...\Builder\NodeDefinition to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
203
204 18
        return $treeBuilder;
205
    }
206
207 18
    private function addViewSection(ArrayNodeDefinition $rootNode): void
208
    {
209
        $rootNode
210 18
            ->children()
211 18
                ->arrayNode('view')
212 18
                    ->fixXmlConfig('format', 'formats')
213 18
                    ->fixXmlConfig('mime_type', 'mime_types')
214 18
                    ->fixXmlConfig('force_redirect', 'force_redirects')
215 18
                    ->addDefaultsIfNotSet()
216 18
                    ->children()
217 18
                        ->scalarNode('default_engine')
218 18
                            ->defaultNull()
219 18
                            ->validate()
220 18
                                ->ifString()
221 18
                                ->thenInvalid('only null is supported')
222 18
                            ->end()
223 18
                        ->end()
224 18
                        ->arrayNode('force_redirects')
225 18
                            ->useAttributeAsKey('name')
226 18
                            ->defaultValue([])
227 18
                            ->validate()
228
                                ->ifTrue(function ($v) { return [] !== $v; })
229 18
                                ->thenInvalid('only the empty array is supported')
230 18
                            ->end()
231 18
                            ->prototype('boolean')->end()
232 18
                        ->end()
233 18
                        ->arrayNode('mime_types')
234 18
                            ->canBeEnabled()
235 18
                            ->beforeNormalization()
236 View Code Duplication
                                ->ifArray()->then(function ($v) {
237
                                    if (!empty($v) && empty($v['formats'])) {
238
                                        unset($v['enabled']);
239
                                        $v = ['enabled' => true, 'formats' => $v];
240
                                    }
241
242
                                    return $v;
243 18
                                })
244 18
                            ->end()
245 18
                            ->fixXmlConfig('format', 'formats')
246 18
                            ->children()
247 18
                                ->scalarNode('service')->defaultNull()->end()
248 18
                                ->arrayNode('formats')
249 18
                                    ->useAttributeAsKey('name')
250 18
                                    ->prototype('array')
251 18
                                        ->beforeNormalization()
252 18
                                            ->ifString()
253
                                            ->then(function ($v) { return array($v); })
254 18
                                        ->end()
255 18
                                        ->prototype('scalar')->end()
256 18
                                    ->end()
257 18
                                ->end()
258 18
                            ->end()
259 18
                        ->end()
260 18
                        ->arrayNode('formats')
261 18
                            ->useAttributeAsKey('name')
262 18
                            ->defaultValue(['json' => true, 'xml' => true])
263 18
                            ->prototype('boolean')->end()
264 18
                        ->end()
265 18
                        ->arrayNode('view_response_listener')
266 18
                            ->beforeNormalization()
267 18
                                ->ifString()
268 View Code Duplication
                                ->then(function ($v) {
269
                                    return ['enabled' => in_array($v, ['force', 'true']), 'force' => 'force' === $v];
270 18
                                })
271 18
                            ->end()
272 18
                            ->canBeEnabled()
273 18
                            ->children()
274 18
                                ->booleanNode('force')->defaultFalse()->end()
275 18
                                ->scalarNode('service')->defaultNull()->end()
276 18
                            ->end()
277 18
                        ->end()
278 18
                        ->scalarNode('failed_validation')->defaultValue(Response::HTTP_BAD_REQUEST)->end()
279 18
                        ->scalarNode('empty_content')->defaultValue(Response::HTTP_NO_CONTENT)->end()
280 18
                        ->booleanNode('serialize_null')->defaultFalse()->end()
281 18
                        ->arrayNode('jsonp_handler')
282 18
                            ->canBeUnset()
283 18
                            ->children()
284 18
                                ->scalarNode('callback_param')->defaultValue('callback')->end()
285 18
                                ->scalarNode('mime_type')->defaultValue('application/javascript+jsonp')->end()
286 18
                            ->end()
287 18
                        ->end()
288 18
                    ->end()
289 18
                ->end()
290 18
            ->end();
291 18
    }
292
293 18
    private function addBodyListenerSection(ArrayNodeDefinition $rootNode): void
294
    {
295 18
        $decodersDefaultValue = ['json' => 'fos_rest.decoder.json'];
296 18
        if (class_exists(XmlEncoder::class)) {
297 18
            $decodersDefaultValue['xml'] = 'fos_rest.decoder.xml';
298
        }
299
        $rootNode
300 18
            ->children()
301 18
                ->arrayNode('body_listener')
302 18
                    ->fixXmlConfig('decoder', 'decoders')
303 18
                    ->addDefaultsIfNotSet()
304 18
                    ->canBeUnset()
305 18
                    ->canBeDisabled()
306 18
                    ->children()
307 18
                        ->scalarNode('service')->defaultNull()->end()
308 18
                        ->scalarNode('default_format')->defaultNull()->end()
309 18
                        ->booleanNode('throw_exception_on_unsupported_content_type')
310 18
                            ->defaultFalse()
311 18
                        ->end()
312 18
                        ->arrayNode('decoders')
313 18
                            ->useAttributeAsKey('name')
314 18
                            ->defaultValue($decodersDefaultValue)
315 18
                            ->prototype('scalar')->end()
316 18
                        ->end()
317 18
                        ->arrayNode('array_normalizer')
318 18
                            ->addDefaultsIfNotSet()
319 18
                            ->beforeNormalization()
320
                                ->ifString()->then(function ($v) {
321
                                    return ['service' => $v];
322 18
                                })
323 18
                            ->end()
324 18
                            ->children()
325 18
                                ->scalarNode('service')->defaultNull()->end()
326 18
                                ->booleanNode('forms')->defaultFalse()->end()
327 18
                            ->end()
328 18
                        ->end()
329 18
                    ->end()
330 18
                ->end()
331 18
            ->end();
332 18
    }
333
334 18
    private function addFormatListenerSection(ArrayNodeDefinition $rootNode): void
335
    {
336
        $rootNode
337 18
            ->children()
338 18
                ->arrayNode('format_listener')
339 18
                    ->fixXmlConfig('rule', 'rules')
340 18
                    ->addDefaultsIfNotSet()
341 18
                    ->canBeUnset()
342 18
                    ->beforeNormalization()
343
                        ->ifTrue(function ($v) {
344
                            // check if we got an assoc array in rules
345 2
                            return isset($v['rules'])
346 2
                                && is_array($v['rules'])
347 2
                                && array_keys($v['rules']) !== range(0, count($v['rules']) - 1);
348 18
                        })
349
                        ->then(function ($v) {
350
                            $v['rules'] = [$v['rules']];
351
352
                            return $v;
353 18
                        })
354 18
                    ->end()
355 18
                    ->canBeEnabled()
356 18
                    ->children()
357 18
                        ->scalarNode('service')->defaultNull()->end()
358 18
                        ->arrayNode('rules')
359 18
                            ->performNoDeepMerging()
360 18
                            ->prototype('array')
361 18
                                ->fixXmlConfig('priority', 'priorities')
362 18
                                ->fixXmlConfig('attribute', 'attributes')
363 18
                                ->children()
364 18
                                    ->scalarNode('path')->defaultNull()->info('URL path info')->end()
365 18
                                    ->scalarNode('host')->defaultNull()->info('URL host name')->end()
366 18
                                    ->variableNode('methods')->defaultNull()->info('Method for URL')->end()
367 18
                                    ->arrayNode('attributes')
368 18
                                        ->useAttributeAsKey('name')
369 18
                                        ->prototype('variable')->end()
370 18
                                    ->end()
371 18
                                    ->booleanNode('stop')->defaultFalse()->end()
372 18
                                    ->booleanNode('prefer_extension')->defaultTrue()->end()
373 18
                                    ->scalarNode('fallback_format')->defaultValue('html')->end()
374 18
                                    ->arrayNode('priorities')
375
                                        ->beforeNormalization()->ifString()->then(function ($v) {
376
                                            return preg_split('/\s*,\s*/', $v);
377 18
                                        })->end()
378 18
                                        ->prototype('scalar')->end()
379 18
                                    ->end()
380 18
                                ->end()
381 18
                            ->end()
382 18
                        ->end()
383 18
                    ->end()
384 18
                ->end()
385 18
            ->end();
386 18
    }
387
388 18
    private function addVersioningSection(ArrayNodeDefinition $rootNode): void
389
    {
390
        $rootNode
391 18
        ->children()
392 18
            ->arrayNode('versioning')
393 18
                ->canBeEnabled()
394 18
                ->children()
395 18
                    ->scalarNode('default_version')->defaultNull()->end()
396 18
                    ->arrayNode('resolvers')
397 18
                        ->addDefaultsIfNotSet()
398 18
                        ->children()
399 18
                            ->arrayNode('query')
400 18
                                ->canBeDisabled()
401 18
                                ->children()
402 18
                                    ->scalarNode('parameter_name')->defaultValue('version')->end()
403 18
                                ->end()
404 18
                            ->end()
405 18
                            ->arrayNode('custom_header')
406 18
                                ->canBeDisabled()
407 18
                                ->children()
408 18
                                    ->scalarNode('header_name')->defaultValue('X-Accept-Version')->end()
409 18
                                ->end()
410 18
                            ->end()
411 18
                            ->arrayNode('media_type')
412 18
                                ->canBeDisabled()
413 18
                                ->children()
414 18
                                    ->scalarNode('regex')->defaultValue('/(v|version)=(?P<version>[0-9\.]+)/')->end()
415 18
                                ->end()
416 18
                            ->end()
417 18
                        ->end()
418 18
                    ->end()
419 18
                    ->arrayNode('guessing_order')
420 18
                        ->defaultValue(['query', 'custom_header', 'media_type'])
421 18
                        ->validate()
422
                            ->ifTrue(function ($v) {
423
                                foreach ($v as $resolver) {
424
                                    if (!in_array($resolver, ['query', 'custom_header', 'media_type'])) {
425
                                        return true;
426
                                    }
427
                                }
428 18
                            })
429 18
                            ->thenInvalid('Versioning guessing order can only contain "query", "custom_header", "media_type".')
430 18
                        ->end()
431 18
                        ->prototype('scalar')->end()
432 18
                    ->end()
433 18
                ->end()
434 18
            ->end()
435 18
        ->end();
436 18
    }
437
438 18
    private function addExceptionSection(ArrayNodeDefinition $rootNode): void
439
    {
440
        $rootNode
441 18
            ->children()
442 18
                ->arrayNode('exception')
443 18
                    ->fixXmlConfig('code', 'codes')
444 18
                    ->fixXmlConfig('message', 'messages')
445 18
                    ->addDefaultsIfNotSet()
446 18
                    ->canBeEnabled()
447 18
                    ->children()
448 18
                        ->scalarNode('exception_controller')->defaultValue('fos_rest.exception.controller::showAction')->end()
449 18
                        ->scalarNode('service')->defaultNull()->end()
450 18
                        ->arrayNode('codes')
451 18
                            ->useAttributeAsKey('name')
452 18
                            ->beforeNormalization()
453 18
                                ->ifArray()
454
                                ->then(function (array $items) {
455 12
                                    foreach ($items as &$item) {
456 12
                                        if (is_int($item)) {
457 2
                                            continue;
458
                                        }
459
460 10
                                        if (!defined(sprintf('%s::%s', Response::class, $item))) {
461 9
                                            throw new InvalidConfigurationException(sprintf('Invalid HTTP code in fos_rest.exception.codes, see %s for all valid codes.', Response::class));
462
                                        }
463
464 1
                                        $item = constant(sprintf('%s::%s', Response::class, $item));
465
                                    }
466
467 3
                                    return $items;
468 18
                                })
469 18
                            ->end()
470 18
                            ->prototype('integer')->end()
471
472 18
                            ->validate()
473 18
                            ->ifArray()
474
                                ->then(function (array $items) {
475 3
                                    foreach ($items as $class => $code) {
476 3
                                        $this->testExceptionExists($class);
477
                                    }
478
479 2
                                    return $items;
480 18
                                })
481 18
                            ->end()
482 18
                        ->end()
483 18
                        ->arrayNode('messages')
484 18
                            ->useAttributeAsKey('name')
485 18
                            ->prototype('boolean')->end()
486 18
                            ->validate()
487 18
                                ->ifArray()
488
                                ->then(function (array $items) {
489 1
                                    foreach ($items as $class => $nomatter) {
490 1
                                        $this->testExceptionExists($class);
491
                                    }
492
493
                                    return $items;
494 18
                                })
495 18
                            ->end()
496 18
                        ->end()
497 18
                        ->booleanNode('debug')
498 18
                            ->defaultValue($this->debug)
499 18
                        ->end()
500 18
                    ->end()
501 18
                ->end()
502 18
            ->end();
503 18
    }
504
505 4
    private function testExceptionExists(string $exception): void
506
    {
507 4
        if (!is_subclass_of($exception, \Exception::class) && !is_a($exception, \Exception::class, true)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Exception::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
508 2
            throw new InvalidConfigurationException(sprintf('FOSRestBundle exception mapper: Could not load class "%s" or the class does not extend from "%s". Most probably this is a configuration problem.', $exception, \Exception::class));
509
        }
510 2
    }
511
}
512