Lines 80.00% 8 / 10
Methods 0.00% 0 / 2
Classes 0.00% 0 / 1
Covered by tests of size
Name Lines Methods CRAP
 asset 0.00% 0 / 1 0.00% 0 / 1 2
 versionedPath 88.88% 8 / 9 0.00% 0 / 1 4.02
32class AssetVersionTwigExtension extends AbstractExtension
33{
34    #[AsTwigFunction(name: 'asset')]
35    public static function asset(string $path): string
36    {
37        return self::versionedPath($path, (string) PMF_ROOT_DIR);
38    }
39
40    public static function versionedPath(string $path, string $rootDir): string
41    {
42        if (str_contains($path, '..')) {
43            return $path;
44        }
45
46        $file = rtrim(string: $rootDir, characters: '/') . '/' . ltrim(string: $path, characters: '/');
47        if (!is_file($file)) {
48            return $path;
49        }
50
51        $modificationTime = filemtime($file);
52        if ($modificationTime === false) {
53            return $path;
54        }
55
56        return $path . '?v=' . $modificationTime;
57    }
58}