RegisterWidgetsPass::process()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 3
Bugs 0 Features 1
Metric Value
cc 3
eloc 10
c 3
b 0
f 1
nc 2
nop 1
dl 0
loc 15
ccs 10
cts 10
cp 1
crap 3
rs 9.9332
1
<?php
2
/**
3
 * This file is part of the sauls/components-bundle package.
4
 *
5
 * @author    Saulius Vaičeliūnas <[email protected]>
6
 * @link      http://saulius.vaiceliunas.lt
7
 * @copyright 2020
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace Sauls\Bundle\Components\DependencyInjection\Compiler;
16
17
use Sauls\Component\Widget\Factory\WidgetFactory;
18
use Sauls\Component\Widget\Widgets\CacheableWidget;
19
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
20
use Symfony\Component\DependencyInjection\ContainerBuilder;
21
22
class RegisterWidgetsPass implements CompilerPassInterface
23
{
24 6
    public function process(ContainerBuilder $container)
25
    {
26 6
        $cacheDefinition = $container->findDefinition('cache.app');
27 6
        $widgetFactoryDefinition = $container->findDefinition(WidgetFactory::class);
28
29 6
        if (!$cacheDefinition && !$widgetFactoryDefinition) {
0 ignored issues
show
introduced by
$cacheDefinition is of type Symfony\Component\DependencyInjection\Definition, thus it always evaluated to true.
Loading history...
30 1
            return;
31
        }
32
33
        $container
34 5
            ->register(CacheableWidget::class, CacheableWidget::class)
35 5
            ->addArgument($cacheDefinition)
36 5
            ->addTag('sauls_widget.widget')
37 5
            ->addMethodCall('setWidgetFactory', [$widgetFactoryDefinition])
38 5
            ->setPublic(true);
39 5
    }
40
}
41