UsedClass::obtainClassNameToUse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace BfwSql;
4
5
/**
6
 * To obtain the class name to used for class declared into a config file
7
 * 
8
 * @package bfw-sql
9
 * @author Vermeulen Maxime <[email protected]>
10
 * @version 2.0
11
 */
12
class UsedClass
13
{
14
    /**
15
     * @var \BfwSql\UsedClass|null $instance UsedClass instance (Singleton)
16
     */
17
    protected static $instance;
18
    
19
    /**
20
     * @var \BFW\Config $config The config instance for the current module
21
     */
22
    protected $config;
23
    
24
    /**
25
     * protected for Singleton pattern
26
     * 
27
     * @param \BFW\Config $config The config instance for the current module
28
     */
29
    protected function __construct(\BFW\Config $config)
30
    {
31
        $this->config = $config;
32
    }
33
    
34
    /**
35
     * Get the UsedClass instance (Singleton pattern)
36
     * 
37
     * @param \BFW\Config|null $config The config instance for the module
38
     * 
39
     * @return \BfwSql\UsedClass
40
     */
41
    public static function getInstance($config = null): \BfwSql\UsedClass
42
    {
43
        if (self::$instance === null) {
44
            $class = get_called_class();
45
            self::$instance = new $class($config);
46
        }
47
        
48
        return self::$instance;
49
    }
50
    
51
    /**
52
     * Getter accessor to config property
53
     * 
54
     * @return \BFW\Config
55
     */
56
    public function getConfig(): \BFW\Config
57
    {
58
        return $this->config;
59
    }
60
61
    /**
62
     * Obtain the class name declared into config file "class.php" for a key
63
     * 
64
     * @param string $classNameKey The class name key into the config file
65
     * 
66
     * @return string
67
     */
68
    public function obtainClassNameToUse(string $classNameKey): string
69
    {
70
        return $this->config->getValue($classNameKey, 'class.php');
71
    }
72
}
73