ResourceCreated::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.2
cc 4
eloc 6
nc 3
nop 1
1
<?php
2
3
/**
4
 * Author: Nil Portugués Calderó <[email protected]>
5
 * Date: 7/29/15
6
 * Time: 12:48 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
class ResourceCreated extends AbstractResponse
14
{
15
    protected $httpCode = 201;
16
17
    /**
18
     * @param string $json
19
     */
20
    public function __construct($json)
21
    {
22
        $data = \json_decode($json, true);
23
24
        if (null !== $data && !empty($data['data']['links']['self'])) {
25
            $data = $data['data']['links']['self'];
26
            $this->headers['Location'] = (!empty($data['href'])) ? $data['href'] : $data;
27
        }
28
29
        $this->response = self::instance($json, $this->httpCode, $this->headers);
30
    }
31
}
32