Image::getWidth()   A
last analyzed

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 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
rs 10
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 int $width
13
 * @property int $height
14
 */
15 1
final class Image implements IXmlConvertible {
16
  use \Nette\SmartObject;
17
18
  public string $url;
19
  public string $title;
20
  public string $link;
21
  private int $width;
22
  private int $height;
23
  public string $description;
24
25
  public function __construct(string $url, string $title, string $link, string $description = "") {
26 1
    $this->url = $url;
27 1
    $this->title = $title;
28 1
    $this->link = $link;
29 1
    $this->description = $description;
30 1
  }
31
32
  protected function getWidth(): int {
33 1
    return $this->width;
34
  }
35
36
  protected function setWidth(int $width): void {
37 1
    $this->width = Numbers::range($width, 0, 144);
38 1
  }
39
40
  protected function getHeight(): int {
41 1
    return $this->height;
42
  }
43
44
  protected function setHeight(int $height): void {
45 1
    $this->height = Numbers::range($height, 0, 400);
46 1
  }
47
48
  public function appendToXml(\SimpleXMLElement &$parent): void {
49 1
    $element = $parent->addChild("image");
50 1
    $element->addChild("url", $this->url);
51 1
    $element->addChild("title", $this->title);
52 1
    $element->addChild("link", $this->link);
53 1
    if($this->description !== "") {
54 1
      $element->addChild("description", $this->description);
55
    }
56 1
    if(isset($this->width)) {
57 1
      $element->addChild("width", (string) $this->width);
58
    }
59 1
    if(isset($this->height)) {
60 1
      $element->addChild("height", (string) $this->height);
61
    }
62 1
  }
63
}
64
?>