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

tito10047 / progressive-image-bundle / 20693585928

04 Jan 2026 01:24PM UTC coverage: 89.796%. Remained the same
20693585928

push

github

tito10047
cs fixer

704 of 784 relevant lines covered (89.8%)

252.6 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

12
namespace Tito10047\ProgressiveImageBundle\Service;
13

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

18
class PreloadCollector
19
{
20
    /**
21
     * @var array<string, array{as: string, priority: string, imagesrcset: string|null, imagesizes: string|null}>
22
     */
23
    private array $urls = [];
24

25
    public function __construct(
26
        private readonly RequestStack $requestStack,
27
    ) {
28
    }
415✔
29

30
    public function add(string $url, string $as = 'image', string $priority = 'high', ?string $srcset = null, ?string $sizes = null): void
31
    {
32
        $this->urls[$url] = [
42✔
33
            'as' => $as,
42✔
34
            'priority' => $priority,
42✔
35
            'imagesrcset' => $srcset,
42✔
36
            'imagesizes' => $sizes,
42✔
37
        ];
42✔
38

39
        $request = $this->requestStack->getCurrentRequest();
42✔
40
        if (!$request) {
42✔
41
            return;
42✔
42
        }
43

44
        $link = (new Link('preload', $url))
×
45
            ->withAttribute('as', $as)
×
46
            ->withAttribute('fetchpriority', $priority);
×
47

48
        if ($srcset) {
×
49
            $link = $link->withAttribute('imagesrcset', $srcset);
×
50
        }
51

52
        if ($sizes) {
×
53
            $link = $link->withAttribute('imagesizes', $sizes);
×
54
        }
55

56
        $linkProvider = $request->attributes->get('_links', new GenericLinkProvider());
×
57
        $request->attributes->set('_links', $linkProvider->withLink($link));
×
58
    }
59

60
    /**
61
     * @return array<string, array{as: string, priority: string, imagesrcset: string|null, imagesizes: string|null}>
62
     */
63
    public function getUrls(): array
64
    {
65
        return $this->urls;
126✔
66
    }
67
}
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