Passed
Push — new-api ( 074931...f151f9 )
by Sebastian
03:55
created

Factory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A createConstraint() 0 12 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
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
        $className = implode("", array_map(function (string $part) {
36 63
            return ucfirst($part); //use locale-safe ucfirst function
37 63
        }, $parts));
38 63
        $className = self::NAMESPACE_CONSTRAINTS . $className;
39
40 63
        if (!class_exists($className)) {
41
            throw new ClassNotFoundException($className);
42
        }
43 63
        return new $className($value, $match);
44
    }
45
}
46