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

tito10047 / progressive-image-bundle / 20693128959

04 Jan 2026 12:47PM UTC coverage: 89.651%. Remained the same
20693128959

push

github

tito10047
fix: adjust indentation and spacing across multiple files for consistent styling and alignment

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

121 existing lines in 9 files now uncovered.

693 of 773 relevant lines covered (89.65%)

249.82 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
/*
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✔
UNCOV
81
                        $this->responsiveAttributes = $this->responsiveAttributeGenerator->generate($this->src, $this->breakpoinsts, $this->metadata->width ?? 0, $this->preload, $this->pointInterest);
126✔
82
                } else {
83
                        $this->decoratedWidth  = $this->metadata?->width;
193✔
84
                        $this->decoratedHeight = $this->metadata?->height;
193✔
85
                        foreach ($this->pathDecorator as $decorator) {
193✔
86
                                $size = $decorator->getSize($this->decoratedSrc, $this->context);
43✔
87
                                if ($size) {
43✔
UNCOV
88
                                        $this->decoratedWidth  = $size['width'];
28✔
UNCOV
89
                                        $this->decoratedHeight = $size['height'];
28✔
90
                                }
91
                        }
92

93
                        if ($this->preload) {
193✔
UNCOV
94
                                $this->preloadCollector->add($this->decoratedSrc, 'image', $this->priority);
14✔
95
                        }
96
        }
97
    }
98

99
    public function getSrcset(): string
100
    {
101
        if (!$this->responsiveAttributes) {
245✔
102
            return '';
119✔
103
        }
104

UNCOV
105
        return "srcset=\"{$this->responsiveAttributes['srcset']}\"";
126✔
106
    }
107

108
    public function getResponsiveSizes(): string
109
    {
110
        if (!$this->responsiveAttributes) {
245✔
111
            return '';
119✔
112
        }
113

UNCOV
114
        return "sizes=\"{$this->responsiveAttributes['sizes']}\"";
126✔
115
    }
116

117
    public function getHash(): ?string
118
    {
119
        return $this->metadata?->originalHash;
290✔
120
    }
121

122
    public function getWidth(): ?int
123
    {
124
                return $this->decoratedWidth;
88✔
125
    }
126

127
    public function getHeight(): ?int
128
    {
129
                return $this->decoratedHeight;
178✔
130
        }
131

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

139
    public function getDecoratedSrc(): string
140
    {
141
        return $this->decoratedSrc ?? $this->src;
289✔
142
    }
143

144
    public function getController(): string
145
    {
146
        return ProgressiveImageBundle::STIMULUS_CONTROLLER;
245✔
147
    }
148

149
        public function getFramework(): string {
150
                return $this->framework;
245✔
151
        }
152
}
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