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

Cecilapp / Cecil / 21911121390

11 Feb 2026 03:24PM UTC coverage: 77.135% (-5.2%) from 82.346%
21911121390

push

github

web-flow
Parallelize page conversion using pcntl (#2313)

Add optional parallel processing to the Convert step by forking worker processes with pcntl_fork. The change: detect pcntl availability and run processParallel(), otherwise fall back to the original sequential processing (processSequential()). Each child converts a chunk of pages and writes serializable results to a temp file; the parent waits for children, reads results, applies front-matter/HTML updates, and removes pages on errors. Concurrency is chosen based on CPU count (getConcurrency). Child processes silence logging with a NullLogger to avoid output conflicts. Also introduce helper methods convertChunk, applyChunkResults and getConcurrency, and add a NullLogger import.

---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ArnaudLigny <80580+ArnaudLigny@users.noreply.github.com>

81 of 132 new or added lines in 4 files covered. (61.36%)

190 existing lines in 7 files now uncovered.

3198 of 4146 relevant lines covered (77.13%)

0.77 hits per line

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

87.67
/src/Util.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;
15

16
use Symfony\Component\Filesystem\Path;
17

18
/**
19
 * Utility class.
20
 *
21
 * Provides various utility methods for formatting class names, method names,
22
 * joining paths, converting memory sizes, and more.
23
 */
24
class Util
25
{
26
    /**
27
     * Formats a class name.
28
     *
29
     * ie: "Cecil\Step\OptimizeHtml" become "OptimizeHtml"
30
     *
31
     * @param object $class
32
     */
33
    public static function formatClassName($class, array $options = []): string
34
    {
35
        $lowercase = false;
1✔
36
        extract($options, EXTR_IF_EXISTS);
1✔
37

38
        $className = substr(strrchr(\get_class($class), '\\'), 1);
1✔
39
        if ($lowercase) {
1✔
40
            $className = strtolower($className);
1✔
41
        }
42

43
        return $className;
1✔
44
    }
45

46
    /**
47
     * Formats a method name.
48
     *
49
     * ie: "Cecil\Renderer\Extension\Core::asset()" become "asset()"
50
     *
51
     * @param string $method
52
     */
53
    public static function formatMethodName(string $method): string
54
    {
55
        $methodName = explode('::', $method)[1];
×
56

57
        return $methodName;
×
58
    }
59

60
    /**
61
     * Converts an array of strings into a path.
62
     */
63
    public static function joinPath(string ...$path): string
64
    {
65
        $path = array_filter($path, function ($path) {
1✔
66
            return !empty($path) && !\is_null($path);
1✔
67
        });
1✔
68
        array_walk($path, function (&$value, $key) {
1✔
69
            $value = str_replace('\\', '/', $value);
1✔
70
            $value = rtrim($value, '/');
1✔
71
            $value = $key == 0 ? $value : ltrim($value, '/');
1✔
72
        });
1✔
73

74
        return Path::canonicalize(implode('/', $path));
1✔
75
    }
76

77
    /**
78
     * Converts an array of strings into a system path.
79
     */
80
    public static function joinFile(string ...$path): string
81
    {
82
        array_walk($path, function (&$value, $key) use (&$path) {
1✔
83
            $value = str_replace(['\\', '/'], [DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR], $value);
1✔
84
            $value = rtrim($value, DIRECTORY_SEPARATOR);
1✔
85
            $value = $key == 0 ? $value : ltrim($value, DIRECTORY_SEPARATOR);
1✔
86
            // unset entry with empty value
87
            if (empty($value)) {
1✔
88
                unset($path[$key]);
1✔
89
            }
90
        });
1✔
91

92
        return implode(DIRECTORY_SEPARATOR, $path);
1✔
93
    }
94

95
    /**
96
     * Converts memory size for human.
97
     */
98
    public static function convertMemory($size): string
99
    {
100
        if ($size === 0) {
1✔
101
            return '0';
×
102
        }
103
        $unit = ['b', 'kb', 'mb', 'gb', 'tb', 'pb'];
1✔
104

105
        return \sprintf('%s %s', round($size / pow(1024, $i = floor(log($size, 1024))), 2), $unit[$i]);
1✔
106
    }
107

108
    /**
109
     * Converts microtime interval for human.
110
     */
111
    public static function convertMicrotime(float $start): string
112
    {
113
        $time = microtime(true) - $start;
1✔
114
        if ($time < 1) {
1✔
115
            return \sprintf('%s ms', round($time * 1000, 0));
1✔
116
        }
117

118
        return \sprintf('%s s', round($time, 2));
1✔
119
    }
120

121
    /**
122
     * Loads class from the source directory, in the given subdirectory $dir.
123
     */
124
    public static function autoload(Builder $builder, string $dir): void
125
    {
126
        spl_autoload_register(function ($className) use ($builder, $dir) {
1✔
127
            $classFile = Util::joinFile($builder->getConfig()->getSourceDir(), $dir, "$className.php");
1✔
128
            if (is_readable($classFile)) {
1✔
129
                require $classFile;
1✔
130
                return;
1✔
131
            }
132
            // in themes
133
            foreach ($builder->getConfig()->getTheme() ?? [] as $theme) {
1✔
134
                $classFile = Util::joinFile($builder->getConfig()->getThemeDirPath($theme, $dir), "$className.php");
1✔
135
                if (is_readable($classFile)) {
1✔
136
                    require $classFile;
×
137
                    return;
×
138
                }
139
            }
140
        });
1✔
141
    }
142

143
    /**
144
     * Matches a URL against known embedded content patterns.
145
     * Supports YouTube, Vimeo, Dailymotion, and GitHub Gists.
146
     *
147
     * @param string $url The URL to check
148
     *
149
     * @return array|false An associative array with 'type' and 'url' keys if a match is found, or false otherwise
150
     */
151
    public static function matchesUrlPattern(string $url): array|false
152
    {
153
        $services = [
1✔
154
            'youtube' => [
1✔
155
                // https://regex101.com/r/gznM1j/1
156
                'pattern' => '(?:https?:\/\/)?(?:www\.)?youtu(?:\.be\/|be.com\/\S*(?:watch|embed)(?:(?:(?=\/[-a-zA-Z0-9_]{11,}(?!\S))\/)|(?:\S*v=|v\/)))([-a-zA-Z0-9_]{11,})',
1✔
157
                'baseurl' => 'https://www.youtube-nocookie.com/embed/',
1✔
158
                'type' => 'video',
1✔
159
            ],
1✔
160
            'vimeo' => [
1✔
161
                // https://regex101.com/r/wCEFhd/1
162
                'pattern' => 'https:\/\/vimeo\.com\/([0-9]+)',
1✔
163
                'baseurl' => 'https://player.vimeo.com/video/',
1✔
164
                'type' => 'video',
1✔
165
            ],
1✔
166
            'dailymotion' => [
1✔
167
                // https://regex101.com/r/YKnLPm/1
168
                'pattern' => '(?:https?:\/\/)?(?:www\.)?dailymotion\.com\/video\/([a-z0-9]+)',
1✔
169
                'baseurl' => 'https://geo.dailymotion.com/player.html?video=',
1✔
170
                'type' => 'video',
1✔
171
            ],
1✔
172
            'github_gist' => [
1✔
173
                // https://regex101.com/r/y3bm2M/1
174
                'pattern' => 'https:\/\/gist\.github\.com\/([-a-zA-Z0-9_]+\/[-a-zA-Z0-9_]+)',
1✔
175
                'baseurl' => 'https://gist.github.com/',
1✔
176
                'type' => 'script',
1✔
177
            ],
1✔
178
        ];
1✔
179

180
        foreach ($services as $service) {
1✔
181
            if (preg_match('/' . $service['pattern'] . '/is', $url, $matches)) {
1✔
UNCOV
182
                return [
×
UNCOV
183
                    'type' => $service['type'],
×
UNCOV
184
                    'url' => $service['baseurl'] . $matches[1],
×
UNCOV
185
                ];
×
186
            }
187
        }
188

189
        return false;
1✔
190
    }
191
}
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