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

Factory::createConstraint()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2.0054

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 13
ccs 8
cts 9
cp 0.8889
crap 2.0054
rs 10
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