JsonCollectionResponse   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 23
rs 10
c 2
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A fromPaginator() 0 9 1
1
<?php
2
3
/**
4
 * Copyright 2014 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
0 ignored issues
show
Coding Style introduced by
Missing @link tag in file comment
Loading history...
18
19
namespace Surfnet\StepupMiddleware\ApiBundle\Response;
20
21
use Pagerfanta\Pagerfanta;
22
use Symfony\Component\HttpFoundation\JsonResponse;
23
24
class JsonCollectionResponse extends JsonResponse
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class JsonCollectionResponse
Loading history...
25
{
26
    public static function fromPaginator(Pagerfanta $paginator, array $filters = []): self
27
    {
28
        return new self(
29
            $paginator->getNbResults(),
30
            $paginator->getCurrentPage(),
31
            $paginator->getMaxPerPage(),
32
            (array)$paginator->getCurrentPageResults(),
33
            [],
34
            $filters,
35
        );
36
    }
37
38
    public function __construct(int $totalItems, int $page, int $pageSize, array $collection, array $headers = [], array $filters = [])
39
    {
40
        $data = [
41
            'collection' => ['total_items' => $totalItems, 'page' => $page, 'page_size' => $pageSize],
42
            'items' => $collection,
43
            'filters' => $filters,
44
        ];
45
46
        parent::__construct($data, 200, $headers);
47
    }
48
}
49