Passed
Push — master ( 8dcdb6...5c2e0a )
by Jakub
01:56
created

Image::setUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Nexendrie\Rss;
5
6
use Nexendrie\Utils\Numbers;
7
8
/**
9
 * Image
10
 *
11
 * @author Jakub Konečný
12
 * @property string $url
13
 * @property string $title
14
 * @property string $link
15
 * @property int $width
16
 * @property int $height
17
 * @property string $description
18
 */
19 1
final class Image implements IXmlConvertible {
20 1
  use \Nette\SmartObject;
21
22
  /** @var string */
23
  protected $url;
24
  /** @var string */
25
  protected $title;
26
  /** @var string */
27
  protected $link;
28
  /** @var int */
29
  protected $width;
30
  /** @var int */
31
  protected $height;
32
  /** @var string */
33
  protected $description;
34
35
  public function __construct(string $url, string $title, string $link, string $description = "") {
36 1
    $this->url = $url;
37 1
    $this->title = $title;
38 1
    $this->link = $link;
39 1
    $this->description = $description;
40 1
  }
41
42
  public function getUrl(): string {
43 1
    return $this->url;
44
  }
45
46
  public function setUrl(string $url): void {
47 1
    $this->url = $url;
48 1
  }
49
50
  public function getTitle(): string {
51 1
    return $this->title;
52
  }
53
54
  public function setTitle(string $title): void {
55 1
    $this->title = $title;
56 1
  }
57
58
  public function getLink(): string {
59 1
    return $this->link;
60
  }
61
62
  public function setLink(string $link): void {
63 1
    $this->link = $link;
64 1
  }
65
66
  public function getWidth(): int {
67 1
    return $this->width;
68
  }
69
70
  public function setWidth(int $width): void {
71 1
    $this->width = Numbers::range($width, 0, 144);
72 1
  }
73
74
  public function getHeight(): int {
75 1
    return $this->height;
76
  }
77
78
  public function setHeight(int $height): void {
79 1
    $this->height = Numbers::range($height, 0, 400);
80 1
  }
81
82
  public function getDescription(): string {
83 1
    return $this->description;
84
  }
85
86
  public function setDescription(string $description): void {
87 1
    $this->description = $description;
88 1
  }
89
90
  public function appendToXml(\SimpleXMLElement &$parent): void {
91 1
    $element = $parent->addChild("image");
92 1
    $element->addChild("url", $this->url);
93 1
    $element->addChild("title", $this->title);
94 1
    $element->addChild("link", $this->link);
95 1
    if($this->description !== "") {
96 1
      $element->addChild("description", $this->description);
97
    }
98 1
    if(isset($this->width)) {
99 1
      $element->addChild("width", (string) $this->width);
100
    }
101 1
    if(isset($this->height)) {
102 1
      $element->addChild("height", (string) $this->height);
103
    }
104 1
  }
105
}
106
?>