Completed
Push — master ( 355225...679235 )
by Zlatin
01:59
created

PaginationServiceProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 54.84%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 4
c 4
b 0
f 1
lcom 0
cbo 3
dl 0
loc 50
ccs 17
cts 31
cp 0.5484
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 4 1
B register() 0 40 3
1
<?php
2
3
namespace Pagination;
4
5
use Silex\Application;
6
use Silex\ServiceProviderInterface;
7
use Symfony\Component\Translation\Translator;
8
9
class PaginationServiceProvider implements ServiceProviderInterface
10
{
11
12
    public function boot(Application $app)
13
    {
14
        
15
    }
16
17 5
    public function register(Application $app)
18
    {
19
20 5
        $app->flush();
21
        
22 5
        $app['paginator.options'] = array(
23 5
            'offset_page' => 2,
24 5
            'items_per_page' => 10,
25
            'hide_prev_next' => true
26 5
        );
27
28
        $app['paginator'] = $app->share(function($app) {
29 3
            $app['paginator.options'] = array_replace(array(
30 3
                'offset_page' => 2,
31 3
                'items_per_page' => 10,
32
                'hide_prev_next' => true
33 3
                    ), $app['paginator.options']);
34 3
            return new \Pagination\Util\Paginator($app);
0 ignored issues
show
Documentation introduced by
$app is of type array<string,array<strin...ing,integer|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...
35 5
        });
36
37 5
        if ($app->offsetExists('twig')) {
38
            $app['twig'] = $app->share($app->extend('twig', function(\Twig_Environment $twig) {
39
                        $twig->addExtension(new Twig\TwigExtension());
40
                        return $twig;
41
                    }));
42
43 3
            $app['twig.path'] = array_merge_recursive($app['twig.path'], array(
44 3
                __DIR__ . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'views'
45
            ));
46
        }
47
        
48 5
        if ($app->offsetExists('translator')) {
49
            $app['translator'] = $app->share($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...
50
                $translationDirectory = __DIR__ . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'translations';
51
                $translator->addResource('yaml', $translationDirectory . DIRECTORY_SEPARATOR . 'messages.bg.yml', 'bg');
52
                $translator->addResource('yaml', $translationDirectory . DIRECTORY_SEPARATOR . 'messages.en.yml', 'en');
53
                return $translator;
54
            }));
55
        }
56 5
    }
57
58
}
59