Completed
Push — include-lib ( fd24a6...4173d3 )
by Arnaud
13:24
created

Redirect   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 18 2
1
<?php
2
/*
3
 * Copyright (c) Arnaud Ligny <[email protected]>
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Cecil\Generator;
10
11
use Cecil\Collection\Collection as PageCollection;
12
use Cecil\Collection\Page\Page;
13
14
/**
15
 * Class TitleReplace.
16
 */
17
class Redirect extends AbstractGenerator implements GeneratorInterface
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function generate(PageCollection $pageCollection, \Closure $messageCallback)
23
    {
24
        $generatedPages = new PageCollection();
25
26
        $filteredPages = $pageCollection->filter(function (Page $page) {
27
            return null !== $page->getVariable('redirect');
28
        });
29
30
        /* @var $page Page */
31
        foreach ($filteredPages as $page) {
32
            $alteredPage = clone $page;
33
            $alteredPage->setLayout('redirect.html');
34
            $alteredPage->setVariable('destination', $page->getVariable('redirect'));
35
            $generatedPages->add($alteredPage);
36
        }
37
38
        return $generatedPages;
39
    }
40
}
41