ParserFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 0
cbo 0
dl 0
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 11 2
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
}