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

Cecilapp / Cecil / 7135108204

07 Dec 2023 11:10PM UTC coverage: 82.976% (+0.4%) from 82.534%
7135108204

Pull #1676

github

web-flow
Merge ce0d85209 into 814daa587
Pull Request #1676: 8.x dev

184 of 222 new or added lines in 31 files covered. (82.88%)

15 existing lines in 5 files now uncovered.

2861 of 3448 relevant lines covered (82.98%)

0.83 hits per line

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

54.05
/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

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

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

37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function init(array $options): void
41
    {
42
        if (!is_dir($this->config->getPagesPath())) {
1✔
UNCOV
43
            throw new RuntimeException(sprintf('Pages path "%s" not found.', $this->config->getPagesPath()));
×
44
        }
45

46
        $this->page = $options['page'];
1✔
47
        $this->canProcess = true;
1✔
48
    }
49

50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function process(): void
54
    {
55
        $namePattern = '/\.(' . implode('|', (array) $this->config->get('pages.ext')) . ')$/';
1✔
56
        $content = Finder::create()
1✔
57
            ->files()
1✔
58
            ->in($this->config->getPagesPath())
1✔
59
            ->sortByName(true);
1✔
60
        // load only one page?
61
        if ($this->page) {
1✔
62
            // is the page path starts with the `pages.dir` configuration option?
63
            // (i.e.: `pages/...`, `/pages/...`, `./pages/...`)
64
            $pagePathAsArray = explode(DIRECTORY_SEPARATOR, Util::joinFile($this->page));
×
65
            if ($pagePathAsArray[0] == (string) $this->config->get('pages.dir')) {
×
66
                unset($pagePathAsArray[0]);
×
67
                $this->page = implode(DIRECTORY_SEPARATOR, $pagePathAsArray);
×
68
            }
69
            if ($pagePathAsArray[0] == '.' && $pagePathAsArray[1] == (string) $this->config->get('pages.dir')) {
×
70
                unset($pagePathAsArray[0]);
×
71
                unset($pagePathAsArray[1]);
×
72
                $this->page = implode(DIRECTORY_SEPARATOR, $pagePathAsArray);
×
73
            }
74
            if (!util\File::getFS()->exists(Util::joinFile($this->config->getPagesPath(), $this->page))) {
×
75
                $this->builder->getLogger()->error(sprintf('File "%s" doesn\'t exist.', $this->page));
×
76
            }
77
            $content->path('.')->path(\dirname($this->page));
×
78
            $content->name('/index\.(' . implode('|', (array) $this->config->get('pages.ext')) . ')$/');
×
79
            $namePattern = basename($this->page);
×
80
        }
81
        $content->name($namePattern);
1✔
82
        if (\is_array($exclude = $this->config->get('pages.exclude'))) {
1✔
83
            $content->exclude($exclude);
1✔
84
            $content->notPath($exclude);
1✔
85
            $content->notName($exclude);
1✔
86
        }
87
        if (file_exists(Util::joinFile($this->config->getPagesPath(), '.gitignore'))) {
1✔
88
            $content->ignoreVCSIgnored(true);
×
89
        }
90
        $this->builder->setPagesFiles($content);
1✔
91

92
        $count = $content->count();
1✔
93
        if ($count === 0) {
1✔
94
            $this->builder->getLogger()->info('Nothing to load');
×
95

96
            return;
×
97
        }
98
        $this->builder->getLogger()->info('Files loaded', ['progress' => [$count, $count]]);
1✔
99
    }
100
}
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

© 2025 Coveralls, Inc