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

Cecilapp / Cecil / 6764522451

05 Nov 2023 11:54PM UTC coverage: 82.208%. First build
6764522451

Pull #1833

github

web-flow
Merge f7b3e3c81 into 8587b51d0
Pull Request #1833: feat: new `site.debug` variable

2 of 3 new or added lines in 1 file covered. (66.67%)

2837 of 3451 relevant lines covered (82.21%)

0.82 hits per line

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

88.37
/src/Renderer/Site.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\Renderer;
15

16
use Cecil\Builder;
17
use Cecil\Collection\Page\Page as CollectionPage;
18

19
/**
20
 * Class Site.
21
 */
22
class Site implements \ArrayAccess
23
{
24
    /** @var Builder Builder object. */
25
    protected $builder;
26

27
    /** @var \Cecil\Config */
28
    protected $config;
29

30
    /** @var string Current language. */
31
    protected $language;
32

33
    public function __construct(Builder $builder, string $language)
34
    {
35
        $this->builder = $builder;
1✔
36
        $this->config = $this->builder->getConfig();
1✔
37
        $this->language = $language;
1✔
38
    }
39

40
    /**
41
     * Implement ArrayAccess.
42
     *
43
     * @param mixed $offset
44
     *
45
     * @return bool
46
     */
47
    #[\ReturnTypeWillChange]
48
    public function offsetExists($offset): bool
49
    {
50
        // special cases
51
        switch ($offset) {
52
            case 'menus':
1✔
53
            case 'home':
1✔
54
            case 'debug':
1✔
55
                return true;
1✔
56
        }
57

58
        return $this->config->has($offset);
1✔
59
    }
60

61
    /**
62
     * Implements \ArrayAccess.
63
     *
64
     * @param mixed $offset
65
     *
66
     * @return mixed|null
67
     */
68
    #[\ReturnTypeWillChange]
69
    public function offsetGet($offset)
70
    {
71
        // Fetchs data from builder instead of config raw data
72
        switch ($offset) {
73
            case 'pages':
1✔
74
                return $this->getPages();
1✔
75
            case 'menus':
1✔
76
                return $this->builder->getMenus($this->language);
1✔
77
            case 'taxonomies':
1✔
78
                return $this->builder->getTaxonomies($this->language);
1✔
79
            case 'data':
1✔
80
                return $this->builder->getData();
1✔
81
            case 'static':
1✔
82
                return $this->builder->getStatic();
1✔
83
            case 'language':
1✔
84
                return new Language($this->config, $this->language);
1✔
85
            case 'home':
1✔
86
                return 'index';
1✔
87
            case 'debug':
1✔
NEW
88
                return $this->builder->isDebug();
×
89
        }
90

91
        return $this->config->get($offset, $this->language);
1✔
92
    }
93

94
    /**
95
     * Implements \ArrayAccess.
96
     *
97
     * @param mixed $offset
98
     * @param mixed $value
99
     *
100
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
101
     */
102
    #[\ReturnTypeWillChange]
103
    public function offsetSet($offset, $value): void
104
    {
105
    }
×
106

107
    /**
108
     * Implements \ArrayAccess.
109
     *
110
     * @param mixed $offset
111
     *
112
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
113
     */
114
    #[\ReturnTypeWillChange]
115
    public function offsetUnset($offset): void
116
    {
117
    }
×
118

119
    /**
120
     * Returns a page in the current language or the one provided.
121
     *
122
     * @throws \DomainException
123
     */
124
    public function getPage(string $id, string $language = null): ?CollectionPage
125
    {
126
        $pageId = $id;
1✔
127
        if ($language === null && $this->language != $this->config->getLanguageDefault()) {
1✔
128
            $pageId = sprintf('%s/%s', $this->language, $id);
1✔
129
        }
130
        if ($language !== null && $language != $this->config->getLanguageDefault()) {
1✔
131
            $pageId = "$language/$id";
1✔
132
        }
133

134
        if ($this->builder->getPages()->has($pageId) === false) {
1✔
135
            return null;
1✔
136
        }
137

138
        return $this->builder->getPages()->get($pageId);
1✔
139
    }
140

141
    /**
142
     * Returns all pages, in the current language.
143
     */
144
    public function getPages(): \Cecil\Collection\Page\Collection
145
    {
146
        return $this->builder->getPages()->filter(function (CollectionPage $page) {
1✔
147
            // We should fix case of virtual pages without language
148
            if ($page->getVariable('language') === null && $this->language == $this->config->getLanguageDefault()) {
1✔
149
                return true;
×
150
            }
151

152
            return $page->getVariable('language') == $this->language;
1✔
153
        });
1✔
154
    }
155

156
    /**
157
     * Returns all pages, regardless of their translation.
158
     */
159
    public function getAllPages(): \Cecil\Collection\Page\Collection
160
    {
161
        return $this->builder->getPages();
1✔
162
    }
163

164
    /**
165
     * Alias of getAllPages().
166
     */
167
    public function getPagesIntl(): \Cecil\Collection\Page\Collection
168
    {
169
        return $this->getAllPages();
×
170
    }
171

172
    /**
173
     * Return current time.
174
     */
175
    public function getTime(): int
176
    {
177
        return time();
1✔
178
    }
179
}
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