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

Cecilapp / Cecil / 15735686664

18 Jun 2025 02:29PM UTC coverage: 82.609% (-0.02%) from 82.627%
15735686664

push

github

ArnaudLigny
refactor: code quality

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

79 existing lines in 5 files now uncovered.

3116 of 3772 relevant lines covered (82.61%)

0.83 hits per line

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

60.42
/src/Step/Pages/Load.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\Step\Pages;
15

16
use Cecil\Step\AbstractStep;
17
use Cecil\Util;
18
use Symfony\Component\Finder\Finder;
19
use Symfony\Component\Finder\SplFileInfo;
20

21
/**
22
 * Load pages step.
23
 *
24
 * This step is responsible for loading pages from the configured pages directory.
25
 * It initializes the pages finder, applies sorting, and filters based on the
26
 * specified page or the default configuration. It also handles exclusions and
27
 * respects the `.gitignore` file if present. The loaded pages are then set in
28
 * the builder for further processing.
29
 */
30
class Load extends AbstractStep
31
{
32
    /** @var string */
33
    protected $page;
34

35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function getName(): string
39
    {
40
        return 'Loading pages';
1✔
41
    }
42

43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function init(array $options): void
47
    {
48
        if (!is_dir($this->config->getPagesPath())) {
1✔
UNCOV
49
            $this->builder->getLogger()->debug(\sprintf('"%s" is not a valid pages directory', $this->config->getPagesPath()));
×
50
            $this->canProcess = false;
×
51

UNCOV
52
            return;
×
53
        }
54

55
        $this->page = $options['page'];
1✔
56
        $this->canProcess = true;
1✔
57
    }
58

59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function process(): void
63
    {
64
        $namePattern = '/\.(' . implode('|', (array) $this->config->get('pages.ext')) . ')$/';
1✔
65
        $pages = Finder::create()
1✔
66
            ->files()
1✔
67
            ->in($this->config->getPagesPath())
1✔
68
            ->sort(function (SplFileInfo $a, SplFileInfo $b): int {
1✔
69
                // section's index first
70
                if ($a->getRelativePath() == $b->getRelativePath() && $a->getBasename('.' . $a->getExtension()) == 'index') {
1✔
71
                    return -1;
1✔
72
                }
73
                if ($b->getRelativePath() == $a->getRelativePath() && $b->getBasename('.' . $b->getExtension()) == 'index') {
1✔
74
                    return 1;
1✔
75
                }
76
                // sort by name
77
                return strnatcasecmp($a->getRealPath(), $b->getRealPath());
1✔
78
            });
1✔
79
        // load only one page?
80
        if ($this->page) {
1✔
81
            // is the page path starts with the `pages.dir` configuration option?
82
            // (i.e.: `pages/...`, `/pages/...`, `./pages/...`)
UNCOV
83
            $pagePathAsArray = explode(DIRECTORY_SEPARATOR, Util::joinFile($this->page));
×
84
            if ($pagePathAsArray[0] == (string) $this->config->get('pages.dir')) {
×
85
                unset($pagePathAsArray[0]);
×
86
                $this->page = implode(DIRECTORY_SEPARATOR, $pagePathAsArray);
×
87
            }
UNCOV
88
            if ($pagePathAsArray[0] == '.' && $pagePathAsArray[1] == (string) $this->config->get('pages.dir')) {
×
89
                unset($pagePathAsArray[0]);
×
90
                unset($pagePathAsArray[1]);
×
91
                $this->page = implode(DIRECTORY_SEPARATOR, $pagePathAsArray);
×
92
            }
UNCOV
93
            if (!util\File::getFS()->exists(Util::joinFile($this->config->getPagesPath(), $this->page))) {
×
94
                $this->builder->getLogger()->error(\sprintf('File "%s" doesn\'t exist.', $this->page));
×
95
            }
UNCOV
96
            $pages->path('.')->path(\dirname($this->page));
×
97
            $pages->name('/index\.(' . implode('|', (array) $this->config->get('pages.ext')) . ')$/');
×
98
            $namePattern = basename($this->page);
×
99
        }
100
        $pages->name($namePattern);
1✔
101
        if (\is_array($exclude = $this->config->get('pages.exclude'))) {
1✔
102
            $pages->exclude($exclude);
1✔
103
            $pages->notPath($exclude);
1✔
104
            $pages->notName($exclude);
1✔
105
        }
106
        if (file_exists(Util::joinFile($this->config->getPagesPath(), '.gitignore'))) {
1✔
UNCOV
107
            $pages->ignoreVCSIgnored(true);
×
108
        }
109
        $this->builder->setPagesFiles($pages);
1✔
110

111
        $total = $pages->count();
1✔
112
        $count = 0;
1✔
113
        if ($total === 0) {
1✔
UNCOV
114
            $this->builder->getLogger()->info('Nothing to load');
×
115

UNCOV
116
            return;
×
117
        }
118
        foreach ($pages as $file) {
1✔
119
            $count++;
1✔
120
            $this->builder->getLogger()->info(\sprintf('File "%s" loaded', $file->getRelativePathname()), ['progress' => [$count, $total]]);
1✔
121
        }
122
    }
123
}
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