PaginatorBuilder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 4
c 3
b 0
f 1
lcom 1
cbo 2
dl 0
loc 35
ccs 13
cts 13
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A build() 0 12 3
1
<?php
2
3
namespace Albert221\Blog\Pagination;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
7
class PaginatorBuilder
8
{
9
    private $twig;
10
    private $perPage;
11
12
    /**
13
     * PaginatorBuilder constructor.
14
     *
15
     * @param \Twig_Environment $twig
16
     * @param int $perPage
17
     */
18 3
    public function __construct(\Twig_Environment $twig, $perPage)
19
    {
20 3
        $this->twig = $twig;
21 3
        $this->perPage = $perPage;
22 3
    }
23
24
    /**
25
     * @param ServerRequestInterface $request
26
     * @param int $count
27
     * @return Paginator
28
     */
29 3
    public function build(ServerRequestInterface $request, $count)
30
    {
31 3
        $page = isset($request->getQueryParams()['page']) &&
32 3
            (($page = $request->getQueryParams()['page']) > 0) ? $page : 1;
33
        
34 3
        return new Paginator(
35 3
            $page,
36 3
            $this->perPage,
37 3
            $count,
38 3
            $this->twig
39 3
        );
40
    }
41
}
42