Completed
Push — master ( 8b1d39...e6cddd )
by Jakob
01:31
created

ConceptBundle::jsonLDSerialize()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
c 0
b 0
f 0
rs 8.8571
cc 5
eloc 13
nc 16
nop 1
1
<?php declare(strict_types = 1);
2
3
namespace JSKOS;
4
5
use JSKOS\PrettyJsonSerializable;
6
7
/**
8
 * A JSKOS Concept Bundle to be used as part of Mappings.
9
 *
10
 * @see https://gbv.github.io/jskos/jskos.html#concept-bundles
11
 */
12
class ConceptBundle extends PrettyJsonSerializable
13
{
14
    const FIELDS = [
15
        'members' => ['Set', 'Concept']
16
    ];
17
18
    /**
19
     * Set of concepts in this bundle.
20
     *
21
     * @var Set $members
22
     */
23
    public $members = [];
24
25
    /**
26
     * Whether the concepts in this bundle are ordered (list) or not (set).
27
     * @var boolean $ordered
28
     */
29
    public $ordered = false;
30
31
    /**
32
     * Whether the concepts in this bundle are combined by OR instead of AND.
33
     * @var boolean $disjunction
34
     */
35
    public $disjunction = false;
36
37
    /**
38
     * Returns data which should be serialized to JSON.
39
     * @param string $context
40
     */
41
    public function jsonLDSerialize(string $context = self::DEFAULT_CONTEXT)
42
    {
43
        $members = [];
44
        foreach ($this->members as $m) {
45
            $members[] = $m->jsonLDSerialize('');
46
        }
47
        $json = [];
48
        if ($context) {
49
            $json['@context'] = $context;
50
        }
51
        $json['members'] = $members;
52
        if ($this->ordered) {
53
            $json['ordered'] = true;
54
        }
55
        if ($this->disjunction) {
56
            $json['disjunction'] = true;
57
        }
58
        return $json;
59
    }
60
}
61