ParserFactory::create()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 11
rs 9.4286
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
3
namespace Fillet\Parser;
4
5
/**
6
 * Creates the appropriate writer class for a post type
7
 *
8
 * @package Fillet\Writer
9
 */
10
class ParserFactory
11
{
12
    /**
13
     * Create a new instance of a parser
14
     *
15
     * @param string $class Class that we want to try and create
16
     *
17
     * @return ParserInterface
18
     * @throws \Exception
19
     */
20
    public static function create($class)
21
    {
22
        $className = 'Fillet\\Parser\\' . ucfirst($class);
23
        if(class_exists($className)) {
24
            /** @var ParserInterface $parser */
25
            $parser = new $className();
26
            return $parser;
27
        }
28
29
        throw new \Exception('There is no parser for ' . $class);
30
    }
31
}