• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Cecilapp / Cecil / 5046064611

pending completion
5046064611

push

github

GitHub
perf: native_function_invocation (#1697)

322 of 322 new or added lines in 62 files covered. (100.0%)

2784 of 4121 relevant lines covered (67.56%)

0.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.33
/src/Generator/Homepage.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of Cecil.
7
 *
8
 * Copyright (c) Arnaud Ligny <arnaud@ligny.fr>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13

14
namespace Cecil\Generator;
15

16
use Cecil\Collection\Page\Page;
17
use Cecil\Collection\Page\Type;
18
use Cecil\Exception\RuntimeException;
19

20
/**
21
 * Class Generator\Homepage.
22
 */
23
class Homepage extends AbstractGenerator implements GeneratorInterface
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function generate(): void
29
    {
30
        foreach ($this->config->getLanguages() as $lang) {
1✔
31
            $language = $lang['code'];
1✔
32
            $pageId = 'index';
1✔
33
            if ($language != $this->config->getLanguageDefault()) {
1✔
34
                $pageId = sprintf('index.%s', $language);
1✔
35
            }
36
            // creates a new index page...
37
            $page = (new Page($pageId))->setPath('')->setVariable('title', 'Home');
1✔
38
            // ... clones it if already exists
39
            if ($this->builder->getPages()->has($pageId)) {
1✔
40
                $page = clone $this->builder->getPages()->get($pageId);
1✔
41
            }
42
            /** @var \Cecil\Collection\Page\Page $page */
43
            $page->setType(Type::HOMEPAGE);
1✔
44
            // collects all pages
45
            $subPages = $this->builder->getPages()->filter(function (Page $page) use ($language) {
1✔
46
                return $page->getType() == TYPE::PAGE
1✔
47
                    && $page->isVirtual() === false
1✔
48
                    && $page->getVariable('exclude') !== true
1✔
49
                    && $page->getVariable('language') == $language;
1✔
50
            });
1✔
51
            // collects pages of a section
52
            /** @var \Cecil\Collection\Page\Collection $subPages */
53
            if ($page->hasVariable('pagesfrom') && $this->builder->getPages()->has((string) $page->getVariable('pagesfrom'))) {
1✔
54
                $subPages = $this->builder->getPages()->get((string) $page->getVariable('pagesfrom'))->getPages();
×
55
            }
56
            if ($subPages instanceof \Cecil\Collection\Page\Collection) {
1✔
57
                // sorts
58
                $pages = $subPages->sortByDate();
1✔
59
                if ($page->hasVariable('sortby')) {
1✔
60
                    $sortMethod = sprintf('sortBy%s', ucfirst((string) $page->getVariable('sortby')));
×
61
                    if (!method_exists($pages, $sortMethod)) {
×
62
                        throw new RuntimeException(sprintf('In page "%s" "%s" is not a valid value for "sortby" variable.', $page->getId(), $page->getVariable('sortby')));
×
63
                    }
64
                    $pages = $pages->$sortMethod();
×
65
                }
66
                $page->setPages($pages);
1✔
67
                if ($pages->first()) {
1✔
68
                    $page->setVariable('date', $pages->first()->getVariable('date'));
1✔
69
                }
70
            }
71
            // set default "main" menu
72
            if (!$page->getVariable('menu')) {
1✔
73
                $page->setVariable('menu', ['main' => ['weight' => 0]]);
1✔
74
            }
75
            $this->generatedPages->add($page);
1✔
76
        }
77
    }
78
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc