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

Cecilapp / Cecil / 5046064611

pending completion
5046064611

push

github

GitHub
perf: native_function_invocation (#1697)

322 of 322 new or added lines in 62 files covered. (100.0%)

2784 of 4121 relevant lines covered (67.56%)

0.68 hits per line

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

53.85
/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
        // legacy support
43
        if (is_dir(Util::joinFile($this->config->getSourceDir(), 'content'))) {
1✔
44
            $this->builder->getLogger()->alert('"content" directory is deprecated, please rename it to "pages"');
×
45
        }
46

47
        if (!is_dir($this->config->getPagesPath())) {
1✔
48
            throw new RuntimeException(sprintf('Pages path "%s" not found.', $this->config->getPagesPath()));
×
49
        }
50

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

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

97
        $count = $content->count();
1✔
98
        if ($count === 0) {
1✔
99
            $this->builder->getLogger()->info('Nothing to load');
×
100

101
            return;
×
102
        }
103
        $this->builder->getLogger()->info('Files loaded', ['progress' => [$count, $count]]);
1✔
104
    }
105
}
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