Passed
Push — master ( e13826...b82956 )
by Sebastian
16:47 queued 09:52
created

Factory::loadLocale()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
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\Util;
11
use Seboettg\CiteProc\Exception\CiteProcException;
12
use Seboettg\CiteProc\Exception\ClassNotFoundException;
13
14
15
/**
16
 * Class Factory
17
 * @package Seboettg\CiteProc\Util
18
 *
19
 * @author Sebastian Böttger <[email protected]>
20
 */
21
class Factory
22
{
23
    const CITE_PROC_NODE_NAMESPACE = "Seboettg\\CiteProc\\Rendering";
24
25
    static $nodes = [
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $nodes.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
26
27
        'layout'        => "\\Layout",
28
        'text'          => "\\Text",
29
        "macro"         => "\\Macro",
30
        "number"        => "\\Number",
31
        "label"         => "\\Label",
32
        "group"         => "\\Group",
33
        "choose"        => "\\Choose\\Choose",
34
        "if"            => "\\Choose\\ChooseIf",
35
        "else-if"       => "\\Choose\\ChooseElseIf",
36
        "else"          => "\\Choose\\ChooseElse",
37
        'date'          => "\\Date\\Date",
38
        "date-part"     => "\\Date\\DatePart",
39
        "names"         => "\\Name\\Names",
40
        "name"          => "\\Name\\Name",
41
        "name-part"     => "\\Name\\NamePart",
42
        "substitute"    => "\\Name\\Substitute",
43
        "et-al"         => "\\Name\\EtAl"
44
    ];
45
46
    public static function create($node, $param = null)
47
    {
48
        $nodeClass = self::CITE_PROC_NODE_NAMESPACE . self::$nodes[$node->getName()];
49
        if (!class_exists($nodeClass)) {
50
            throw new ClassNotFoundException($nodeClass);
51
        }
52
        if ($param != null) {
53
            return new $nodeClass($node, $param);
54
        }
55
        return new $nodeClass($node);
56
    }
57
}