Completed
Push — master ( e8fccc...474902 )
by Andreas
23:28
created

midcom_services_rcs_config   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
c 2
b 0
f 0
dl 0
loc 59
ccs 14
cts 16
cp 0.875
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A use_rcs() 0 3 1
A get_bin_prefix() 0 3 1
A get_rootdir() 0 8 2
A get_backend_class() 0 7 2
1
<?php
2
/**
3
 * The class containing the configuration options for RCS.
4
 *
5
 * @author tarjei huse
6
 * @package midcom.services.rcs
7
 * @copyright The Midgard Project, http://www.midgard-project.org
8
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
9
 */
10
11
/**
12
 * The config class is used to generate the RCS configuration.
13
 *
14
 * @see midcom_services_rcs for an overview of the options
15
 * @package midcom.services.rcs
16
 */
17
class midcom_services_rcs_config
18
{
19
    /**
20
     * The array of configuration options
21
     *
22
     * @var midcom_config
23
     */
24
    private $config;
25
26
    /**
27
     * Constructor
28
     */
29 9
    public function __construct(midcom_config $config)
30
    {
31 9
        $this->config = $config;
32 9
    }
33
34
    /**
35
     * Returns the root of the directory containing the version-controlled files.
36
     */
37 83
    public function get_rootdir() : string
38
    {
39 83
        if (empty($this->config['midcom_services_rcs_root'])) {
40
            $basedir = dirname(midgard_connection::get_instance()->config->sharedir);
41
            $this->config['midcom_services_rcs_root'] = $basedir . '/rcs';
42
        }
43
44 83
        return $this->config['midcom_services_rcs_root'];
45
    }
46
47
    /**
48
     * If the RCS service is enabled
49
     * (set by midcom_services_rcs_enable)
50
     *
51
     * @return boolean true if it is enabled
52
     */
53 83
    public function use_rcs() : bool
54
    {
55 83
        return !empty($this->config['midcom_services_rcs_enable']);
56
    }
57
58
    /**
59
     * Returns the prefix for the rcs utilities.
60
     */
61 83
    public function get_bin_prefix() : string
62
    {
63 83
        return $this->config['midcom_services_rcs_bin_dir'] . '/';
64
    }
65
66
    /**
67
     * Returns the backend classname.
68
     */
69 82
    public function get_backend_class() : string
70
    {
71 82
        if ($this->use_rcs()) {
72 82
            return midcom_services_rcs_backend_rcs::class;
73
        }
74
75 1
        return midcom_services_rcs_backend_null::class;
76
    }
77
}
78