Passed
Push — master ( 7ddfc7...8dcdb6 )
by Jakub
01:29
created

SkipHoursCollection::appendToXml()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
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
/**
7
 * SkipHoursCollection
8
 *
9
 * @author Jakub Konečný
10
 * @internal
11
 */
12 1
final class SkipHoursCollection implements IXmlConvertible {
13
  /** @var string[] */
14
  protected $hours = [];
15
16
  /**
17
   * @param int[] $hours
18
   */
19
  public function __construct(array $hours) {
20 1
    array_walk($hours, function(int &$value) {
21 1
      if($value < 10) {
22 1
        $value = "0" . (string) $value;
23
      }
24 1
      $value = (string) $value;
25 1
    });
26
    /** @var string[] $hours */
27 1
    $hours = array_unique($hours);
28 1
    $this->hours = $hours;
29 1
  }
30
31
  public function appendToXml(\SimpleXMLElement &$parent): void {
32 1
    $element = $parent->addChild("skipHours");
33 1
    array_walk($this->hours, function(string $value) use($element) {
34 1
      $element->addChild("hour", $value);
35 1
    });
36 1
  }
37
}
38
?>