Completed
Push — v2 ( f15f0a...141320 )
by Joschi
05:08
created

Item   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 130
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 96%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 4
dl 0
loc 130
ccs 24
cts 25
cp 0.96
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 3
A getType() 0 4 1
A getId() 0 4 1
A getLanguage() 0 4 1
A getProperties() 0 4 1
A getProperty() 0 12 3
A isEmpty() 0 4 1
1
<?php
2
3
/**
4
 * micrometa
5
 *
6
 * @category Jkphl
7
 * @package Jkphl\Micrometa
8
 * @subpackage Jkphl\Micrometa\Domain\Miom
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\Micrometa\Domain\Item;
38
39
use Jkphl\Micrometa\Domain\Factory\IriFactory;
40
use Jkphl\Micrometa\Domain\Factory\PropertyListFactory;
41
use Jkphl\Micrometa\Domain\Factory\PropertyListFactoryInterface;
42
43
/**
44
 * Micro information item
45
 *
46
 * @package Jkphl\Micrometa
47
 * @subpackage Jkphl\Micrometa\Domain
48
 */
49
class Item implements ItemInterface
50
{
51
    /**
52
     * Use the setup methods
53
     */
54
    use ItemSetupTrait;
55
56
    /**
57
     * Item type(s)
58
     *
59
     * @var \stdClass[]
60
     */
61
    protected $type;
62
63
    /**
64
     * Item properties
65
     *
66
     * @var PropertyListInterface
67
     */
68
    protected $properties;
69
70
    /**
71
     * Item ID
72
     *
73
     * @var string
74
     */
75
    protected $itemId;
76
77
    /**
78
     * Item language
79
     *
80
     * @var string
81
     */
82
    protected $itemLanguage;
83
84
    /**
85
     * Item constructor
86
     *
87
     * @param string|\stdClass|\stdClass[] $type Item type(s)
88
     * @param \stdClass[] $properties Item properties
89
     * @param string|null $itemId Item id
90
     * @param string|null $itemLanguage Item language
91
     * @param PropertyListFactoryInterface|null $propertyListFactory Property list factory
92
     */
93 52
    public function __construct(
94
        $type,
95
        array $properties = [],
96
        $itemId = null,
97
        $itemLanguage = null,
98
        PropertyListFactoryInterface $propertyListFactory = null
99
    ) {
100 52
        $this->setup(
101 52
            $propertyListFactory ?: new PropertyListFactory(),
102 52
            is_array($type) ? $type : [$type],
103
            $properties,
104 52
            trim($itemId),
105 52
            trim($itemLanguage)
106
        );
107 47
    }
108
109
    /**
110
     * Return the item types
111
     *
112
     * @return \stdClass[] Item types
113
     */
114 26
    public function getType()
115
    {
116 26
        return $this->type;
117
    }
118
119
    /**
120
     * Return the item ID (if any)
121
     *
122
     * @return string|null Item id
123
     */
124 21
    public function getId()
125
    {
126 21
        return $this->itemId;
127
    }
128
129
    /**
130
     * Return the item language (if any)
131
     *
132
     * @return string|null Item language
133
     */
134 20
    public function getLanguage()
135
    {
136 20
        return $this->itemLanguage;
137
    }
138
139
    /**
140
     * Return all item properties
141
     *
142
     * @return PropertyListInterface Item properties list
143
     */
144 21
    public function getProperties()
145
    {
146 21
        return $this->properties;
147
    }
148
149
    /**
150
     * Return the values of a particular property
151
     *
152
     * @param string|\stdClass|Iri $name Property name
153
     * @param string|null $profile Property profile
154
     * @return array Item property values
155
     */
156 11
    public function getProperty($name, $profile = null)
157
    {
158 11
        $iri = IriFactory::create(
159 11
            (($profile === null) || is_object($name)) ?
160 9
                $name :
161
                (object)[
162 4
                    'profile' => $profile,
163 11
                    'name' => $name
164
                ]
165
        );
166 11
        return $this->properties->offsetGet($iri);
167
    }
168
169
    /**
170
     * Return whether the value should be considered empty
171
     *
172
     * @return boolean Value is empty
173
     */
174 23
    public function isEmpty()
175
    {
176 23
        return false;
177
    }
178
}
179