Completed
Push — master ( 52b242...112fdc )
by Thomas
17s queued 11s
created

addLoggerConfigurationNodeFromDefaultsConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the ekino Drupal Debug project.
7
 *
8
 * (c) ekino
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 Ekino\Drupal\Debug\Configuration;
15
16
use Ekino\Drupal\Debug\Configuration\Model\ActionConfiguration;
17
use Ekino\Drupal\Debug\Configuration\Model\DefaultsConfiguration as DefaultsConfigurationModel;
18
use Ekino\Drupal\Debug\Logger\LoggerStack;
19
use Monolog\Logger;
20
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
21
22
trait LoggerConfigurationTrait
23
{
24 19
    private static function addLoggerConfigurationNode(NodeBuilder $nodeBuilder, string $defaultChannel, string $defaultFilePath): NodeBuilder
25
    {
26
        return $nodeBuilder
27 19
            ->arrayNode('logger')
28 19
                ->canBeDisabled()
29 19
                ->children()
30 19
                    ->scalarNode('channel')
31 19
                        ->cannotBeEmpty()
32 19
                        ->defaultValue($defaultChannel)
33 19
                    ->end()
34 19
                    ->scalarNode('file_path')
0 ignored issues
show
Bug introduced by
The method scalarNode() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of Symfony\Component\Config...der\NodeParentInterface such as Symfony\Component\Config...ion\Builder\NodeBuilder. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
                    ->/** @scrutinizer ignore-call */ scalarNode('file_path')
Loading history...
35 19
                        ->cannotBeEmpty()
36 19
                        ->defaultValue($defaultFilePath)
37 19
                    ->end()
38 19
                ->end()
39 19
            ->end();
40
    }
41
42 19
    private static function addLoggerConfigurationNodeFromDefaultsConfiguration(NodeBuilder $nodeBuilder, DefaultsConfigurationModel $defaultsConfiguration): NodeBuilder
43
    {
44 19
        $defaultLoggerConfiguration = $defaultsConfiguration->getLogger();
45
46 19
        return self::addLoggerConfigurationNode($nodeBuilder, $defaultLoggerConfiguration['channel'], $defaultLoggerConfiguration['file_path']);
47
    }
48
49 2
    private static function getConfiguredLogger(ActionConfiguration $actionConfiguration): ?Logger
50
    {
51 2
        $processedConfiguration = $actionConfiguration->getProcessedConfiguration();
52 2
        if (!$processedConfiguration['logger']['enabled']) {
53
            return null;
54
        }
55
56 2
        return LoggerStack::getInstance($processedConfiguration['logger']['channel'], $processedConfiguration['logger']['file_path']);
57
    }
58
}
59