Factory::createConstraint()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

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 12
rs 10
1
<?php
2
declare(strict_types=1);
3
/*
4
 * citeproc-php
5
 *
6
 * @link        http://github.com/seboettg/citeproc-php for the source repository
7
 * @copyright   Copyright (c) 2016 Sebastian Böttger.
8
 * @license     https://opensource.org/licenses/MIT
9
 */
10
11
namespace Seboettg\CiteProc\Constraint;
12
13
use Seboettg\CiteProc\Exception\ClassNotFoundException;
14
use function Seboettg\CiteProc\ucfirst;
15
16
class Factory extends \Seboettg\CiteProc\Util\Factory
17
{
18
    private const NAMESPACE_CONSTRAINTS = "Seboettg\\CiteProc\\Constraint\\";
19
20
    /**
21
     * @throws ClassNotFoundException
22
     */
23
    public static function createConstraint(string $name, string $value, string $match): Constraint
24
    {
25
        $parts = explode("-", $name);
26
        $className = implode("", array_map(function ($part) {
27
            return ucfirst($part);//overridden function
28
        }, $parts));
29
        $className = self::NAMESPACE_CONSTRAINTS . $className;
30
31
        if (!class_exists($className)) {
32
            throw new ClassNotFoundException($className);
33
        }
34
        return new $className($value, $match);
35
    }
36
}
37