Rel   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 0
dl 0
loc 42
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A extractLinks() 0 14 5
A through() 0 18 3
1
<?php
2
/*
3
 * This file is part of the Respect\Rest package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Respect\Rest\Routines;
10
11
use ArrayObject;
12
use Respect\Rest\Request;
13
14
class Rel extends ArrayObject implements Routinable, ProxyableThrough
15
{
16 4
    public function __construct(array $list)
17
    {
18 4
        $this->setFlags(self::ARRAY_AS_PROPS);
19 4
        $this->exchangeArray($list);
20 4
    }
21
22 4
    public function extractLinks($data, $relSpec, $deep = true)
23
    {
24 4
        if (is_callable($relSpec)) {
25 1
            return call_user_func($relSpec, $data);
26 3
        } elseif ($deep && is_array($relSpec)) {
27 2
            foreach ($relSpec as &$r) {
28 2
                $r = $this->extractLinks($data, $r, false);
29
            }
30
31 2
            return $relSpec;
32
        }
33
34 3
        return $relSpec;
35
    }
36
37 4
    public function through(Request $request, $params)
38
    {
39 4
        $rels = $this;
40
41 4
        return function ($data) use ($rels) {
42 4
            foreach ($rels as &$r) {
43 4
                $r = $rels->extractLinks($data, $r);
44
            }
45
46 4
            if (!isset($data['links'])) {
47 4
                $data['links'] = array();
48
            }
49
50 4
            $data['links'] = array_merge_recursive($data['links'], $rels->getArrayCopy());
51
52 4
            return $data;
53 4
        };
54
    }
55
}
56