Completed
Push — master ( eaa10a...12d04d )
by Albert
03:25
created

PaginatorBuilder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Albert221\Blog\Pagination;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
7
class PaginatorBuilder
8
{
9
    private $twig;
10
    
11
    private $perPage;
12
13
    public function __construct(\Twig_Environment $twig, $perPage)
14
    {
15
        $this->twig = $twig;
16
        $this->perPage = $perPage;
17
    }
18
19
    public function build(ServerRequestInterface $request, $count)
20
    {
21
        $page = isset($request->getQueryParams()['page']) ? $request->getQueryParams()['page'] : 1;
22
        
23
        return new Paginator(
24
            $page,
25
            $this->perPage,
26
            ceil($count / $this->perPage),
27
            $this->twig
28
        );
29
    }
30
}
31