Response   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 39
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 18 5
1
<?php
2
3
/**
4
 * Author: Nil Portugués Calderó <[email protected]>
5
 * Date: 7/29/15
6
 * Time: 12:47 AM.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace NilPortugues\Api\JsonApi\Http\Response;
12
13
/**
14
 * Class Response.
15
 */
16
class Response extends AbstractResponse
17
{
18
    /**
19
     * @var int
20
     */
21
    protected $httpCode = 200;
22
23
    /**
24
     * @var array
25
     */
26
    protected $links = [
27
        'next' => 'next',
28
        'last' => 'last',
29
        'first' => 'first',
30
        'previous' => 'prev',
31
    ];
32
33
    /**
34
     * @param string $json
35
     */
36
    public function __construct($json)
37
    {
38
        $pagination = json_decode($json, true);
39
        if (!empty($pagination['links'])) {
40
            $headerLinks = [];
41
            foreach ($this->links as $linkName => $relName) {
42
                if (!empty($pagination['links'][$linkName]['href'])) {
43
                    $headerLinks[] = sprintf('<%s>; rel="%s"', $pagination['links'][$linkName]['href'], $relName);
44
                }
45
            }
46
47
            if (!empty($headerLinks)) {
48
                $this->headers['Link'] = implode(', ', $headerLinks);
49
            }
50
        }
51
52
        parent::__construct($json);
53
    }
54
}
55