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

Cecilapp / Cecil / 21667157519

04 Feb 2026 10:05AM UTC coverage: 82.582% (-0.02%) from 82.602%
21667157519

push

github

ArnaudLigny
refactor: use Adler-32 hash for build ID

Replace the timestamp-based build ID (date('YmdHis')) with an Adler-32 hash of the timestamp to produce a fixed-length identifier. Also update the getBuildId docblock to remove the '(date)' note. This normalizes the build ID format and avoids exposing the raw timestamp.

1 of 1 new or added line in 1 file covered. (100.0%)

11 existing lines in 1 file now uncovered.

3314 of 4013 relevant lines covered (82.58%)

0.83 hits per line

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

74.51
/src/Collection/Page/Collection.php
1
<?php
2

3
/**
4
 * This file is part of Cecil.
5
 *
6
 * (c) Arnaud Ligny <arnaud@ligny.fr>
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\Collection\Page;
15

16
use Cecil\Collection\Collection as CecilCollection;
17
use Cecil\Exception\RuntimeException;
18

19
/**
20
 * Pages collection class.
21
 *
22
 * Represents a collection of pages, providing methods to filter and sort them.
23
 */
24
class Collection extends CecilCollection
25
{
26
    /**
27
     * Returns all "showable" pages.
28
     */
29
    public function showable(array $includeStatus = []): self
30
    {
31
        return $this->filter(function (Page $page) use ($includeStatus) {
1✔
32
            // check if page status should be explicitly included
33
            $statusIncluded = \in_array($page->getVariable('status'), $includeStatus, true);
1✔
34

35
            // standard showable criteria, with optional status-based inclusion
36
            if (
37
                (
38
                    $page->getVariable('published') === true  // page is published
1✔
39
                    || $statusIncluded                          // or explicitly included by status
1✔
40
                )
41
                && (
42
                    $page->getVariable('excluded') !== true   // and page is listed
1✔
43
                    && $page->getVariable('exclude') !== true   // and backward compatibility
1✔
44
                )
45
                && $page->isVirtual() === false               // and page is created from a file
1✔
46
                && $page->getVariable('redirect') === null    // and page is not a redirection
1✔
47
            ) {
48
                return true;
1✔
49
            }
50
            return false;
1✔
51
        });
1✔
52
    }
53

54
    /**
55
     * Alias of showable().
56
     */
57
    public function all(array $includeStatus = []): self
58
    {
59
        return $this->showable($includeStatus);
×
60
    }
61

62
    /**
63
     * Alias of showable().
64
     */
65
    public function public(array $includeStatus = []): self
66
    {
UNCOV
67
        return $this->showable($includeStatus);
×
68
    }
69

70
    /**
71
     * Sorts pages by.
72
     *
73
     * $options:
74
     * [date|updated|title|weight]
75
     * or
76
     * [
77
     *   variable   => date|updated|title|weight
78
     *   desc_title => false|true
79
     *   reverse    => false|true
80
     * ]
81
     */
82
    public function sortBy(string|array|null $options): self
83
    {
84
        $sortBy = \is_string($options) ? $options : $options['variable'] ?? 'date';
1✔
85
        $sortMethod = \sprintf('sortBy%s', ucfirst(str_replace('updated', 'date', $sortBy)));
1✔
86
        if (!method_exists($this, $sortMethod)) {
1✔
UNCOV
87
            throw new RuntimeException(\sprintf('"%s" is not a valid value for `sortby` to sort collection "%s".', $sortBy, $this->getId()));
×
88
        }
89

90
        return $this->$sortMethod($options);
1✔
91
    }
92

93
    /**
94
     * Sorts pages by date (or 'updated'): the most recent first.
95
     */
96
    public function sortByDate(string|array|null $options = null): self
97
    {
98
        $opt = [];
1✔
99
        // backward compatibility (i.e. $options = 'updated')
100
        if (\is_string($options)) {
1✔
101
            $opt['variable'] = $options;
1✔
102
        }
103
        // options
104
        $opt['variable'] = $options['variable'] ?? 'date';
1✔
105
        $opt['descTitle'] = $options['descTitle'] ?? false;
1✔
106
        $opt['reverse'] = $options['reverse'] ?? false;
1✔
107
        // sort
108
        $pages = $this->usort(function ($a, $b) use ($opt) {
1✔
109
            if ($a[$opt['variable']] == $b[$opt['variable']]) {
1✔
110
                // if dates are equal and "descTitle" is true
111
                if ($opt['descTitle'] && (isset($a['title']) && isset($b['title']))) {
1✔
UNCOV
112
                    return strnatcmp($b['title'], $a['title']);
×
113
                }
114

115
                return 0;
1✔
116
            }
117

118
            return $a[$opt['variable']] > $b[$opt['variable']] ? -1 : 1;
1✔
119
        });
1✔
120
        if ($opt['reverse']) {
1✔
UNCOV
121
            $pages = $pages->reverse();
×
122
        }
123

124
        return $pages;
1✔
125
    }
126

127
    /**
128
     * Sorts pages by title (natural sort).
129
     */
130
    public function sortByTitle(string|array|null $options = null): self
131
    {
132
        $opt = [];
1✔
133
        // options
134
        $opt['reverse'] = $options['reverse'] ?? false;
1✔
135
        // sort
136
        return $this->usort(function ($a, $b) use ($opt) {
1✔
137
            return ($opt['reverse'] ? -1 : 1) * strnatcmp($a['title'], $b['title']);
1✔
138
        });
1✔
139
    }
140

141
    /**
142
     * Sorts by weight (the heaviest first).
143
     */
144
    public function sortByWeight(string|array|null $options = null): self
145
    {
UNCOV
146
        $opt = [];
×
147
        // options
148
        $opt['reverse'] = $options['reverse'] ?? false;
×
149
        // sort
UNCOV
150
        return $this->usort(function ($a, $b) use ($opt) {
×
UNCOV
151
            if ($a['weight'] == $b['weight']) {
×
UNCOV
152
                return 0;
×
153
            }
154

UNCOV
155
            return ($opt['reverse'] ? -1 : 1) * ($a['weight'] < $b['weight'] ? -1 : 1);
×
UNCOV
156
        });
×
157
    }
158

159
    /**
160
     * {@inheritdoc}
161
     */
162
    public function get(string $id): Page
163
    {
164
        return parent::get($id);
1✔
165
    }
166

167
    /**
168
     * {@inheritdoc}
169
     */
170
    public function first(): ?Page
171
    {
172
        return parent::first();
1✔
173
    }
174

175
    /**
176
     * {@inheritdoc}
177
     */
178
    public function filter(\Closure $callback): self
179
    {
180
        return parent::filter($callback);
1✔
181
    }
182

183
    /**
184
     * {@inheritdoc}
185
     */
186
    public function usort(?\Closure $callback = null): self
187
    {
188
        return parent::usort($callback);
1✔
189
    }
190

191
    /**
192
     * {@inheritdoc}
193
     */
194
    public function reverse(): self
195
    {
UNCOV
196
        return parent::reverse();
×
197
    }
198
}
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