Item   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getType() 0 4 1
A getId() 0 4 1
A getLanguage() 0 4 1
A getProperties() 0 4 1
A getProperty() 0 13 3
A isEmpty() 0 4 1
A __construct() 0 15 3
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 © 2018 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 © 2018 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 constructor
58
     *
59
     * @param string|\stdClass|\stdClass[] $type                     Item type(s)
60
     * @param \stdClass[] $properties                                Item properties
61
     * @param string|null $itemId                                    Item id
62
     * @param string|null $itemLanguage                              Item language
63
     * @param PropertyListFactoryInterface|null $propertyListFactory Property list factory
64
     */
65 56
    public function __construct(
66
        $type,
67
        array $properties = [],
68
        $itemId = null,
69
        $itemLanguage = null,
70
        PropertyListFactoryInterface $propertyListFactory = null
71
    ) {
72 56
        $this->setup(
73 56
            $propertyListFactory ?: new PropertyListFactory(),
74 56
            is_array($type) ? $type : [$type],
75 56
            $properties,
76 56
            trim($itemId),
77 56
            trim($itemLanguage)
78
        );
79 51
    }
80
81
    /**
82
     * Return the item types
83
     *
84
     * @return \stdClass[] Item types
85
     */
86 26
    public function getType()
87
    {
88 26
        return $this->type;
89
    }
90
91
    /**
92
     * Return the item ID (if any)
93
     *
94
     * @return string|null Item id
95
     */
96 21
    public function getId()
97
    {
98 21
        return $this->itemId;
99
    }
100
101
    /**
102
     * Return the item language (if any)
103
     *
104
     * @return string|null Item language
105
     */
106 19
    public function getLanguage()
107
    {
108 19
        return $this->itemLanguage;
109
    }
110
111
    /**
112
     * Return all item properties
113
     *
114
     * @return PropertyListInterface Item properties list
115
     */
116 21
    public function getProperties()
117
    {
118 21
        return $this->properties;
119
    }
120
121
    /**
122
     * Return the values of a particular property
123
     *
124
     * @param string|\stdClass|Iri $name Property name
125
     * @param string|null $profile       Property profile
126
     *
127
     * @return array Item property values
128
     */
129 12
    public function getProperty($name, $profile = null)
130
    {
131 12
        $iri = IriFactory::create(
132 12
            (($profile === null) || is_object($name)) ?
133 10
                $name :
134
                (object)[
135 4
                    'profile' => $profile,
136 12
                    'name'    => $name
137
                ]
138
        );
139
140 12
        return $this->properties->offsetGet($iri);
141
    }
142
143
    /**
144
     * Return whether the value should be considered empty
145
     *
146
     * @return boolean Value is empty
147
     */
148 25
    public function isEmpty()
149
    {
150 25
        return false;
151
    }
152
}
153