Completed
Push — master ( 2edeb4...8f93c5 )
by Albert
03:04
created

PaginatorBuilder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
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 3
    public function __construct(\Twig_Environment $twig, $perPage)
14
    {
15 3
        $this->twig = $twig;
16 3
        $this->perPage = $perPage;
17 3
    }
18
19 3
    public function build(ServerRequestInterface $request, $count)
20
    {
21 3
        $page = isset($request->getQueryParams()['page']) &&
22 3
            ($page = $request->getQueryParams()['page'] > 0) ? $page : 1;
23
        
24 3
        return new Paginator(
25 3
            $page,
26 3
            $this->perPage,
27 3
            ceil($count / $this->perPage),
28 3
            $this->twig
29 3
        );
30
    }
31
}
32