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

Cecilapp / Cecil / 13307234714

13 Feb 2025 12:03PM UTC coverage: 83.409% (-0.08%) from 83.484%
13307234714

push

github

web-flow
refactor: better log/console messages (#2117)

2 of 7 new or added lines in 4 files covered. (28.57%)

2951 of 3538 relevant lines covered (83.41%)

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
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\Step\Pages;
15

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

22
/**
23
 * Loads pages.
24
 */
25
class Load extends AbstractStep
26
{
27
    /** @var string */
28
    protected $page;
29

30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function getName(): string
34
    {
35
        return 'Loading pages';
1✔
36
    }
37

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

NEW
47
            return;
×
48
        }
49

50
        $this->page = $options['page'];
1✔
51
        $this->canProcess = true;
1✔
52
    }
53

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

106
        $total = $pages->count();
1✔
107
        $count = 0;
1✔
108
        if ($total === 0) {
1✔
109
            $this->builder->getLogger()->info('Nothing to load');
×
110

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