AbstractParser::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
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