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

SkipHoursCollection   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 23
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A appendToXml() 0 4 1
A __construct() 0 10 2
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
?>