Completed
Push — master ( 0206c4...e90e98 )
by Guilh
9s
created

FOSRestExtension::loadBodyConverter()   B

Complexity

Conditions 5
Paths 7

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5.0113
Metric Value
dl 0
loc 18
ccs 12
cts 13
cp 0.9231
rs 8.8571
cc 5
eloc 9
nc 7
nop 4
crap 5.0113
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\FileLocator;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\DefinitionDecorator;
17
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
18
use Symfony\Component\DependencyInjection\Reference;
19
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
20
use Symfony\Component\HttpFoundation\Request;
21
use Symfony\Component\HttpFoundation\Response;
22
23
class FOSRestExtension extends Extension
24
{
25
    /**
26
     * Loads the services based on your application configuration.
27
     *
28
     * @param array            $configs
29
     * @param ContainerBuilder $container
30
     *
31
     * @throws \InvalidArgumentException
32
     * @throws \LogicException
33
     */
34 47
    public function load(array $configs, ContainerBuilder $container)
35
    {
36 47
        $config = $this->processConfiguration(new Configuration(), $configs);
37
38 42
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
39 42
        $loader->load('view.xml');
40 42
        $loader->load('routing.xml');
41 42
        $loader->load('request.xml');
42 42
        $loader->load('serializer.xml');
43
44 42
        $container->getDefinition('fos_rest.routing.loader.controller')->replaceArgument(4, $config['routing_loader']['default_format']);
45 42
        $container->getDefinition('fos_rest.routing.loader.yaml_collection')->replaceArgument(4, $config['routing_loader']['default_format']);
46 42
        $container->getDefinition('fos_rest.routing.loader.xml_collection')->replaceArgument(4, $config['routing_loader']['default_format']);
47
48 42
        $container->getDefinition('fos_rest.routing.loader.yaml_collection')->replaceArgument(2, $config['routing_loader']['include_format']);
49 42
        $container->getDefinition('fos_rest.routing.loader.xml_collection')->replaceArgument(2, $config['routing_loader']['include_format']);
50 42
        $container->getDefinition('fos_rest.routing.loader.reader.action')->replaceArgument(3, $config['routing_loader']['include_format']);
51
52
        // The validator service alias is only set if validation is enabled for the request body converter
53 42
        $validator = $config['service']['validator'];
54 42
        unset($config['service']['validator']);
55
56 42
        foreach ($config['service'] as $key => $service) {
57 42
            if (null !== $service) {
58 42
                $container->setAlias('fos_rest.'.$key, $service);
59 42
            }
60 42
        }
61
62 42
        $this->loadForm($config, $loader, $container);
63 42
        $this->loadException($config, $loader, $container);
64 40
        $this->loadBodyConverter($config, $validator, $loader, $container);
65 40
        $this->loadView($config, $loader, $container);
66
67 40
        $this->loadBodyListener($config, $loader, $container);
68 40
        $this->loadFormatListener($config, $loader, $container);
69 40
        $this->loadVersioning($config, $loader, $container);
70 40
        $this->loadParamFetcherListener($config, $loader, $container);
71 40
        $this->loadAllowedMethodsListener($config, $loader, $container);
72 40
        $this->loadAccessDeniedListener($config, $loader, $container);
73 40
        $this->loadZoneMatcherListener($config, $loader, $container);
74
75
        // Needs RequestBodyParamConverter and View Handler loaded.
76 40
        $this->loadSerializer($config, $container);
77 40
    }
78
79 42
    private function loadForm(array $config, XmlFileLoader $loader, ContainerBuilder $container)
80
    {
81 42
        if (!empty($config['disable_csrf_role'])) {
82 1
            $loader->load('forms.xml');
83 1
            $container->getDefinition('fos_rest.form.extension.csrf_disable')->replaceArgument(1, $config['disable_csrf_role']);
84 1
        }
85 42
    }
86
87 40
    private function loadAccessDeniedListener(array $config, XmlFileLoader $loader, ContainerBuilder $container)
88
    {
89 40
        if ($config['access_denied_listener']['enabled'] && !empty($config['access_denied_listener']['formats'])) {
90
            $loader->load('access_denied_listener.xml');
91
92
            $service = $container->getDefinition('fos_rest.access_denied_listener');
93
94
            if (!empty($config['access_denied_listener']['service'])) {
95
                $service->clearTag('kernel.event_listener');
96
            }
97
98
            $service->replaceArgument(0, $config['access_denied_listener']['formats']);
99
            $service->replaceArgument(1, $config['unauthorized_challenge']);
100
        }
101 40
    }
102
103 40 View Code Duplication
    private function loadAllowedMethodsListener(array $config, XmlFileLoader $loader, ContainerBuilder $container)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
104
    {
105 40
        if ($config['allowed_methods_listener']['enabled']) {
106 1
            if (!empty($config['allowed_methods_listener']['service'])) {
107
                $service = $container->getDefinition('fos_rest.allowed_methods_listener');
108
                $service->clearTag('kernel.event_listener');
109
            }
110
111 1
            $loader->load('allowed_methods_listener.xml');
112
113 1
            $container->getDefinition('fos_rest.allowed_methods_loader')->replaceArgument(1, $config['cache_dir']);
114 1
        }
115 40
    }
116
117 40
    private function loadBodyListener(array $config, XmlFileLoader $loader, ContainerBuilder $container)
118
    {
119 40
        if ($config['body_listener']['enabled']) {
120 39
            $loader->load('body_listener.xml');
121
122 39
            $service = $container->getDefinition('fos_rest.body_listener');
123
124 39
            if (!empty($config['body_listener']['service'])) {
125
                $service->clearTag('kernel.event_listener');
126
            }
127
128 39
            $service->replaceArgument(1, $config['body_listener']['throw_exception_on_unsupported_content_type']);
129 39
            $service->addMethodCall('setDefaultFormat', array($config['body_listener']['default_format']));
130
131 39
            $container->getDefinition('fos_rest.decoder_provider')->replaceArgument(1, $config['body_listener']['decoders']);
132
133 39
            $arrayNormalizer = $config['body_listener']['array_normalizer'];
134
135 39
            if (null !== $arrayNormalizer['service']) {
136 3
                $bodyListener = $container->getDefinition('fos_rest.body_listener');
137 3
                $bodyListener->addArgument(new Reference($arrayNormalizer['service']));
138 3
                $bodyListener->addArgument($arrayNormalizer['forms']);
139 3
            }
140 39
        }
141 40
    }
142
143 40
    private function loadFormatListener(array $config, XmlFileLoader $loader, ContainerBuilder $container)
144
    {
145 40
        if ($config['format_listener']['enabled'] && !empty($config['format_listener']['rules'])) {
146 5
            $loader->load('format_listener.xml');
147
148 5
            if (!empty($config['format_listener']['service'])) {
149
                $service = $container->getDefinition('fos_rest.format_listener');
150
                $service->clearTag('kernel.event_listener');
151
            }
152
153 5
            foreach ($config['format_listener']['rules'] as &$rule) {
154 5
                if (!isset($rule['exception_fallback_format'])) {
155 5
                    $rule['exception_fallback_format'] = $rule['fallback_format'];
156 5
                }
157 5
            }
158
159 5
            $container->setParameter(
160 5
                'fos_rest.format_listener.rules',
161 5
                $config['format_listener']['rules']
162 5
            );
163
164 5 View Code Duplication
            if ($config['view']['mime_types']['enabled'] && !method_exists(Request::class, 'getMimeTypes')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
165 2
                $container->getDefinition('fos_rest.format_negotiator')->addArgument($config['view']['mime_types']['formats']);
166 2
            }
167 5
        }
168 40
    }
169
170 40
    private function loadVersioning(array $config, XmlFileLoader $loader, ContainerBuilder $container)
171
    {
172 40
        if (!empty($config['versioning']['enabled'])) {
173 2
            $loader->load('versioning.xml');
174
175 2
            $versionListener = $container->getDefinition('fos_rest.versioning.listener');
176 2
            $versionListener->replaceArgument(2, $config['versioning']['default_version']);
177
178 2
            $resolvers = [];
179 2 View Code Duplication
            if ($config['versioning']['resolvers']['query']['enabled']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
180 2
                $resolvers['query'] = $container->getDefinition('fos_rest.versioning.query_parameter_resolver');
181 2
                $resolvers['query']->replaceArgument(0, $config['versioning']['resolvers']['query']['parameter_name']);
182 2
            }
183 2 View Code Duplication
            if ($config['versioning']['resolvers']['custom_header']['enabled']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
184 2
                $resolvers['custom_header'] = $container->getDefinition('fos_rest.versioning.header_resolver');
185 2
                $resolvers['custom_header']->replaceArgument(0, $config['versioning']['resolvers']['custom_header']['header_name']);
186 2
            }
187 2 View Code Duplication
            if ($config['versioning']['resolvers']['media_type']['enabled']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
188 2
                $resolvers['media_type'] = $container->getDefinition('fos_rest.versioning.media_type_resolver');
189 2
                $resolvers['media_type']->replaceArgument(0, $config['versioning']['resolvers']['media_type']['regex']);
190 2
            }
191
192 2
            $chainResolver = $container->getDefinition('fos_rest.versioning.chain_resolver');
193 2
            foreach ($config['versioning']['guessing_order'] as $resolver) {
194 2
                if (isset($resolvers[$resolver])) {
195 2
                    $chainResolver->addMethodCall('addResolver', [$resolvers[$resolver]]);
196 2
                }
197 2
            }
198 2
        }
199 40
    }
200
201 40 View Code Duplication
    private function loadParamFetcherListener(array $config, XmlFileLoader $loader, ContainerBuilder $container)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
202
    {
203 40
        if ($config['param_fetcher_listener']['enabled']) {
204 4
            $loader->load('param_fetcher_listener.xml');
205
206 4
            if (!empty($config['param_fetcher_listener']['service'])) {
207
                $service = $container->getDefinition('fos_rest.param_fetcher_listener');
208
                $service->clearTag('kernel.event_listener');
209
            }
210
211 4
            if ($config['param_fetcher_listener']['force']) {
212 1
                $container->getDefinition('fos_rest.param_fetcher_listener')->replaceArgument(1, true);
213 1
            }
214 4
        }
215 40
    }
216
217 40
    private function loadBodyConverter(array $config, $validator, XmlFileLoader $loader, ContainerBuilder $container)
218
    {
219 40
        if (empty($config['body_converter'])) {
220
            return;
221
        }
222
223 40
        if (!empty($config['body_converter']['enabled'])) {
224 2
            $loader->load('request_body_param_converter.xml');
225
226 2
            if (!empty($config['body_converter']['validation_errors_argument'])) {
227 2
                $container->getDefinition('fos_rest.converter.request_body')->replaceArgument(4, $config['body_converter']['validation_errors_argument']);
228 2
            }
229 2
        }
230
231 40
        if (!empty($config['body_converter']['validate'])) {
232 2
            $container->setAlias('fos_rest.validator', $validator);
233 2
        }
234 40
    }
235
236 40
    private function loadView(array $config, XmlFileLoader $loader, ContainerBuilder $container)
237
    {
238 40
        if (!empty($config['view']['exception_wrapper_handler'])) {
239
            $container->setAlias('fos_rest.view.exception_wrapper_handler', $config['view']['exception_wrapper_handler']);
240
        }
241
242 40
        if (!empty($config['view']['jsonp_handler'])) {
243 1
            $handler = new DefinitionDecorator($config['service']['view_handler']);
244 1
            $handler->setPublic(true);
245
246 1
            $jsonpHandler = new Reference('fos_rest.view_handler.jsonp');
247 1
            $handler->addMethodCall('registerHandler', ['jsonp', [$jsonpHandler, 'createResponse']]);
248 1
            $container->setDefinition('fos_rest.view_handler', $handler);
249
250 1
            $container->getDefinition('fos_rest.view_handler.jsonp')->replaceArgument(0, $config['view']['jsonp_handler']['callback_param']);
251
252 1
            if (empty($config['view']['mime_types']['jsonp'])) {
253 1
                $config['view']['mime_types']['jsonp'] = $config['view']['jsonp_handler']['mime_type'];
254 1
            }
255 1
        }
256
257 40 View Code Duplication
        if ($config['view']['mime_types']['enabled']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
258 2
            $loader->load('mime_type_listener.xml');
259
260 2
            if (!empty($config['mime_type_listener']['service'])) {
261
                $service = $container->getDefinition('fos_rest.mime_type_listener');
262
                $service->clearTag('kernel.event_listener');
263
            }
264
265 2
            $container->getDefinition('fos_rest.mime_type_listener')->replaceArgument(0, $config['view']['mime_types']['formats']);
266 2
        }
267
268 40 View Code Duplication
        if ($config['view']['view_response_listener']['enabled']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
269 6
            $loader->load('view_response_listener.xml');
270 6
            $service = $container->getDefinition('fos_rest.view_response_listener');
271
272 6
            if (!empty($config['view_response_listener']['service'])) {
273
                $service->clearTag('kernel.event_listener');
274
            }
275
276 6
            $service->replaceArgument(1, $config['view']['view_response_listener']['force']);
277 6
        }
278
279 40
        $formats = [];
280 40 View Code Duplication
        foreach ($config['view']['formats'] as $format => $enabled) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
281 40
            if ($enabled) {
282 40
                $formats[$format] = false;
283 40
            }
284 40
        }
285 40 View Code Duplication
        foreach ($config['view']['templating_formats'] as $format => $enabled) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
286 40
            if ($enabled) {
287 40
                $formats[$format] = true;
288 40
            }
289 40
        }
