Serializer::serializePagination()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 9
ccs 0
cts 9
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
namespace App\Http\Rest;
3
4
use RazonYang\Yii2\JSend\Serializer as BaseSerializer;
5
use Yii;
6
use yii\web\Link;
7
8
class Serializer extends BaseSerializer
9
{
10
    public $collectionEnvelope = 'items';
11
12
    public $linksEnvelope = 'links';
13
14
    public $metaEnvelope = 'meta';
15
16
    protected function serializePagination($pagination)
17
    {
18
        return [
19
            $this->linksEnvelope => Link::serialize($pagination->getLinks(true)),
20
            $this->metaEnvelope => [
21
                'limit' => $pagination->getPageSize(),
22
                'page' => $pagination->getPage() + 1,
23
                'page_count' => $pagination->getPageCount(),
24
                'total_count' => $pagination->totalCount,
25
            ],
26
        ];
27
    }
28
}
29