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

Cecilapp / Cecil / 21441511038

28 Jan 2026 02:10PM UTC coverage: 82.613% (+0.03%) from 82.588%
21441511038

push

github

ArnaudLigny
Fix image resize logic for equal dimensions

Adds a check to return the original image if the requested width and height match the current image dimensions, preventing unnecessary processing.

1 of 2 new or added lines in 1 file covered. (50.0%)

23 existing lines in 3 files now uncovered.

3307 of 4003 relevant lines covered (82.61%)

0.83 hits per line

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

71.43
/src/Step/Assets/Save.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\Step\Assets;
15

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

21
/**
22
 * Save assets step.
23
 *
24
 * This step is responsible for saving assets to the output directory.
25
 * It copies files from the cache to the output directory, ensuring that
26
 * assets are available for the final build. If the cache is disabled, it
27
 * clears the cache directory before processing assets.
28
 */
29
class Save extends AbstractStep
30
{
31
    protected Cache $cache;
32

33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function getName(): string
37
    {
38
        return 'Saving assets';
1✔
39
    }
40

41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function init(array $options): void
45
    {
46
        // last build step: should clear cache?
47
        $this->clearCacheIfDisabled();
1✔
48

49
        if ($options['dry-run']) {
1✔
UNCOV
50
            return;
×
51
        }
52

53
        $this->cache = new Cache($this->builder, 'assets');
1✔
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->getAssetsList());
1✔
67
        if ($total > 0) {
1✔
68
            $count = 0;
1✔
69
            foreach ($this->builder->getAssetsList() as $path) {
1✔
70
                // if file deleted from assets cache
71
                if (!Util\File::getFS()->exists($this->cache->getContentFilePathname($path))) {
1✔
UNCOV
72
                    $this->builder->getLogger()->warning(\sprintf('Asset "%s" not found in cache, skipping. You should clear all cache.', $path));
×
UNCOV
73
                    break;
×
74
                }
75
                $count++;
1✔
76
                Util\File::getFS()->copy($this->cache->getContentFilePathname($path), Util::joinFile($this->config->getOutputPath(), $path), false);
1✔
77
                $message = \sprintf('Asset "%s" saved', $path);
1✔
78
                $this->builder->getLogger()->info($message, ['progress' => [$count, $total]]);
1✔
79
            }
80
        }
81
    }
82

83
    /**
84
     * Deletes cache directory, if cache is disabled.
85
     */
86
    private function clearCacheIfDisabled(): void
87
    {
88
        if (!$this->config->isEnabled('cache')) {
1✔
89
            try {
UNCOV
90
                Util\File::getFS()->remove($this->config->getCachePath());
×
UNCOV
91
            } catch (\Exception) {
×
UNCOV
92
                throw new RuntimeException(\sprintf('Unable to remove cache directory "%s".', $this->config->getCachePath()));
×
93
            }
94
        }
95
    }
96
}
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