Completed
Pull Request — 3.x (#6180)
by Wojciech
06:01
created

WebpackEntriesCompilerPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 20 4
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\DependencyInjection\Compiler;
15
16
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
19
/**
20
 * @author Silas Joisten <[email protected]>
21
 */
22
final class WebpackEntriesCompilerPass implements CompilerPassInterface
23
{
24
    public function process(ContainerBuilder $container): void
25
    {
26
        $configs = $container->getExtensionConfig('webpack_encore');
27
28
        $entries = [];
29
        foreach ($configs as $config) {
30
            if (!isset($config['builds'])) {
31
                continue;
32
            }
33
34
            $entries = array_merge($entries, $config['builds']);
35
        }
36
37
        if (!$entries) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $entries of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
38
            return;
39
        }
40
41
        $container->getDefinition('twig')
42
            ->addMethodCall('addGlobal', ['sonata_admin_webpack_entries', $entries]);
43
    }
44
}
45