Tag   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
eloc 19
c 2
b 1
f 1
dl 0
loc 55
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setValue() 0 4 1
A setAttributes() 0 4 1
A setKey() 0 4 1
A write() 0 15 3
1
<?php
2
3
namespace iamsaint\yml\components;
4
5
use iamsaint\yml\BaseObject;
6
use XMLWriter;
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
    /**
25
     * @param XMLWriter $writer
26
     */
27
    public function write($writer): void
28
    {
29
        $writer->startElement($this->key);
30
31
        foreach ($this->attributes as $key => $value) {
32
            $writer->writeAttribute($key, $value);
33
        }
34
35
        if ($this->value instanceof BaseObject) {
36
            $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

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