Category   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 67
rs 10
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A write() 0 17 4
A setId() 0 4 1
A setParentId() 0 4 1
A writeCustomTags() 0 4 2
A setName() 0 4 1
1
<?php
2
3
namespace iamsaint\yml\components;
4
5
use iamsaint\yml\BaseObject;
6
use XMLWriter;
7
8
/**
9
 * Class Category
10
 * @package iamsaint\yml\components
11
 *
12
 * @property string $name
13
 * @property int $id
14
 * @property int $parentId
15
 * @property Tag[] $customTags
16
 */
17
class Category extends BaseObject
18
{
19
    public $name;
20
    public $id;
21
    public $parentId;
22
    public $customTags = [];
23
24
    /**
25
     * @param XMLWriter $writer
26
     */
27
    public function write($writer): void
28
    {
29
        $writer->startElement('category');
30
31
        if (null !== $this->id) {
32
            $writer->writeAttribute('id', $this->id);
33
        }
34
        if (null !== $this->parentId) {
35
            $writer->writeAttribute('parentId', $this->parentId);
36
        }
37
        if (null !== $this->name) {
38
            $writer->text($this->name);
39
        }
40
41
        $this->writeCustomTags($writer);
42
43
        $writer->endElement();
44
    }
45
46
    /**
47
     * @param XMLWriter $writer
48
     */
49
    public function writeCustomTags($writer): void
50
    {
51
        foreach ($this->customTags as $tag) {
52
            $tag->write($writer);
53
        }
54
    }
55
56
    /**
57
     * @param mixed $name
58
     * @return Category
59
     */
60
    public function setName($name): Category
61
    {
62
        $this->name = $name;
63
        return $this;
64
    }
65
66
    /**
67
     * @param mixed $id
68
     * @return Category
69
     */
70
    public function setId($id): Category
71
    {
72
        $this->id = $id;
73
        return $this;
74
    }
75
76
    /**
77
     * @param mixed $parentId
78
     * @return Category
79
     */
80
    public function setParentId($parentId): Category
81
    {
82
        $this->parentId = $parentId;
83
        return $this;
84
    }
85
}
86