Completed
Push — include-lib ( fd24a6...4173d3 )
by Arnaud
13:24
created

Converter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A convertFrontmatter() 0 14 4
A convertBody() 0 6 1
1
<?php
2
/*
3
 * Copyright (c) Arnaud Ligny <[email protected]>
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Cecil\Converter;
10
11
use ParsedownExtra;
12
use Cecil\Exception\Exception;
13
use Symfony\Component\Yaml\Exception\ParseException;
14
use Symfony\Component\Yaml\Yaml;
15
16
/**
17
 * Class Converter.
18
 */
19
class Converter implements ConverterInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public static function convertFrontmatter($string, $type = 'yaml')
25
    {
26
        switch ($type) {
27
            case 'ini':
28
                return parse_ini_string($string);
29
            case 'yaml':
30
            default:
31
                try {
32
                    return Yaml::parse((string) $string);
33
                } catch (ParseException $e) {
34
                    throw new Exception($e->getMessage());
35
                }
36
        }
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public static function convertBody($string)
43
    {
44
        $parsedown = new ParsedownExtra();
45
46
        return $parsedown->text($string);
47
    }
48
}
49