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

tito10047 / progressive-image-bundle / 20894678042

11 Jan 2026 11:52AM UTC coverage: 89.9% (-0.08%) from 89.975%
20894678042

push

github

tito10047
Add support for custom filter in LiipImagineControllerTest and ResponsiveAttributeGeneratorTest

2 of 9 new or added lines in 3 files covered. (22.22%)

139 existing lines in 9 files now uncovered.

721 of 802 relevant lines covered (89.9%)

261.42 hits per line

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

97.14
/src/Twig/Components/Image.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

12
namespace Tito10047\ProgressiveImageBundle\Twig\Components;
13

14
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
15
use Symfony\UX\TwigComponent\Attribute\PostMount;
16
use Tito10047\ProgressiveImageBundle\Decorators\PathDecoratorInterface;
17
use Tito10047\ProgressiveImageBundle\DTO\BreakpointAssignment;
18
use Tito10047\ProgressiveImageBundle\DTO\ImageMetadata;
19
use Tito10047\ProgressiveImageBundle\Exception\PathResolutionException;
20
use Tito10047\ProgressiveImageBundle\ProgressiveImageBundle;
21
use Tito10047\ProgressiveImageBundle\Service\MetadataReaderInterface;
22
use Tito10047\ProgressiveImageBundle\Service\PreloadCollector;
23
use Tito10047\ProgressiveImageBundle\Service\ResponsiveAttributeGenerator;
24

25
#[AsTwigComponent]
26
final class Image
27
{
28
    public ?string $src = null;
29
    public ?string $filter = null;
30
    public ?string $alt = null;
31
    public ?string $pointInterest = null;
32
    /**
33
     * @var array<string, mixed>
34
     */
35
    public array $context = [];
36
        private ?ImageMetadata $metadata        = null;
37
    private string $decoratedSrc;
38
        private ?int           $decoratedWidth  = null;
39
        private ?int           $decoratedHeight = null;
40
    public bool $preload = false;
41
    public ?int $ttl = null;
42
    public string $priority = 'high';
43
    public ?string $sizes = null;
44
    public ?string $ratio = null;
45
    /**
46
     * @var BreakpointAssignment[]
47
     */
48
    private array $breakpoinsts = [];
49
    /**
50
         * @var array{sizes: string, srcset: string, variables: array<string, string>}|null
51
     */
52
    private ?array $responsiveAttributes = null;
53

54
    /**
55
     * @param iterable<PathDecoratorInterface> $pathDecorator
56
     */
57
    public function __construct(
58
        private readonly MetadataReaderInterface $analyzer,
59
        private readonly iterable $pathDecorator,
60
        private readonly ?ResponsiveAttributeGenerator $responsiveAttributeGenerator,
61
        private readonly PreloadCollector $preloadCollector,
62
                private readonly string $framework = 'custom',
63
    ) {
64
    }
319✔
65

66
    #[PostMount]
67
    public function postMount(): void
68
    {
69
                $this->decoratedSrc = $this->src;
319✔
70
                foreach ($this->pathDecorator as $decorator) {
319✔
71
                        $this->decoratedSrc = $decorator->decorate($this->decoratedSrc, $this->context);
57✔
72
                }
73

74
        try {
75
            $this->metadata = $this->analyzer->getMetadata($this->src);
319✔
76
        } catch (PathResolutionException) {
134✔
77
            $this->metadata = null;
134✔
78
        }
79
                $this->breakpoinsts = $this->sizes ? BreakpointAssignment::parseSegments($this->sizes, $this->ratio) : [];
319✔
80
                if ($this->breakpoinsts && $this->responsiveAttributeGenerator) {
319✔
NEW
81
                        $context = $this->context;
126✔
NEW
82
                        if ($this->filter) {
126✔
NEW
83
                                $context['filter'] = $this->filter;
×
84
                        }
NEW
85
                        $this->responsiveAttributes = $this->responsiveAttributeGenerator->generate($this->src, $this->breakpoinsts, $this->metadata->width ?? 0, $this->preload, $this->pointInterest, $context);
126✔
86
                } else {
87
                        $this->decoratedWidth  = $this->metadata?->width;
193✔
88
                        $this->decoratedHeight = $this->metadata?->height;
193✔
89
                        foreach ($this->pathDecorator as $decorator) {
193✔
90
                                $size = $decorator->getSize($this->decoratedSrc, $this->context);
43✔
91
                                if ($size) {
43✔
UNCOV
92
                                        $this->decoratedWidth  = $size['width'];
28✔
UNCOV
93
                                        $this->decoratedHeight = $size['height'];
28✔
94
                                }
95
                        }
96

97
                        if ($this->preload) {
193✔
UNCOV
98
                                $this->preloadCollector->add($this->decoratedSrc, 'image', $this->priority);
14✔
99
                        }
100
        }
101
    }
102

103
    public function getSrcset(): string
104
    {
105
        if (!$this->responsiveAttributes) {
245✔
106
            return '';
119✔
107
        }
108

UNCOV
109
        return "srcset=\"{$this->responsiveAttributes['srcset']}\"";
126✔
110
    }
111

112
    public function getResponsiveSizes(): string
113
    {
114
        if (!$this->responsiveAttributes) {
245✔
115
            return '';
119✔
116
        }
117

UNCOV
118
        return "sizes=\"{$this->responsiveAttributes['sizes']}\"";
126✔
119
    }
120

121
    public function getHash(): ?string
122
    {
123
        return $this->metadata?->originalHash;
290✔
124
    }
125

126
    public function getWidth(): ?int
127
    {
128
                return $this->decoratedWidth;
88✔
129
    }
130

131
    public function getHeight(): ?int
132
    {
133
                return $this->decoratedHeight;
178✔
134
        }
135

136
        /**
137
         * @return array<string, string>
138
         */
139
        public function getVariables(): array {
140
                return $this->responsiveAttributes['variables'] ?? [];
245✔
141
    }
142

143
    public function getDecoratedSrc(): string
144
    {
145
        return $this->decoratedSrc ?? $this->src;
289✔
146
    }
147

148
    public function getController(): string
149
    {
150
        return ProgressiveImageBundle::STIMULUS_CONTROLLER;
245✔
151
    }
152

153
        public function getFramework(): string {
154
                return $this->framework;
245✔
155
        }
156
}
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