RssChannelItem::toXml()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 4
eloc 9
c 4
b 0
f 0
nc 4
nop 2
dl 0
loc 12
ccs 9
cts 9
cp 1
crap 4
rs 9.9666
1
<?php
2
declare(strict_types=1);
3
4
namespace Nexendrie\Rss;
5
6
use Symfony\Component\OptionsResolver\OptionsResolver;
7
8
/**
9
 * Rss Channel Item
10
 *
11
 * @author Jakub Konečný
12
 */
13 1
final class RssChannelItem {
14
  use \Nette\SmartObject;
15
16
  private array $data;
17
18
  public function __construct(array $data) {
19 1
    $this->data = $data;
20 1
  }
21
22
  private function configureOptions(OptionsResolver $resolver, Generator $generator): void {
23 1
    foreach($generator->extensions as $extension) {
24 1
      $extension->configureItemOptions($resolver, $generator);
25
    }
26 1
  }
27
28
  public function toXml(\SimpleXMLElement &$element, Generator $generator): void {
29 1
    $resolver = new OptionsResolver();
30 1
    $this->configureOptions($resolver, $generator);
31 1
    $data = $resolver->resolve($this->data);
32 1
    foreach($data as $key => $value) {
33 1
      if($value === "") {
34 1
        continue;
35
      }
36 1
      if(!$value instanceof IXmlConvertible) {
37 1
        $value = new GenericElement($key, $value);
38
      }
39 1
      $value->appendToXml($element);
40
    }
41 1
  }
42
}
43
?>