AbstractContext   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 1
dl 0
loc 91
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getChildren() 0 4 1
A getParentThing() 0 4 1
A setParentThing() 0 11 2
A addChild() 0 5 1
A getDefaultVocabulary() 0 4 1
1
<?php
2
3
/**
4
 * rdfa-lite-microdata
5
 *
6
 * @category Jkphl
7
 * @package Jkphl\RdfaLiteMicrodata
8
 * @subpackage Jkphl\RdfaLiteMicrodata\Application
9
 * @author Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright Copyright © 2017 Joschi Kuphal <[email protected]> / @jkphl
11
 * @license http://opensource.org/licenses/MIT The MIT License (MIT)
12
 */
13
14
/***********************************************************************************
15
 *  The MIT License (MIT)
16
 *
17
 *  Copyright © 2017 Joschi Kuphal <[email protected]> / @jkphl
18
 *
19
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
20
 *  this software and associated documentation files (the "Software"), to deal in
21
 *  the Software without restriction, including without limitation the rights to
22
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
23
 *  the Software, and to permit persons to whom the Software is furnished to do so,
24
 *  subject to the following conditions:
25
 *
26
 *  The above copyright notice and this permission notice shall be included in all
27
 *  copies or substantial portions of the Software.
28
 *
29
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
31
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
32
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
33
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
 ***********************************************************************************/
36
37
namespace Jkphl\RdfaLiteMicrodata\Application\Context;
38
39
use Jkphl\RdfaLiteMicrodata\Application\Parser\RootThing;
40
use Jkphl\RdfaLiteMicrodata\Domain\Thing\ThingInterface;
41
use Jkphl\RdfaLiteMicrodata\Domain\Vocabulary\VocabularyInterface;
42
43
/**
44
 * Abstract parsing context
45
 *
46
 * @package Jkphl\RdfaLiteMicrodata
47
 * @subpackage Jkphl\RdfaLiteMicrodata\Application
48
 */
49
abstract class AbstractContext implements ContextInterface
50
{
51
    /**
52
     * Current default vocabulary
53
     *
54
     * @var VocabularyInterface
55
     */
56
    protected $defaultVocabulary = null;
57
58
    /**
59
     * Parent thing
60
     *
61
     * @var ThingInterface
62
     */
63
    protected $parentThing;
64
65
    /**
66
     * Root thing
67
     *
68
     * @var RootThing
69
     */
70
    protected $rootThing;
71
72
    /**
73
     * Context constructor
74
     */
75 27
    public function __construct()
76
    {
77 27
        $this->parentThing = $this->rootThing = new RootThing();
78 27
    }
79
80
    /**
81
     * Return the registered child things
82
     *
83
     * @return ThingInterface[] Child things
84
     */
85 12
    public function getChildren()
86
    {
87 12
        return $this->rootThing->getChildren();
88
    }
89
90
    /**
91
     * Return the current parent thing
92
     *
93
     * @return ThingInterface|null Parent thing
94
     */
95 12
    public function getParentThing()
96
    {
97 12
        return $this->parentThing;
98
    }
99
100
    /**
101
     * Set the parent thing
102
     *
103
     * @param ThingInterface $parentThing Parent thing
104
     * @return ContextInterface Self reference
105
     */
106 13
    public function setParentThing(ThingInterface $parentThing)
107
    {
108
        // If the new parent thing differs from the current one
109 13
        if ($this->parentThing !== $parentThing) {
110 13
            $context = clone $this;
111 13
            $context->parentThing = $parentThing;
112 13
            return $context;
113
        }
114
115 1
        return $this;
116
    }
117
118
    /**
119
     * Add a child thing to the current parent thing
120
     *
121
     * @param ThingInterface $thing Child thing
122
     * @return ContextInterface Self reference
123
     */
124 12
    public function addChild(ThingInterface $thing)
125
    {
126 12
        $this->rootThing->addChild($thing);
127 12
        return $this;
128
    }
129
130
    /**
131
     * Return the current default vocabulary
132
     *
133
     * @return VocabularyInterface Current default vocabulary
134
     */
135 15
    public function getDefaultVocabulary()
136
    {
137 15
        return $this->defaultVocabulary;
138
    }
139
}
140