Utils::addOrReplaceDefinitionArgument()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 6
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiechu\SymfonyCommonsBundle\DependencyInjection;
6
7
use Symfony\Component\DependencyInjection\Definition;
8
use Symfony\Component\DependencyInjection\Exception\OutOfBoundsException;
9
10
class Utils
11
{
12
    /**
13
     * @param Definition $definition
14
     * @param int        $index
15
     * @param mixed      $value
16
     *
17
     * @throws OutOfBoundsException
18
     */
19 13
    public static function addOrReplaceDefinitionArgument(Definition $definition, int $index, $value): void
20
    {
21 13
        if (array_key_exists($index, $definition->getArguments())) {
22
            $definition->replaceArgument($index, $value);
23
        } else {
24 13
            $definition->setArgument($index, $value);
25
        }
26 13
    }
27
28
    /**
29
     * @param Definition $definition
30
     */
31 5
    public static function clearListenerTags(Definition $definition): void
32
    {
33 5
        $definition->clearTag('kernel.event_subscriber');
34 5
        $definition->clearTag('kernel.event_listener');
35
36 5
        $definition->setPublic(false);
37 5
    }
38
}
39