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

tito10047 / progressive-image-bundle / 20675022582

03 Jan 2026 08:51AM UTC coverage: 86.782%. Remained the same
20675022582

push

github

tito10047
update copyright in LICENSE.md

604 of 696 relevant lines covered (86.78%)

175.71 hits per line

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

55.0
/src/Service/PreloadCollector.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
namespace Tito10047\ProgressiveImageBundle\Service;
12

13
use Symfony\Component\HttpFoundation\RequestStack;
14
use Symfony\Component\WebLink\GenericLinkProvider;
15
use Symfony\Component\WebLink\Link;
16

17
class PreloadCollector {
18
        private array $urls = [];
19

20
        public function __construct(
21
                private readonly RequestStack $requestStack
22
        ) {
23
        }
287✔
24

25
        public function add(string $url, string $as = 'image', string $priority = 'high', ?string $srcset = null, ?string $sizes = null): void {
26
                $this->urls[$url] = [
28✔
27
                        'as' => $as,
28✔
28
                        'priority' => $priority,
28✔
29
                        'imagesrcset' => $srcset,
28✔
30
                        'imagesizes' => $sizes,
28✔
31
                ];
28✔
32

33
                $request = $this->requestStack->getCurrentRequest();
28✔
34
                if (!$request) {
28✔
35
                        return;
28✔
36
                }
37

38
                $link = (new Link('preload', $url))
×
39
                        ->withAttribute('as', $as)
×
40
                        ->withAttribute('fetchpriority', $priority);
×
41

42
                if ($srcset) {
×
43
                        $link = $link->withAttribute('imagesrcset', $srcset);
×
44
                }
45

46
                if ($sizes) {
×
47
                        $link = $link->withAttribute('imagesizes', $sizes);
×
48
                }
49

50
                $linkProvider = $request->attributes->get('_links', new GenericLinkProvider());
×
51
                $request->attributes->set('_links', $linkProvider->withLink($link));
×
52
        }
53

54
        public function getUrls(): array {
55
                return $this->urls;
98✔
56
        }
57
}
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