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

PaginatorBuilder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A build() 0 11 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