RestfulServerItem   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 20
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handleRelation() 0 9 2
A __construct() 0 3 1
1
<?php
2
3
namespace SilverStripe\RestfulServer;
4
5
use SilverStripe\ORM\SS_List;
6
7
/**
8
 * Restful server handler for a single DataObject
9
 */
10
class RestfulServerItem
11
{
12
    private static $url_handlers = array(
0 ignored issues
show
introduced by
The private property $url_handlers is not used, and could be removed.
Loading history...
13
        '$Relation' => 'handleRelation',
14
    );
15
16
    public function __construct($item)
17
    {
18
        $this->item = $item;
0 ignored issues
show
Bug Best Practice introduced by
The property item does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
19
    }
20
21
    public function handleRelation($request)
22
    {
23
        $funcName = $request('Relation');
24
        $relation = $this->item->$funcName();
25
26
        if ($relation instanceof SS_List) {
27
            return new RestfulServerList($relation);
28
        } else {
29
            return new RestfulServerItem($relation);
30
        }
31
    }
32
}
33