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

tito10047 / progressive-image-bundle / 21092637779

17 Jan 2026 10:11AM UTC coverage: 75.638% (-15.3%) from 90.889%
21092637779

Pull #4

github

web-flow
Merge e0e96fffd into 0bfbae60a
Pull Request #4: Switch `ResponsiveAttributeGenerator::generate` to return `Responsive…

31 of 33 new or added lines in 6 files covered. (93.94%)

4 existing lines in 1 file now uncovered.

711 of 940 relevant lines covered (75.64%)

7.99 hits per line

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

74.36
/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\DTO\ResponsiveAttributesInterface;
20
use Tito10047\ProgressiveImageBundle\Exception\PathResolutionException;
21
use Tito10047\ProgressiveImageBundle\ProgressiveImageBundle;
22
use Tito10047\ProgressiveImageBundle\Service\MetadataReaderInterface;
23
use Tito10047\ProgressiveImageBundle\Service\PreloadCollector;
24
use Tito10047\ProgressiveImageBundle\Service\ResponsiveAttributeGenerator;
25

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

52
        private ?ResponsiveAttributesInterface $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
                private readonly bool   $defaultRetina = true,
64
    ) {
65
    }
12✔
66

67
    #[PostMount]
68
    public function postMount(): void
69
    {
70
                if (null === $this->retina) {
12✔
71
                        $this->retina = $this->defaultRetina;
12✔
72
                }
73

74
                $this->decoratedSrc = $this->src;
12✔
75
                foreach ($this->pathDecorator as $decorator) {
12✔
76
                        $this->decoratedSrc = $decorator->decorate($this->decoratedSrc, $this->context);
1✔
77
                }
78

79
        try {
80
            $this->metadata = $this->analyzer->getMetadata($this->src);
12✔
81
        } catch (PathResolutionException) {
8✔
82
            $this->metadata = null;
8✔
83
        }
84
                $this->breakpoinsts = $this->sizes ? BreakpointAssignment::parseSegments($this->sizes, $this->ratio) : [];
12✔
85
                if ($this->breakpoinsts && $this->responsiveAttributeGenerator) {
12✔
86
                        $context = $this->context;
1✔
87
                        if ($this->filter) {
1✔
88
                                $context['filter'] = $this->filter;
×
89
                        }
90
                        $this->responsiveAttributes = $this->responsiveAttributeGenerator->generate($this->src, $this->breakpoinsts, $this->metadata->width ?? 0, $this->preload, $this->pointInterest, $context, $this->retina);
1✔
91
                } else {
92
                        $this->decoratedWidth  = $this->metadata?->width;
11✔
93
                        $this->decoratedHeight = $this->metadata?->height;
11✔
94
                        foreach ($this->pathDecorator as $decorator) {
11✔
95
                                $size = $decorator->getSize($this->decoratedSrc, $this->context);
1✔
96
                                if ($size) {
1✔
97
                                        $this->decoratedWidth  = $size['width'];
×
98
                                        $this->decoratedHeight = $size['height'];
×
99
                                }
100
                        }
101

102
                        if ($this->preload) {
11✔
103
                                $this->preloadCollector->add($this->decoratedSrc, 'image', $this->priority);
×
104
                        }
105
        }
106
    }
107

108
    public function getSrcset(): string
109
    {
UNCOV
110
        if (!$this->responsiveAttributes) {
×
UNCOV
111
            return '';
×
112
        }
113

NEW
114
                return "srcset=\"{$this->responsiveAttributes->getDefaultSource()->getSrcset()}\"";
×
115
    }
116

117
    public function getResponsiveSizes(): string
118
    {
UNCOV
119
        if (!$this->responsiveAttributes) {
×
UNCOV
120
            return '';
×
121
        }
122

NEW
123
                return "sizes=\"{$this->responsiveAttributes->getDefaultSource()->getSizes()}\"";
×
124
        }
125

126
        public function getResponsiveAttributes(): ?ResponsiveAttributesInterface {
127
                return $this->responsiveAttributes;
8✔
128
    }
129

130
        public function hasResponsiveAttributes(): bool {
131
                return $this->responsiveAttributes !== null;
8✔
132
        }
133

134
    public function getHash(): ?string
135
    {
136
        return $this->metadata?->originalHash;
11✔
137
    }
138

139
    public function getWidth(): ?int
140
    {
141
                return $this->decoratedWidth;
4✔
142
    }
143

144
    public function getHeight(): ?int
145
    {
146
                return $this->decoratedHeight;
10✔
147
        }
148

149
        public function getVariables(): array {
150
                return $this->responsiveAttributes?->getVariables() ?? [];
8✔
151
    }
152

153
    public function getDecoratedSrc(): string
154
    {
155
        return $this->decoratedSrc ?? $this->src;
10✔
156
    }
157

158
    public function getController(): string
159
    {
160
        return ProgressiveImageBundle::STIMULUS_CONTROLLER;
8✔
161
    }
162

163
        public function getFramework(): string {
164
                return $this->framework;
8✔
165
        }
166
}
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