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

Cecilapp / Cecil / 7340760138

27 Dec 2023 06:03PM UTC coverage: 83.42% (+0.01%) from 83.406%
7340760138

push

github

ArnaudLigny
refactor: code quality

8 of 8 new or added lines in 6 files covered. (100.0%)

1 existing line in 1 file now uncovered.

2878 of 3450 relevant lines covered (83.42%)

0.83 hits per line

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

86.96
/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
        // If it's a built-in variable: dot not fetchs data from config raw
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✔
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 for the provided language or the current one provided.
121
     *
122
     * @throws \DomainException
123
     */
124
    public function getPage(string $id, string $language = null): ?CollectionPage
125
    {
126
        $pageId = $id;
1✔
127
        $language = $language ?? $this->language;
1✔
128

129
        if ($language !== null && $language != $this->config->getLanguageDefault()) {
1✔
130
            $pageId = "$language/$id";
1✔
131
        }
132

133
        if ($this->builder->getPages()->has($pageId) === false) {
1✔
134
            // if multilingual == false
135
            if ($this->builder->getPages()->has($id) && $this->builder->getPages()->get($id)->getVariable('multilingual') === false) {
1✔
136
                return $this->builder->getPages()->get($id);
×
137
            }
138

139
            return null;
1✔
140
        }
141

142
        return $this->builder->getPages()->get($pageId);
1✔
143
    }
144

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

159
            return $page->getVariable('language') == $this->language;
1✔
160
        });
1✔
161
    }
162

163
    /**
164
     * Returns all pages, regardless of their translation.
165
     */
166
    public function getAllPages(): \Cecil\Collection\Page\Collection
167
    {
168
        return $this->builder->getPages();
1✔
169
    }
170

171
    /**
172
     * Alias of getAllPages().
173
     */
174
    public function getPagesIntl(): \Cecil\Collection\Page\Collection
175
    {
176
        return $this->getAllPages();
×
177
    }
178

179
    /**
180
     * Returns current time.
181
     */
182
    public function getTime(): int
183
    {
184
        return time();
1✔
185
    }
186

187
    /**
188
     * Returns the property value(s) of an output format.
189
     */
190
    public function getOutputProperty(string $name, string $property): string|array|null
191
    {
192
        return $this->config->getOutputFormatProperty($name, $property);
1✔
193
    }
194
}
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