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

tito10047 / progressive-image-bundle / 20675431244

03 Jan 2026 09:29AM UTC coverage: 88.617% (+0.3%) from 88.338%
20675431244

push

github

tito10047
add TTL support for image caching: implement configurable TTL handling in cache services, adapt Twig components, and update tests to validate TTL functionality

12 of 12 new or added lines in 3 files covered. (100.0%)

120 existing lines in 9 files now uncovered.

615 of 694 relevant lines covered (88.62%)

184.23 hits per line

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

96.77
/src/Service/LiipImagineRuntimeConfigGenerator.php
1
<?php
2

3
/*
4
 * This file is part of the Progressive Image Bundle.
5
 *
6
 * (c) Jozef Môstka <https://github.com/tito10047/progressive-image-bundle>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
declare(strict_types=1);
12

13
namespace Tito10047\ProgressiveImageBundle\Service;
14

15
use Liip\ImagineBundle\Exception\Imagine\Filter\NonExistingFilterException;
16
use Liip\ImagineBundle\Imagine\Filter\FilterConfiguration;
17

18
final class LiipImagineRuntimeConfigGenerator implements LiipImagineRuntimeConfigGeneratorInterface
19
{
20
    public function __construct(
21
        private readonly FilterConfiguration $filterConfiguration,
22
    ) {
UNCOV
23
    }
350✔
24

25
    /**
26
     * @return array{filterName: string, config: array<string, mixed>}
27
     */
28
    public function generate(int $width, int $height, ?string $filter = null, ?string $pointInterest = null, ?int $origWidth = null, ?int $origHeight = null): array
29
    {
UNCOV
30
        $filterName = $filter ? sprintf('%s_%dx%d', $filter, $width, $height) : sprintf('%dx%d', $width, $height);
210✔
31

UNCOV
32
        if ($pointInterest) {
210✔
UNCOV
33
            $filterName .= '_'.$pointInterest;
56✔
34
        }
35

UNCOV
36
        $config = [];
210✔
UNCOV
37
        if (null !== $filter) {
210✔
38
            try {
UNCOV
39
                $config = $this->filterConfiguration->get($filter);
28✔
40
            } catch (NonExistingFilterException) {
×
41
            }
42
        }
43

UNCOV
44
        if (!isset($config['filters'])) {
210✔
UNCOV
45
            $config['filters'] = [];
182✔
46
        }
47

UNCOV
48
        if ($pointInterest && $origWidth && $origHeight) {
210✔
UNCOV
49
            [$poiX, $poiY] = explode('x', $pointInterest);
56✔
UNCOV
50
            $config['filters']['crop'] = [
56✔
UNCOV
51
                'start' => $this->calculateCropStart((int) $poiX, (int) $poiY, $width, $height, $origWidth, $origHeight),
56✔
UNCOV
52
                'size' => [$width, $height],
56✔
UNCOV
53
            ];
56✔
54
        }
55

UNCOV
56
        $config['filters']['thumbnail'] = [
210✔
UNCOV
57
            'size' => [$width, $height],
210✔
UNCOV
58
            'mode' => 'outbound',
210✔
UNCOV
59
        ];
210✔
60

UNCOV
61
        return [
210✔
UNCOV
62
            'filterName' => $filterName,
210✔
UNCOV
63
            'config' => $config,
210✔
UNCOV
64
        ];
210✔
65
    }
66

67
    /**
68
     * @return array{int, int}
69
     */
70
    private function calculateCropStart(int $poiX, int $poiY, int $targetWidth, int $targetHeight, int $origWidth, int $origHeight): array
71
    {
72
        // 1. Vypočítame stred orezu na originálnom obrázku podľa percentuálneho bodu záujmu
UNCOV
73
        $centerX = (int) ($poiX / 100 * $origWidth);
56✔
UNCOV
74
        $centerY = (int) ($poiY / 100 * $origHeight);
56✔
75

76
        // 2. Vypočítame začiatok orezu tak, aby stred bol na bode záujmu
UNCOV
77
        $startX = $centerX - (int) ($targetWidth / 2);
56✔
UNCOV
78
        $startY = $centerY - (int) ($targetHeight / 2);
56✔
79

80
        // 3. Zabezpečíme, aby orez nevychádzal mimo originálny obrázok
UNCOV
81
        $startX = max(0, min($startX, $origWidth - $targetWidth));
56✔
UNCOV
82
        $startY = max(0, min($startY, $origHeight - $targetHeight));
56✔
83

UNCOV
84
        return [$startX, $startY];
56✔
85
    }
86
}
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