WhiteOctoberPagerfantaExtension::load()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 9.424
c 0
b 0
f 0
cc 4
nc 8
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Pagerfanta package.
5
 *
6
 * (c) Pablo Díez <[email protected]>
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 WhiteOctober\PagerfantaBundle\DependencyInjection;
13
14
use Symfony\Component\Config\FileLocator;
15
use Symfony\Component\Config\Definition\Processor;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\ContainerInterface;
18
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
19
use Symfony\Component\DependencyInjection\Reference;
20
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
21
22
/**
23
 * WhiteOctoberPagerfantaExtension.
24
 *
25
 * @author Pablo Díez <[email protected]>
26
 */
27
class WhiteOctoberPagerfantaExtension extends Extension
28
{
29
    /**
30
     * Responds to the "white_october_pagerfanta" configuration parameter.
31
     *
32
     * @param array            $configs
33
     * @param ContainerBuilder $container
34
     */
35
    public function load(array $configs, ContainerBuilder $container)
36
    {
37
        $configuration = new Configuration();
38
        $processor = new Processor();
39
40
        $config = $processor->processConfiguration($configuration, $configs);
41
        $container->setParameter('white_october_pagerfanta.default_view', $config['default_view']);
42
43
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
44
        $loader->load('pagerfanta.xml');
45
46
        if ($config['exceptions_strategy']['out_of_range_page'] == Configuration::EXCEPTION_STRATEGY_TO_HTTP_NOT_FOUND) {
47
            $convertListener = $container->getDefinition('pagerfanta.convert_not_valid_max_per_page_to_not_found_listener');
48
            $convertListener->addTag('kernel.event_subscriber');
49
        }
50
51
        if ($config['exceptions_strategy']['not_valid_current_page'] == Configuration::EXCEPTION_STRATEGY_TO_HTTP_NOT_FOUND) {
52
            $convertListener = $container->getDefinition('pagerfanta.convert_not_valid_current_page_to_not_found_listener');
53
            $convertListener->addTag('kernel.event_subscriber');
54
        }
55
56
        // BC layer to inject the 'request' service when RequestStack is unavailable
57
        if (!class_exists('Symfony\\Component\\HttpFoundation\\RequestStack')) {
58
            $container
59
                ->getDefinition('twig.extension.pagerfanta')
60
                ->addMethodCall('setRequest', array(
61
                    new Reference('request', ContainerInterface::NULL_ON_INVALID_REFERENCE, false),
0 ignored issues
show
Unused Code introduced by
The call to Reference::__construct() has too many arguments starting with false.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
62
                ))
63
            ;
64
        }
65
    }
66
}
67