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

tito10047 / progressive-image-bundle / 20661725623

02 Jan 2026 04:11PM UTC coverage: 89.065%. Remained the same
20661725623

push

github

tito10047
replace `grid` with `sizes`: update all references in templates, tests, and documentation to align with the new attribute name; adjust `Image` component logic accordingly and ensure backward compatibility

1 of 1 new or added line in 1 file covered. (100.0%)

111 existing lines in 9 files now uncovered.

562 of 631 relevant lines covered (89.06%)

166.02 hits per line

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

100.0
/src/Twig/Components/Image.php
1
<?php
2

3
namespace Tito10047\ProgressiveImageBundle\Twig\Components;
4

5
use Tito10047\ProgressiveImageBundle\DTO\BreakpointAssignment;
6
use Tito10047\ProgressiveImageBundle\Service\ResponsiveAttributeGenerator;
7
use Tito10047\ProgressiveImageBundle\SrcsetGenerator\SrcsetGeneratorInterface;
8
use Tito10047\ProgressiveImageBundle\Service\PreloadCollector;
9
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
10
use Symfony\UX\TwigComponent\Attribute\PostMount;
11
use Tito10047\ProgressiveImageBundle\Decorators\PathDecoratorInterface;
12
use Tito10047\ProgressiveImageBundle\DTO\ImageMetadata;
13
use Tito10047\ProgressiveImageBundle\Exception\PathResolutionException;
14
use Tito10047\ProgressiveImageBundle\ProgressiveImageBundle;
15
use Tito10047\ProgressiveImageBundle\Service\MetadataReader;
16

17
#[AsTwigComponent]
18
class Image {
19

20

21
        public ?string         $src = null;
22
        public ?string         $filter = null;
23
        public ?string         $alt = null;
24
        public ?string         $pointInterest = null;
25
        public array           $context = [];
26
        private ?ImageMetadata $metadata;
27
        private string         $decoratedSrc;
28
        private ?int           $decoratedWidth;
29
        private ?int           $decoratedHeight;
30
        public bool            $preload = false;
31
        public string  $priority = 'high';
32
        public ?string $sizes    = null;
33
        public ?string $ratio    = null;
34
        private array          $breakpoinsts = [];
35
        /**
36
         * @var array{sizes: string, srcset: string}|null
37
         */
38
        private ?array         $responsiveAttributes = null;
39

40
        /**
41
         * @param iterable<PathDecoratorInterface> $pathDecorator
42
         * @param $defaultPreset null|array{
43
         *     widths: array<string, int>,
44
         *     sizes: string
45
         * }
46
         * @param $presets null|array<string,array{
47
         *      widths: array<string, int>,
48
         *      sizes: string
49
         *  }>
50
         */
51
        public function __construct(
52
                private readonly MetadataReader $analyzer,
53
                private readonly iterable       $pathDecorator,
54
                private readonly ?ResponsiveAttributeGenerator $responsiveAttributeGenerator,
55
                private readonly PreloadCollector            $preloadCollector,
56
        ) {
57
        }
232✔
58

59
        #[PostMount]
60
        public function postMount(): void {
61
                try {
62
                        $this->metadata = $this->analyzer->getMetadata($this->src);
232✔
63
                }catch (PathResolutionException){
89✔
64
                        $this->metadata = null;
89✔
65
                }
66
                $this->decoratedSrc = $this->src;
232✔
67
                $this->decoratedWidth = $this->metadata?->width;
232✔
68
                $this->decoratedHeight = $this->metadata?->height;
232✔
69
                foreach ($this->pathDecorator as $decorator) {
232✔
70
                        $this->decoratedSrc = $decorator->decorate($this->decoratedSrc, $this->context);
57✔
71
                        $size = $decorator->getSize($this->decoratedSrc, $this->context);
57✔
72
                        if ($size){
57✔
UNCOV
73
                                $this->decoratedWidth = $size["width"];
28✔
UNCOV
74
                                $this->decoratedHeight = $size["height"];
28✔
75
                        }
76
                }
77
                $this->breakpoinsts = $this->sizes ? BreakpointAssignment::parseSegments($this->sizes, $this->ratio) : [];
232✔
78
                if ($this->breakpoinsts) {
232✔
UNCOV
79
                        $this->responsiveAttributes = $this->responsiveAttributeGenerator?->generate($this->src, $this->breakpoinsts, $this->decoratedWidth ?? 0, $this->preload, $this->pointInterest);
84✔
80
                }elseif ($this->preload){
148✔
UNCOV
81
                        $this->preloadCollector->add($this->decoratedSrc, "image", $this->priority);
14✔
82
                }
83
        }
84

85
        public function getSrcset():string {
86
                if (!$this->responsiveAttributes){
158✔
87
                        return "";
74✔
88
                }
UNCOV
89
                return "srcset=\"{$this->responsiveAttributes['srcset']}\"";
84✔
90
        }
91

92
        public function getResponsiveSizes():string {
93
                if (!$this->responsiveAttributes){
158✔
94
                        return "";
74✔
95
                }
UNCOV
96
                return "sizes=\"{$this->responsiveAttributes["sizes"]}\"";
84✔
97
        }
98

99
        public function getHash(): ?string {
100
                return $this->metadata?->originalHash;
203✔
101
        }
102

103
        public function getWidth():?int {
104
                return $this->decoratedWidth??$this->metadata?->width;
157✔
105
        }
106

107
        public function getHeight():?int {
108
                return $this->decoratedHeight??$this->metadata?->height;
217✔
109
        }
110

111
        public function getDecoratedSrc(): string {
112
                return $this->decoratedSrc??$this->src;
202✔
113
        }
114

115
        public function getController(): ?string {
116
                return ProgressiveImageBundle::STIMULUS_CONTROLLER;
158✔
117
        }
118

119
}
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