YamlParserCallable   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 44
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A __invoke() 0 11 2
1
<?php
2
namespace Germania\YamlServices;
3
4
use Symfony\Component\Yaml\Yaml;
5
use Psr\Log\LoggerInterface;
6
use Psr\Log\NullLogger;
7
8
class YamlParserCallable
9
{
10
11
12
    /**
13
     * @var integer
14
     */
15
    public $default_yaml_flags = 0;
16
17
18
    /**
19
     * @var LoggerInterface
20
     */
21
    public $logger;
22
23
24
    /**
25
     * @param integer $default_yaml_flags  Default parsing flags, if needed.
26
     * @param LoggerInterface $logger      Optional PSR3 Logger
27
     */
28 45
    public function __construct( $default_yaml_flags = 0, LoggerInterface $logger = null)
29
    {
30 45
        $this->default_yaml_flags = $default_yaml_flags;
31 45
        $this->logger = $logger ?: new NullLogger;
32 45
    }
33
34
35
    /**
36
     * @param  string   $yaml_content The YAML content to parse
37
     * @param  int|null $yaml_flags   Custom YAML flags
38
     * @return string
39
     */
40 20
    public function __invoke( $yaml_content, $yaml_flags = null )
41
    {
42 20
        $flags = is_integer($yaml_flags) ? $yaml_flags : $this->default_yaml_flags;
43
44 20
        $this->logger->info("Parse YAML content", [
45 20
            'length' => mb_strlen( $yaml_content ),
46 16
            'flags' => $flags
47 4
        ]);
48
49 20
        return Yaml::parse($yaml_content, $flags);
50
    }
51
}
52