Passed
Push — master ( f36a08...6258cd )
by Sebastian
12:50
created

Factory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 25
ccs 8
cts 9
cp 0.8889
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A createConstraint() 0 13 2
1
<?php
2
/*
3
 * citeproc-php
4
 *
5
 * @link        http://github.com/seboettg/citeproc-php for the source repository
6
 * @copyright   Copyright (c) 2016 Sebastian Böttger.
7
 * @license     https://opensource.org/licenses/MIT
8
 */
9
10
namespace Seboettg\CiteProc\Constraint;
11
12
use Seboettg\CiteProc\Exception\ClassNotFoundException;
13
14
/**
15
 * Class Factory
16
 * @package Seboettg\CiteProc\Constraint
17
 *
18
 * @author Sebastian Böttger <[email protected]>
19
 */
20
class Factory extends \Seboettg\CiteProc\Util\Factory
21
{
22
23
    const NAMESPACE_CONSTRAINTS = "Seboettg\\CiteProc\\Constraint\\";
24
25
    /**
26
     * @param string $name
27
     * @param string $value
28
     * @param string $match
29
     * @return mixed
30
     * @throws ClassNotFoundException
31
     */
32 55
    public static function createConstraint($name, $value, $match)
33
    {
34 55
        $className = "";
35 55
        $parts = explode("-", $name);
36
        array_walk($parts, function ($part) use (&$className) {
37 55
            $className .= ucfirst($part);
38 55
        });
39 55
        $className = self::NAMESPACE_CONSTRAINTS . $className;
40
41 55
        if (!class_exists($className)) {
42
            throw new ClassNotFoundException($className);
43
        }
44 55
        return new $className($value, $match);
45
    }
46
}
47