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

Cecilapp / Cecil / 13786562850

11 Mar 2025 11:08AM UTC coverage: 82.938% (-0.5%) from 83.394%
13786562850

push

github

web-flow
Merge pull request #2133 from Cecilapp/cache

feat: better cache and Twig cache fragments

106 of 124 new or added lines in 11 files covered. (85.48%)

23 existing lines in 6 files now uncovered.

2970 of 3581 relevant lines covered (82.94%)

0.83 hits per line

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

80.77
/src/Step/Pages/Save.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\Collection\Page\Page;
17
use Cecil\Exception\RuntimeException;
18
use Cecil\Renderer\Page as PageRenderer;
19
use Cecil\Step\AbstractStep;
20
use Cecil\Util;
21

22
/**
23
 * Pages saving.
24
 */
25
class Save extends AbstractStep
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function getName(): string
31
    {
32
        return 'Saving pages';
1✔
33
    }
34

35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function init(array $options): void
39
    {
40
        if ($options['dry-run']) {
1✔
UNCOV
41
            return;
×
42
        }
43

44
        Util\File::getFS()->mkdir($this->config->getOutputPath());
1✔
45

46
        $this->canProcess = true;
1✔
47
    }
48

49
    /**
50
     * {@inheritdoc}
51
     *
52
     * @throws RuntimeException
53
     */
54
    public function process(): void
55
    {
56
        $filteredPages = $this->builder->getPages()->filter(function (Page $page) {
1✔
57
            return !empty($page->getRendered());
1✔
58
        });
1✔
59
        $total = \count($filteredPages);
1✔
60

61
        $count = 0;
1✔
62
        foreach ($filteredPages as $page) {
1✔
63
            $count++;
1✔
64
            $files = [];
1✔
65

66
            foreach ($page->getRendered() as $format => $rendered) {
1✔
67
                if (false === $pathname = (new PageRenderer($this->config))->getOutputFilePath($page, $format)) {
1✔
68
                    throw new RuntimeException(\sprintf("Can't get pathname of page '%s' (format: '%s').", $page->getId(), $format));
×
69
                }
70
                $pathname = $this->cleanPath(Util::joinFile($this->config->getOutputPath(), $pathname));
1✔
71

72
                try {
73
                    Util\File::getFS()->dumpFile($pathname, $rendered['output']);
1✔
74
                } catch (\Symfony\Component\Filesystem\Exception\IOException $e) {
×
75
                    throw new RuntimeException($e->getMessage());
×
76
                }
77

78
                $files[] = $this->builder->isDebug() ? $pathname : substr($pathname, \strlen($this->config->getDestinationDir()) + 1);
1✔
79
            }
80

81
            $message = \sprintf('File(s) "%s" saved', implode(', ', $files));
1✔
82
            $this->builder->getLogger()->info($message, ['progress' => [$count, $total]]);
1✔
83
        }
84
    }
85

86
    /**
87
     * Removes unnecessary directory separators.
88
     */
89
    private function cleanPath(string $pathname): string
90
    {
91
        if (DIRECTORY_SEPARATOR == '\\') {
1✔
92
            $pathname = preg_replace('#\\\\+#', '\\', $pathname);
×
93
        }
94

95
        return preg_replace('#/+#', '/', $pathname);
1✔
96
    }
97
}
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