ConfigurationDecorator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 29
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A decorateFile() 0 8 2
A setConfigurationToFileIfFoundAny() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Symplify
7
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
8
 */
9
10
namespace Symplify\PHP7_Sculpin\Renderable\Configuration;
11
12
use Symplify\PHP7_Sculpin\Configuration\Parser\YamlAndNeonParser;
13
use Symplify\PHP7_Sculpin\Renderable\File\AbstractFile;
14
15
final class ConfigurationDecorator
16
{
17
    /**
18
     * @var YamlAndNeonParser
19
     */
20
    private $yamlAndNeonParser;
21
22 7
    public function __construct(YamlAndNeonParser $yamlAndNeonParser)
23
    {
24 7
        $this->yamlAndNeonParser = $yamlAndNeonParser;
25 7
    }
26
27 4
    public function decorateFile(AbstractFile $file)
28
    {
29 4
        if (preg_match('/^\s*(?:---[\s]*[\r\n]+)(.*?)(?:---[\s]*[\r\n]+)(.*?)$/s', $file->getContent(), $matches)) {
30 2
            $file->changeContent($matches[2]);
31
32 2
            $this->setConfigurationToFileIfFoundAny($matches[1], $file);
33
        }
34 4
    }
35
36 2
    private function setConfigurationToFileIfFoundAny(string $content, AbstractFile $file)
37
    {
38 2
        if (! preg_match('/^(\s*[-]+\s*|\s*)$/', $content)) {
39 2
            $configuration = $this->yamlAndNeonParser->decode($content);
40 2
            $file->setConfiguration($configuration);
41
        }
42 2
    }
43
}
44