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

PaginatorBuilder::build()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
ccs 0
cts 10
cp 0
rs 9.4285
cc 2
eloc 7
nc 2
nop 2
crap 6
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