Redirect   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 17
ccs 9
cts 9
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 12 3
1
<?php
2
3
/**
4
 * This file is part of Cecil.
5
 *
6
 * (c) Arnaud Ligny <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Cecil\Generator;
15
16
use Cecil\Collection\Page\Page;
17
18
/**
19
 * Redirect generator class.
20
 *
21
 * This class is responsible for generating redirect pages based on the
22
 * 'redirect' variable set in the pages. It filters the pages to find those
23
 * that have a 'redirect' variable defined and creates a new page with the
24
 * 'layout' set to 'redirect'. The generated pages are then added to the
25
 * collection of generated pages.
26
 */
27
class Redirect extends AbstractGenerator implements GeneratorInterface
28
{
29
    /**
30
     * {@inheritdoc}
31
     */
32 1
    public function generate(): void
33
    {
34 1
        $filteredPages = $this->builder->getPages()->filter(function (Page $page) {
35 1
            return $page->getVariable('redirect') !== null
36 1
                && $page->getVariable('layout') != 'redirect';
37 1
        });
38
39
        /** @var Page $page */
40 1
        foreach ($filteredPages as $page) {
41 1
            $alteredPage = clone $page;
42 1
            $alteredPage->setVariable('layout', 'redirect');
43 1
            $this->generatedPages->add($alteredPage);
44
        }
45
    }
46
}
47