Passed
Push — master ( b154b6...f3f49e )
by Alexey
01:50
created

Tag::setKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 2
c 1
b 1
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace iamsaint\yml\components;
4
5
use iamsaint\yml\BaseObject;
6
use function count;
7
8
/**
9
 * Class Shop
10
 * @package iamsaint\yml\components
11
 *
12
 * @property string $key
13
 * @property string $groupKey
14
 * @property BaseObject|string $value
15
 * @property array $attributes
16
 */
17
class Tag extends BaseObject
18
{
19
    public $key;
20
    public $groupKey;
21
    public $value;
22
    public $attributes = [];
23
24
    public function write(): void
25
    {
26
        $this->writer->startElement($this->key);
27
28
        foreach ($this->attributes as $key => $value) {
29
            $this->writer->writeAttribute($key, $value);
30
        }
31
32
        if($this->value instanceof BaseObject) {
33
            $this->writer->writeElement($this->groupKey, $this->value);
0 ignored issues
show
Bug introduced by
$this->value of type iamsaint\yml\BaseObject is incompatible with the type string expected by parameter $content of XMLWriter::writeElement(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
            $this->writer->writeElement($this->groupKey, /** @scrutinizer ignore-type */ $this->value);
Loading history...
34
        } else {
35
            $this->writer->text($this->value);
36
        }
37
38
        $this->writer->endElement();
39
    }
40
41
    /**
42
     * @param array $attributes
43
     * @return Tag
44
     */
45
    public function setAttributes($attributes) {
46
        $this->attributes = $attributes;
47
        return $this;
48
    }
49
50
    /**
51
     * @param string $key
52
     * @return Tag
53
     */
54
    public function setKey($key) {
55
        $this->key = $key;
56
        return $this;
57
    }
58
59
    /**
60
     * @param BaseObject|string $value
61
     * @return Tag
62
     */
63
    public function setValue($value) {
64
        $this->value = $value;
65
        return $this;
66
    }
67
}