• 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

76.19
/src/Step/Assets/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\Assets;
15

16
use Cecil\Assets\Cache;
17
use Cecil\Exception\RuntimeException;
18
use Cecil\Step\AbstractStep;
19
use Cecil\Util;
20

21
/**
22
 * Assets saving.
23
 */
24
class Save extends AbstractStep
25
{
26
    protected Cache $cache;
27
    protected string $cacheKey;
28

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

37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function init(array $options): void
41
    {
42
        // should clear cache?
43
        $this->clearCache();
1✔
44

45
        if ($options['dry-run']) {
1✔
NEW
46
            return;
×
47
        }
48

49
        $this->cache = new \Cecil\Assets\Cache($this->builder, (string) $this->config->get('cache.assets.dir'));
1✔
50
        $this->cacheKey = \sprintf('_list__%s', $this->builder->getVersion());
1✔
51
        if (empty($this->assets) && $this->cache->has($this->cacheKey)) {
1✔
NEW
52
            $this->builder->setAssets($this->cache->get($this->cacheKey));
×
53
        }
54

55
        $this->canProcess = true;
1✔
56
    }
57

58
    /**
59
     * {@inheritdoc}
60
     * Note: a file from `static/` with the same name will NOT be overridden.
61
     *
62
     * @throws RuntimeException
63
     */
64
    public function process(): void
65
    {
66
        $total = \count($this->builder->getAssets());
1✔
67
        $count = 0;
1✔
68
        foreach ($this->builder->getAssets() as $path) {
1✔
69
            $count++;
1✔
70
            Util\File::getFS()->copy($this->cache->getContentFilePathname($path), Util::joinFile($this->config->getOutputPath(), $path), false);
1✔
71
            $message = \sprintf('Asset "%s" saved', $path);
1✔
72
            $this->builder->getLogger()->info($message, ['progress' => [$count, $total]]);
1✔
73
        }
74
        $this->cache->set($this->cacheKey, $this->builder->getAssets());
1✔
75
    }
76

77
    /**
78
     * Deletes cache directory.
79
     */
80
    private function clearCache(): void
81
    {
82
        if ($this->config->get('cache.enabled') === false) {
1✔
83
            try {
NEW
84
                Util\File::getFS()->remove($this->config->getCachePath());
×
NEW
85
            } catch (\Exception) {
×
NEW
86
                throw new RuntimeException(\sprintf('Can\'t remove cache directory "%s".', $this->config->getCachePath()));
×
87
            }
88
        }
89
    }
90
}
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