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

midcom_services_rcs_config::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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