Passed
Push — master ( 669e12...79866c )
by Marcel
08:09
created

WebpackEntryCssSourceExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 1 1
A getFunctions() 0 3 1
A getCssSource() 0 9 2
1
<?php
2
3
namespace App\Twig;
4
5
use Symfony\Contracts\Service\Attribute\SubscribedService;
6
use Symfony\Contracts\Service\ServiceSubscriberInterface;
7
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupInterface;
8
use Twig\Extension\AbstractExtension;
9
use Twig\TwigFunction;
10
11
class WebpackEntryCssSourceExtension extends AbstractExtension {
12
13
    public function __construct(private readonly EntrypointLookupInterface $entrypointLookup, private readonly string $publicDir) {
14
15
    }
16
17
    public function getFunctions() {
18
        return [
19
            new TwigFunction('css_source', [ $this, 'getCssSource'])
20
        ];
21
    }
22
23
    public function getCssSource(string $entryName): string {
24
        $files = $this->entrypointLookup->getCssFiles($entryName);
25
        $source = '';
26
27
        foreach($files as $file) {
28
            $source .= file_get_contents($this->publicDir . $file);
29
        }
30
31
        return $source;
32
    }
33
}