Passed
Push — master ( 134fca...b154b6 )
by Alexey
02:33
created

Tag::write()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 8
c 1
b 0
f 1
nc 4
nop 0
dl 0
loc 15
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
}