OfferPicture   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 50
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A writeCustomTags() 0 4 2
A write() 0 11 2
A rules() 0 5 1
A setUrl() 0 4 1
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