FeedGenerator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getXml() 0 13 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: ninoskopac
5
 * Date: 01/05/2018
6
 * Time: 23:11
7
 */
8
declare(strict_types=1);
9
namespace iTunesPodcastFeed;
10
11
use iTunesPodcastFeed\Interfaces\Channel as ChannelInterface;
12
use iTunesPodcastFeed\Interfaces\FeedGenerator as FeedGeneratorInterface;
13
use iTunesPodcastFeed\Interfaces\Item as ItemInterface;
14
15
class FeedGenerator implements FeedGeneratorInterface
16
{
17
    /**
18
     * @var ChannelInterface
19
     */
20
    private $config;
21
    /**
22
     * @var ItemInterface[]
23
     */
24
    private $items;
25
26
    /**
27
     * FeedGenerator constructor.
28
     *
29
     * @param ChannelInterface $config
30
     * @param ItemInterface[] $items
31
     */
32
    public function __construct(ChannelInterface $config, ItemInterface ...$items)
33
    {
34
        $this->config = $config;
35
        $this->items = $items;
36
    }
37
38
    /**
39
     * @return string
40
     */
41
    public function getXml(): string
42
    {
43
        $template = file_get_contents(__DIR__ . '/templates/feed.xml');
44
        $template = str_replace('{{channelMeta}}', $this->config->getXml(), $template);
45
        $itemsXml = '';
46
47
        foreach ($this->items as $item) {
48
            $itemsXml .= $item->getXml() . "\n";
49
        }
50
51
        $template = str_replace('{{items}}', $itemsXml, $template);
52
53
        return $template;
54
    }
55
}