290
291 40
        $container->getDefinition('fos_rest.routing.loader.yaml_collection')->replaceArgument(3, $formats);
292 40
        $container->getDefinition('fos_rest.routing.loader.xml_collection')->replaceArgument(3, $formats);
293 40
        $container->getDefinition('fos_rest.routing.loader.reader.action')->replaceArgument(4, $formats);
294
295 40
        foreach ($config['view']['force_redirects'] as $format => $code) {
296 40
            if (true === $code) {
297 40
                $config['view']['force_redirects'][$format] = Response::HTTP_FOUND;
298 40
            }
299 40
        }
300
301 40 View Code Duplication
        if (!is_numeric($config['view']['failed_validation'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
302
            $config['view']['failed_validation'] = constant('\Symfony\Component\HttpFoundation\Response::'.$config['view']['failed_validation']);
303
        }
304
305 40
        $defaultViewHandler = $container->getDefinition('fos_rest.view_handler.default');
306 40
        $defaultViewHandler->replaceArgument(5, $formats);
307 40
        $defaultViewHandler->replaceArgument(6, $config['view']['failed_validation']);
308
309 40 View Code Duplication
        if (!is_numeric($config['view']['empty_content'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
310
            $config['view']['empty_content'] = constant('\Symfony\Component\HttpFoundation\Response::'.$config['view']['empty_content']);
311
        }
312
313 40
        $defaultViewHandler->replaceArgument(7, $config['view']['empty_content']);
314 40
        $defaultViewHandler->replaceArgument(8, $config['view']['serialize_null']);
315 40
        $defaultViewHandler->replaceArgument(9, $config['view']['force_redirects']);
316 40
        $defaultViewHandler->replaceArgument(10, $config['view']['default_engine']);
317 40
    }
318
319 42
    private function loadException(array $config, XmlFileLoader $loader, ContainerBuilder $container)
320
    {
321 42
        if ($config['exception']['enabled']) {
322 6
            $loader->load('exception_listener.xml');
323
324 6
            if (!empty($config['exception']['service'])) {
325
                $service = $container->getDefinition('fos_rest.exception_listener');
326
                $service->clearTag('kernel.event_listener');
327
            }
328
329 6
            if ($config['exception']['exception_controller']) {
330
                $container->getDefinition('fos_rest.exception_listener')->replaceArgument(0, $config['exception']['exception_controller']);
331 6
            } elseif (isset($container->getParameter('kernel.bundles')['TwigBundle'])) {
332 1
                $container->getDefinition('fos_rest.exception_listener')->replaceArgument(0, 'fos_rest.exception.twig_controller:showAction');
333 1
            }
334
335 6 View Code Duplication
            if ($config['view']['mime_types']['enabled'] && !method_exists(Request::class, 'getMimeTypes')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
336 1
                $container->getDefinition('fos_rest.exception_format_negotiator')->addArgument($config['view']['mime_types']['formats']);
337 1
            }
338
339 6
            $exceptionController = $container->getDefinition('fos_rest.exception.controller');
340 6
            $exceptionController->replaceArgument(3, $config['exception']['codes']);
341 6
            $exceptionController->replaceArgument(4, $config['exception']['messages']);
342 6
        }
343
344 42
        foreach ($config['exception']['codes'] as $exception => $code) {
345 2
            if (!is_numeric($code)) {
346
                $config['exception']['codes'][$exception] = constant("\Symfony\Component\HttpFoundation\Response::$code");
347
            }
348
349 2
            $this->testExceptionExists($exception);
350 41
        }
351
352 41
        foreach ($config['exception']['messages'] as $exception => $message) {
353 3
            $this->testExceptionExists($exception);
354 40
        }
355 40
    }
356
357 40
    private function loadSerializer(array $config, ContainerBuilder $container)
358
    {
359 40
        $bodyConverter = $container->hasDefinition('fos_rest.converter.request_body') ? $container->getDefinition('fos_rest.converter.request_body') : null;
360 40
        $viewHandler = $container->getDefinition('fos_rest.view_handler.default');
361
362 40 View Code Duplication
        if (!empty($config['serializer']['version'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
363 1
            if ($bodyConverter) {
364
                $bodyConverter->replaceArgument(2, $config['serializer']['version']);
365
            }
366 1
            $viewHandler->addMethodCall('setExclusionStrategyVersion', array($config['serializer']['version']));
367 1
        }
368
369 40 View Code Duplication
        if (!empty($config['serializer']['groups'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
370 1
            if ($bodyConverter) {
371
                $bodyConverter->replaceArgument(1, $config['serializer']['groups']);
372
            }
373 1
            $viewHandler->addMethodCall('setExclusionStrategyGroups', array($config['serializer']['groups']));
374 1
        }
375
376 40
        $viewHandler->addMethodCall('setSerializeNullStrategy', array($config['serializer']['serialize_null']));
377 40
    }
378
379 40
    private function loadZoneMatcherListener(array $config, XmlFileLoader $loader, ContainerBuilder $container)
380
    {
381 40
        if (!empty($config['zone'])) {
382 1
            $loader->load('zone_matcher_listener.xml');
383 1
            $zoneMatcherListener = $container->getDefinition('fos_rest.zone_matcher_listener');
384
385 1
            foreach ($config['zone'] as $zone) {
386 1
                $matcher = $this->createZoneRequestMatcher($container,
387 1
                    $zone['path'],
388 1
                    $zone['host'],
389 1
                    $zone['methods'],
390 1
                    $zone['ips']
391 1
                );
392
393 1
                $zoneMatcherListener->addMethodCall('addRequestMatcher', array($matcher));
394 1
            }
395 1
        }
396 40
    }
397
398 1
    private function createZoneRequestMatcher(ContainerBuilder $container, $path = null, $host = null, $methods = array(), $ip = null)
399
    {
400 1
        if ($methods) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $methods of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
401
            $methods = array_map('strtoupper', (array) $methods);
402
        }
403
404 1
        $serialized = serialize(array($path, $host, $methods, $ip));
405 1
        $id = 'fos_rest.zone_request_matcher.'.md5($serialized).sha1($serialized);
406
407
        // only add arguments that are necessary
408 1
        $arguments = array($path, $host, $methods, $ip);
409 1
        while (count($arguments) > 0 && !end($arguments)) {
410 1
            array_pop($arguments);
411 1
        }
412
413
        $container
414 1
            ->setDefinition($id, new DefinitionDecorator('fos_rest.zone_request_matcher'))
415 1
            ->setArguments($arguments)
416
        ;
417
418 1
        return new Reference($id);
419
    }
420
421
    /**
422
     * Checks if an exception is loadable.
423
     *
424
     * @param string $exception Class to test
425
     *
426
     * @throws \InvalidArgumentException if the class was not found.
427
     */
428 5
    private function testExceptionExists($exception)
429
    {
430 5
        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...
431 2
            throw new \InvalidArgumentException("FOSRestBundle exception mapper: Could not load class '$exception' or the class does not extend from '\Exception'. Most probably this is a configuration problem.");
432
        }
433 3
    }
434
}
435