Completed
Push — master ( 86db02...ceb69b )
by Zlatin
01:56
created

PaginationServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 84.38%

Importance

Changes 6
Bugs 1 Features 1
Metric Value
wmc 3
c 6
b 1
f 1
lcom 0
cbo 5
dl 0
loc 51
ccs 27
cts 32
cp 0.8438
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B register() 0 46 3
1
<?php
2
3
namespace Pagination;
4
5
use Pimple\Container;
6
use Silex\Application;
7
use Pimple\ServiceProviderInterface;
8
use Symfony\Component\Translation\Translator;
9
10
class PaginationServiceProvider implements ServiceProviderInterface
11
{
12
13 5
    public function register(Container $app)
14
    {
15
16 5
        $app['paginator.options'] = array(
17 5
            'offset_page' => 2,
18 5
            'page_param' => 'page',
19 5
            'items_per_page' => 10,
20
            'hide_prev_next' => true
21 5
        );
22
23
        $app['paginator'] = $app->factory(function($app) {
24
25 3
            $app['paginator.options'] = array_replace(array(
26 3
                'offset_page' => 2,
27 3
                'page_param' => 'page',
28 3
                'items_per_page' => 10,
29
                'hide_prev_next' => true
30 3
                    ), $app['paginator.options']);
31
32 3
            return new \Pagination\Util\Paginator($app);
0 ignored issues
show
Documentation introduced by
$app is of type array<string,array<strin...eger|string|boolean>"}>, but the function expects a object<Silex\Application>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
33 5
        });
34
35 5
        if (!$app->offsetExists('twig')) {
36 5
            $app->register(new \Silex\Provider\TwigServiceProvider());
37 5
        }
38
        
39 5
        if (!$app->offsetExists('translator')) {
40 5
            $app->register(new \Silex\Provider\TranslationServiceProvider());
41 5
        }
42
43
        $app['twig'] = $app->extend('twig', function(\Twig_Environment $twig) {
44 3
            $twig->addExtension(new Twig\TwigExtension());
45
            return $twig;
46 5
        });
47
48 5
        $app['twig.path'] = array_merge_recursive($app['twig.path'], array(
49 5
            __DIR__ . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'views'
50 5
        ));
51
52 5
        $app['translator'] = $app->extend('translator', function(Translator $translator, Application $app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
53
            $translationDirectory = __DIR__ . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'translations';
54
            $translator->addResource('yaml', $translationDirectory . DIRECTORY_SEPARATOR . 'messages.bg.yml', 'bg');
55
            $translator->addResource('yaml', $translationDirectory . DIRECTORY_SEPARATOR . 'messages.en.yml', 'en');
56
            return $translator;
57 5
        });
58 5
    }
59
60
}
61