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

Cecilapp / Cecil / 6910181435

17 Nov 2023 11:34PM UTC coverage: 82.11% (-0.07%) from 82.181%
6910181435

push

github

ArnaudLigny
Merge branch 'master' of https://github.com/Cecilapp/Cecil

2818 of 3432 relevant lines covered (82.11%)

0.82 hits per line

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

85.42
/src/Generator/Taxonomy.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\Collection\Taxonomy\Vocabulary;
19

20
/**
21
 * Class Generator\Taxonomy.
22
 */
23
class Taxonomy 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
            if ($this->config->get('taxonomies', $language, false) && $this->builder->getTaxonomies($language) !== null) {
1✔
33
                /** @var Vocabulary $vocabulary */
34
                foreach ($this->builder->getTaxonomies($language) as $vocabulary) {
1✔
35
                    $plural = $vocabulary->getId();
1✔
36
                    $singular = $this->config->get("taxonomies.$plural", $language, false);
1✔
37
                    if (\count($vocabulary) > 0) {
1✔
38
                        $date = date('Y-m-d');
1✔
39
                        /*
40
                        * Creates $plural/$term pages (list of pages)
41
                        * e.g.: /tags/tag-1/
42
                        */
43
                        foreach ($vocabulary as $term) {
1✔
44
                            $pageId = $path = Page::slugify($term->getId());
1✔
45
                            if ($language != $this->config->getLanguageDefault()) {
1✔
46
                                $pageId = "$language/$pageId";
1✔
47
                            }
48
                            $pages = $term->sortByDate();
1✔
49
                            $date = $pages->first()->getVariable('date');
1✔
50
                            // creates page for each term
51
                            $page = (new Page($pageId))
1✔
52
                                ->setPath($path)
1✔
53
                                ->setVariable('title', $term->getName())
1✔
54
                                ->setVariable('date', $date)
1✔
55
                                ->setVariable('language', $language);
1✔
56
                            if ($this->builder->getPages()->has($pageId)) {
1✔
57
                                $page = clone $this->builder->getPages()->get($pageId);
×
58
                            }
59
                            $page->setType(Type::TERM)
1✔
60
                                ->setPages($pages)
1✔
61
                                ->setVariable('term', $term->getId())
1✔
62
                                ->setVariable('plural', $plural)
1✔
63
                                ->setVariable('singular', $singular);
1✔
64
                            $this->generatedPages->add($page);
1✔
65
                        }
66
                        /*
67
                        * Creates $plural pages (list of terms)
68
                        * e.g.: /tags/
69
                        */
70
                        $pageId = $path = Page::slugify($plural);
1✔
71
                        if ($language != $this->config->getLanguageDefault()) {
1✔
72
                            $pageId = "$language/$pageId";
1✔
73
                        }
74
                        $page = (new Page($pageId))->setVariable('title', ucfirst($plural))
1✔
75
                            ->setPath($path);
1✔
76
                        if ($this->builder->getPages()->has($pageId)) {
1✔
77
                            $page = clone $this->builder->getPages()->get($pageId);
×
78
                            $page->unSection();
×
79
                        }
80
                        // creates page for each plural
81
                        $page->setType(Type::VOCABULARY)
1✔
82
                            ->setPath($path)
1✔
83
                            ->setTerms($vocabulary)
1✔
84
                            ->setVariable('date', $date)
1✔
85
                            ->setVariable('language', $language)
1✔
86
                            ->setVariable('plural', $plural)
1✔
87
                            ->setVariable('singular', $singular);
1✔
88
                        // human readable title
89
                        if ($page->getVariable('title') == 'index') {
1✔
90
                            $page->setVariable('title', $plural);
×
91
                        }
92
                        // adds page only if a template exist
93
                        try {
94
                            $this->generatedPages->add($page);
1✔
95
                        } catch (\Exception $e) {
×
96
                            printf("%s\n", $e->getMessage());
×
97
                            unset($page); // do not adds page
×
98
                        }
99
                    }
100
                }
101
            }
102
        }
103
    }
104
}
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