Completed
Push — master ( 754f5c...d85481 )
by Joschi
05:03
created

Item   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 102
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 102
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 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 54
    public function __construct(
66
        $type,
67
        array $properties = [],
68
        $itemId = null,
69
        $itemLanguage = null,
70
        PropertyListFactoryInterface $propertyListFactory = null
71
    ) {
72 54
        $this->setup(
73 54
            $propertyListFactory ?: new PropertyListFactory(),
74 54
            is_array($type) ? $type : [$type],
75
            $properties,
76 54
            trim($itemId),
77 54
            trim($itemLanguage)
78
        );
79 49
    }
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 20
    public function getLanguage()
107
    {
108 20
        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
     * @return array Item property values
127
     */
128 11
    public function getProperty($name, $profile = null)
129
    {
130 11
        $iri = IriFactory::create(
131 11
            (($profile === null) || is_object($name)) ?
132 9
                $name :
133
                (object)[
134 4
                    'profile' => $profile,
135 11
                    'name' => $name
136
                ]
137
        );
138 11
        return $this->properties->offsetGet($iri);
139
    }
140
141
    /**
142
     * Return whether the value should be considered empty
143
     *
144
     * @return boolean Value is empty
145
     */
146 25
    public function isEmpty()
147
    {
148 25
        return false;
149
    }
150
}
151