Completed
Push — master ( 44676f...b7bc18 )
by Jens
13:18
created

Set   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
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 49
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 10 3
A ofType() 0 5 1
A ofTypeAndData() 0 4 1
A __toString() 0 8 2
1
<?php
2
/**
3
 * @author @jayS-de <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Model\Common;
7
8
/**
9
 * @package Commercetools\Core\Model\Common
10
 * @link https://dev.commercetools.com/http-api-projects-products.html#attribute
11
 * @link https://dev.commercetools.com/http-api-projects-productTypes.html#settype
12
 * @link https://dev.commercetools.com/http-api-projects-productTypes.html#attributetype
13
 */
14
class Set extends Collection implements TypeableInterface
15
{
16
    /**
17
     * @param $offset
18
     * @internal
19
     */
20 28
    protected function initialize($offset)
21
    {
22 28
        parent::initialize($offset);
23
24 28
        $type = $this->getType();
25 28
        if ($this->isPrimitive($type) === false && $this->isDeserializableType($type) === false) {
26 4
            $value = new $type($this->typeData[$offset]);
27 4
            $this->typeData[$offset] = $value;
28
        }
29 28
    }
30
31
    /**
32
     * @param $type
33
     * @param Context|callable $context
34
     * @return $this
35
     */
36 30
    public static function ofType($type, $context = null)
37
    {
38 30
        $set = static::of($context);
39 30
        return $set->setType($type);
40
    }
41
42
    /**
43
     * @param $type
44
     * @param array $data
45
     * @param Context|callable $context
46
     * @return $this
47
     */
48 27
    public static function ofTypeAndData($type, array $data, $context = null)
49
    {
50 27
        return static::ofType($type, $context)->setRawData($data);
51
    }
52
53
54 1
    public function __toString()
55
    {
56 1
        $values = [];
57 1
        foreach ($this as $set) {
58 1
            $values[] = (string)$set;
59
        }
60 1
        return implode(', ', $values);
61
    }
62
}
63