Completed
Pull Request — master (#16)
by Tomáš
07:39
created

ConfigurationDecorator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 14
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A decorateFile() 0 11 3
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 Symfony\Component\Yaml\Yaml;
13
use Symplify\PHP7_Sculpin\Renderable\File\File;
14
15
final class ConfigurationDecorator
16
{
17
    public function decorateFile(File $file)
18
    {
19
        if (preg_match('/^\s*(?:---[\s]*[\r\n]+)(.*?)(?:---[\s]*[\r\n]+)(.*?)$/s', $file->getContent(), $matches)) {
20
            $file->changeContent($matches[2]);
21
22
            if (!preg_match('/^(\s*[-]+\s*|\s*)$/', $matches[1])) {
23
                $configuration = Yaml::parse($matches[1]);
24
                $file->setConfiguration($configuration);
25
            }
26
        }
27
    }
28
}
29