Passed
Push — new-api ( 18d26d...074931 )
by Sebastian
04:59
created

Factory::createConstraint()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 10
ccs 6
cts 7
cp 0.8571
crap 2.0116
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
use function Seboettg\CiteProc\ucfirst;
14
15
/**
16
 * Class Factory
17
 * @package Seboettg\CiteProc\Constraint
18
 *
19
 * @author Sebastian Böttger <[email protected]>
20
 */
21
class Factory extends \Seboettg\CiteProc\Util\Factory
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 63
    public static function createConstraint(string $name, string $value, string $match)
33
    {
34 63
        $parts = explode("-", $name);
35 63
        $className = implode("", array_map("ucfirst", $parts));
36 63
        $className = self::NAMESPACE_CONSTRAINTS . $className;
37
38 63
        if (!class_exists($className)) {
39
            throw new ClassNotFoundException($className);
40
        }
41 63
        return new $className($value, $match);
42
    }
43
}
44