GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ArraySerializer   A
last analyzed

↳ Parent: Project

Coupling/Cohesion

Components 0
Dependencies 3

Complexity

Total Complexity 11

Size/Duplication

Total Lines 119
Duplicated Lines 0 %

Test Coverage

Coverage 94.44%

Importance

Changes 0
Metric Value
wmc 11
c 0
b 0
f 0
lcom 0
cbo 3
dl 0
loc 119
ccs 34
cts 36
cp 0.9444
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A collection() 0 4 2
A item() 0 4 1
A null() 0 4 1
A includedData() 0 4 1
A meta() 0 8 2
B paginator() 0 25 3
A cursor() 0 11 1
1
<?php
2
3
/*
4
 * This file is part of the League\Fractal package.
5
 *
6
 * (c) Phil Sturgeon <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace League\Fractal\Serializer;
13
14
use League\Fractal\Pagination\CursorInterface;
15
use League\Fractal\Pagination\PaginatorInterface;
16
use League\Fractal\Resource\ResourceInterface;
17
18
class ArraySerializer extends SerializerAbstract
19
{
20
    /**
21
     * Serialize a collection.
22
     *
23
     * @param string $resourceKey
24
     * @param array  $data
25
     *
26
     * @return array
27
     */
28 2
    public function collection($resourceKey, array $data)
29
    {
30 2
        return [$resourceKey ?: 'data' => $data];
31
    }
32
33
    /**
34
     * Serialize an item.
35
     *
36
     * @param string $resourceKey
37
     * @param array  $data
38
     *
39
     * @return array
40
     */
41 5
    public function item($resourceKey, array $data)
42
    {
43 5
        return $data;
44
    }
45
46
    /**
47
     * Serialize null resource.
48
     *
49
     * @return array
50
     */
51 1
    public function null()
52
    {
53 1
        return [];
54
    }
55
56
    /**
57
     * Serialize the included data.
58
     *
59
     * @param ResourceInterface $resource
60
     * @param array             $data
61
     *
62
     * @return array
63
     */
64
    public function includedData(ResourceInterface $resource, array $data)
65
    {
66
        return $data;
67
    }
68
69
    /**
70
     * Serialize the meta.
71
     *
72
     * @param array $meta
73
     *
74
     * @return array
75
     */
76 17
    public function meta(array $meta)
77
    {
78 17
        if (empty($meta)) {
79 15
            return [];
80
        }
81
82 9
        return ['meta' => $meta];
83
    }
84
85
    /**
86
     * Serialize the paginator.
87
     *
88
     * @param PaginatorInterface $paginator
89
     *
90
     * @return array
91
     */
92 1
    public function paginator(PaginatorInterface $paginator)
93
    {
94 1
        $currentPage = (int) $paginator->getCurrentPage();
95 1
        $lastPage = (int) $paginator->getLastPage();
96
97
        $pagination = [
98 1
            'total' => (int) $paginator->getTotal(),
99 1
            'count' => (int) $paginator->getCount(),
100 1
            'per_page' => (int) $paginator->getPerPage(),
101 1
            'current_page' => $currentPage,
102 1
            'total_pages' => $lastPage,
103 1
        ];
104
105 1
        $pagination['links'] = [];
106
107 1
        if ($currentPage > 1) {
108 1
            $pagination['links']['previous'] = $paginator->getUrl($currentPage - 1);
109 1
        }
110
111 1
        if ($currentPage < $lastPage) {
112 1
            $pagination['links']['next'] = $paginator->getUrl($currentPage + 1);
113 1
        }
114
115 1
        return ['pagination' => $pagination];
116
    }
117
118
    /**
119
     * Serialize the cursor.
120
     *
121
     * @param CursorInterface $cursor
122
     *
123
     * @return array
124
     */
125 1
    public function cursor(CursorInterface $cursor)
126
    {
127
        $cursor = [
128 1
            'current' => $cursor->getCurrent(),
129 1
            'prev' => $cursor->getPrev(),
130 1
            'next' => $cursor->getNext(),
131 1
            'count' => (int) $cursor->getCount(),
132 1
        ];
133
134 1
        return ['cursor' => $cursor];
135
    }
136
}
137