AbstractParser::getResponse()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 2
1
<?php
2
namespace Thunder\SimilarWebApi;
3
4
/**
5
 * @author Tomasz Kowalczyk <[email protected]>
6
 */
7
abstract class AbstractParser implements ParserInterface
8
    {
9
    protected $name;
10
    protected $mapping;
11
12 38
    public function __construct($name, array $mapping)
13
        {
14 38
        $this->name = $name;
15 38
        $this->mapping = $mapping;
16 38
        }
17
18 38
    public function getResponse($content)
19
        {
20 38
        $response = $this->parse($content);
21 33
        $class = 'Thunder\\SimilarWebApi\\Response\\'.$this->name;
22
23 33
        if(!class_exists($class, true))
24 33
            {
25 1
            throw new \RuntimeException(sprintf('Failed to load response class %s!', $class));
26
            }
27
28 32
        return new $class($response);
29
        }
30
31
    abstract protected function parse($content);
32
    }
33