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

ConceptBundle   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 49
c 1
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B jsonLDSerialize() 0 19 5
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