Included::isEmpty()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * Author: Nil Portugués Calderó <[email protected]>
4
 * Date: 12/14/15
5
 * Time: 7:13 PM.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace NilPortugues\Api\JsonApi\Http\Request\Parameters;
11
12
/**
13
 * Class Included.
14
 */
15
class Included
16
{
17
    /**
18
     * @var array
19
     */
20
    protected $included = [];
21
22
    /**
23
     * @param string $relationship
24
     */
25
    public function add($relationship)
26
    {
27
        $data = \explode('.', (string) $relationship);
28
        $type = $data[0];
29
        $attribute = (!empty($data[1])) ? $data[1] : null;
30
31
        if (null === $attribute) {
32
            $this->included[$type] = $type;
33
        } else {
34
            if (!empty($this->included[$type]) && is_string($this->included[$type])) {
35
                $this->included[$type] = [];
36
            }
37
            $this->included[$type][] = $attribute;
38
        }
39
    }
40
41
    /**
42
     * @return array
43
     */
44
    public function get()
45
    {
46
        return $this->included;
47
    }
48
49
    /**
50
     * @return bool
51
     */
52
    public function isEmpty()
53
    {
54
        return 0 === count($this->included);
55
    }
56
}
57