Factory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 19
rs 10
c 1
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A createConstraint() 0 12 2
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