Items::getItems()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php namespace FreedomCore\TrinityCore\Support\Classes;
2
3
/**
4
 * Class Items
5
 * @package FreedomCore\TrinityCore\Support\Classes
6
 */
7
class Items
8
{
9
10
    /**
11
     * Array of items
12
     * @var array
13
     */
14
    protected $items = [];
15
16
    /**
17
     * Items constructor.
18
     * @param array ...$items
19
     */
20 8
    public function __construct(...$items)
21
    {
22 8
        if (isset($items[0][0])) {
23 8
            $items = $items[0];
24
        }
25 8
        $this->items = $items;
26 8
    }
27
28
    /**
29
     * Get Items
30
     * @return array
31
     */
32 2
    public function getItems() : array
33
    {
34 2
        return $this->items;
35
    }
36
37
    /**
38
     * Count how many items we are created
39
     * @return int
40
     */
41 2
    public function count() : int
42
    {
43 2
        return count($this->items);
44
    }
45
46
    /**
47
     * Convert Class Object To Array
48
     * @return array
49
     */
50 2
    public function toArray() : array
51
    {
52 2
        $items = [];
53 2
        foreach ($this->items as $item) {
54
            /**
55
             * @var $item Item
56
             */
57 2
            $items[] = $item->getDataForConsoleAsArray();
58
        }
59 2
        return $items;
60
    }
61
62
    /**
63
     * Convert Class Object To TrinityCore Command Attribute
64
     * @return string
65
     */
66 2
    public function toCommandAttribute() : string
67
    {
68 2
        $items = [];
69 2
        foreach ($this->items as $item) {
70 2
            $items[] = $item->getDataForConsoleAsCommandAttribute();
71
        }
72 2
        return trim(implode(' ', $items));
73
    }
74
}
75