Passed
Push — main ( abb6be...7a1dde )
by Iain
04:38
created

BillingCompilerPass::handleEnabledDecider()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 0
loc 11
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright Iain Cambridge 2020-2023.
7
 *
8
 * Use of this software is governed by the Business Source License included in the LICENSE file and at https://getparthenon.com/docs/next/license.
9
 *
10
 * Change Date: TBD ( 3 years after 2.2.0 release )
11
 *
12
 * On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file.
13
 */
14
15
namespace Parthenon\Billing\Compiler;
16
17
use Parthenon\Billing\Webhook\HandlerManager;
18
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
19
use Symfony\Component\DependencyInjection\ContainerBuilder;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Depend...ection\ContainerBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use Symfony\Component\DependencyInjection\Reference;
21
22
final class BillingCompilerPass implements CompilerPassInterface
23
{
24
    public function process(ContainerBuilder $container)
25
    {
26
        $this->handleEnabledDecider($container);
27
    }
28
29
    private function handleEnabledDecider(ContainerBuilder $container): void
30
    {
31
        if (!$container->hasDefinition(HandlerManager::class)) {
32
            return;
33
        }
34
35
        $handlerManager = $container->getDefinition(HandlerManager::class);
36
        $definitions = $container->findTaggedServiceIds('parthenon.billing.webhooks.handler');
37
38
        foreach ($definitions as $id => $tagInfo) {
39
            $handlerManager->addMethodCall('addHandler', [new Reference($id)]);
40
        }
41
    }
42
}
43