Test Failed
Push — master ( a58c94...1bcec0 )
by Brent
03:26
created

AbstractAdapter::getData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace Brendt\Stitcher\Adapter;
4
5
use Brendt\Stitcher\Config;
6
use Brendt\Stitcher\factory\ParserFactory;
7
8
/**
9
 * The AbstractAdapter class provides a base for adapters who need to parse template variables.
10
 */
11
abstract class AbstractAdapter implements Adapter
12
{
13
14
    /**
15
     * @var ParserFactory
16
     */
17
    protected $parserFactory;
18
19
    /**
20
     * Construct the adapter and set the parser factory variable.
21
     *
22
     * @see \Brendt\Stitcher\Factory\ParserFactory
23
     */
24
    public function __construct() {
25
        $this->parserFactory = Config::getDependency('factory.parser');
26
    }
27
28
    /**
29
     * This function will get the parser based on the value provided.
30
     * This value is parsed by the parser, or returned if no suitable parser was found.
31
     *
32
     * @param $value
33
     *
34
     * @return mixed
35
     *
36
     * @see \Brendt\Stitcher\Factory\ParserFactory
37
     */
38
    protected function getData($value) {
39
        $parser = $this->parserFactory->getParser($value);
40
41
        if (!$parser) {
42
            return $value;
43
        }
44
45
        return $parser->parse($value);
46
    }
47
48
}
49