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

Set::__toString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 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