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

68publishers / webpack-encore-bundle / 13510931892

25 Feb 2025 12:37AM UTC coverage: 93.452% (+2.1%) from 91.379%
13510931892

push

github

tg666
PHP-Cs-Fixer should be run on PHP 8.3 because the package does not support PHP 8.4

314 of 336 relevant lines covered (93.45%)

0.93 hits per line

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

94.74
/src/Bridge/Symfony/Console/Command/WarmupCacheCommand.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace SixtyEightPublishers\WebpackEncoreBundle\Bridge\Symfony\Console\Command;
6

7
use Psr\Cache\InvalidArgumentException;
8
use SixtyEightPublishers\WebpackEncoreBundle\Asset\EntryPointLookup;
9
use SixtyEightPublishers\WebpackEncoreBundle\Exception\EntryPointNotFoundException;
10
use Symfony\Component\Cache\Adapter\ArrayAdapter;
11
use Symfony\Component\Cache\Adapter\NullAdapter;
12
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
13
use Symfony\Component\Console\Attribute\AsCommand;
14
use Symfony\Component\Console\Command\Command;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Output\OutputInterface;
17
use Symfony\Component\Console\Style\SymfonyStyle;
18
use Throwable;
19
use function array_map;
20
use function file_exists;
21
use function sprintf;
22
use function unserialize;
23

24
#[AsCommand(
25
    name: 'encore:warmup-cache',
26
    description: 'Dumps entrypoints data into PHP file for faster loading in production environment.',
27
)]
28
final class WarmupCacheCommand extends Command
29
{
30
    /** @var array<string, string> */
31
    private array $cacheKeys;
32

33
    private string $cacheFile;
34

35
    /**
36
     * @param array<string, string> $cacheKeys
37
     */
38
    public function __construct(array $cacheKeys, string $cacheFile)
39
    {
40
        parent::__construct();
1✔
41

42
        $this->cacheKeys = $cacheKeys;
1✔
43
        $this->cacheFile = $cacheFile;
1✔
44
    }
1✔
45

46
    /**
47
     * @throws Throwable|InvalidArgumentException
48
     */
49
    protected function execute(InputInterface $input, OutputInterface $output): int
50
    {
51
        $style = new SymfonyStyle($input, $output);
1✔
52
        $arrayAdapter = new ArrayAdapter();
1✔
53

54
        foreach ($this->cacheKeys as $cacheKey => $path) {
1✔
55
            if (!file_exists($path)) {
1✔
56
                continue;
×
57
            }
58

59
            $entryPointLookup = new EntryPointLookup($path, $arrayAdapter, $cacheKey);
1✔
60

61
            try {
62
                $entryPointLookup->getJavaScriptFiles('dummy');
1✔
63
            } catch (EntryPointNotFoundException $e) {
1✔
64
                # ignore exception
65
            }
66
        }
67

68
        $values = array_map(static fn ($val) => null !== $val ? unserialize($val, ['allowed_classes' => false]) : null, $arrayAdapter->getValues());
1✔
69
        $phpArrayAdapter = new PhpArrayAdapter($this->cacheFile, new NullAdapter());
1✔
70

71
        $phpArrayAdapter->warmUp($values);
1✔
72
        $style->success(sprintf(
1✔
73
            'Entrypoints successfully dumped into "%s".',
1✔
74
            $this->cacheFile,
1✔
75
        ));
76

77
        return Command::SUCCESS;
1✔
78
    }
79
}
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