OfferPicture::setUrl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace iamsaint\yml\components;
4
5
use iamsaint\yml\BaseObject;
6
use XMLWriter;
7
8
/**
9
 * Class OfferPicture
10
 * @package iamsaint\yml\components
11
 *
12
 * @property string $url
13
 * @property Tag[] $customTags
14
 */
15
class OfferPicture extends BaseObject
16
{
17
    public $url;
18
    public $customTags = [];
19
20
    /**
21
     * @param XMLWriter $writer
22
     */
23
    public function write($writer): void
24
    {
25
        $writer->startElement('picture');
26
27
        if (null !== $this->url) {
28
            $writer->text($this->url);
29
        }
30
31
        $this->writeCustomTags($writer);
32
33
        $writer->endElement();
34
    }
35
36
    /**
37
     * @param XMLWriter $writer
38
     */
39
    public function writeCustomTags($writer): void
40
    {
41
        foreach ($this->customTags as $tag) {
42
            $tag->write($writer);
43
        }
44
    }
45
46
    /**
47
     * @return array
48
     */
49
    public function rules(): array
50
    {
51
        return [
52
            ['url', 'required'],
53
            ['url', 'url']
54
        ];
55
    }
56
57
    /**
58
     * @param $url
59
     * @return BaseObject
60
     */
61
    public function setUrl($url): BaseObject
62
    {
63
        $this->url = $url;
64
        return $this;
65
    }
66
}
67