Passed
Branch master (056094)
by Andreas
04:47
created

midgard_connection   A

Complexity

Total Complexity 32

Size/Duplication

Total Lines 166
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 3

Test Coverage

Coverage 52.63%

Importance

Changes 0
Metric Value
dl 0
loc 166
ccs 40
cts 76
cp 0.5263
rs 9.6
c 0
b 0
f 0
wmc 32
lcom 3
cbo 3

26 Methods

Rating   Name   Duplication   Size   Complexity  
A reopen() 0 2 1
A get_error_string() 0 6 2
A set_loglevel() 0 7 2
A copy() 0 3 1
A is_enabled_workspace() 0 3 1
A open_config() 0 4 1
A get_content_manager() 0 2 1
A set_error_string() 0 3 1
A enable_dbus() 0 2 1
A get_instance() 0 6 2
A set_error() 0 4 1
A get_error() 0 3 1
A enable_workspace() 0 2 1
A open() 0 13 3
A list_auth_types() 0 2 1
A get_loglevel() 0 3 1
A connect() 0 2 1
A is_connected() 0 3 1
A set_workspace() 0 2 1
A is_enabled_replication() 0 3 1
A is_enabled_quota() 0 3 1
A get_user() 0 6 2
A is_enabled_dbus() 0 3 1
A enable_replication() 0 3 1
A enable_quota() 0 2 1
A get_workspace() 0 2 1
1
<?php
2
/**
3
 * @author CONTENT CONTROL http://www.contentcontrol-berlin.de/
4
 * @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/
5
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
6
 */
7
8
use midgard\portable\storage\connection;
9
use midgard\portable\api\error\exception;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, exception. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
10
use midgard\portable\api\config;
11
12
class midgard_connection
13
{
14
    /**
15
     *
16
     * @var config
17
     */
18
    public $config;
19
20
    private static $instance;
21
22
    private $error_code = exception::OK;
23
24
    private $error_string;
25
26
    private $loglevel;
27
28
    private $available_loglevels = ['error', 'warn', 'warning', 'info', 'message', 'debug'];
29
30
    private $replication_enabled = true;
31
32 135
    public static function get_instance()
33
    {
34 135
        if (self::$instance === null) {
35
            self::$instance = new static;
36
        }
37 135
        return self::$instance;
38
    }
39
40
    public function copy()
41
    {
42
        return clone self::$instance;
43
    }
44
45 1
    public function open($name)
46
    {
47 1
        if ($this->config !== null) {
48 1
            $this->error_code = exception::INTERNAL;
49 1
            $this->error_string = 'MidgardConfig already associated with MidgardConnection';
50 1
            return false;
51
        }
52 1
        $config = new config;
53 1
        if (!$config->read_file($name, false)) {
54 1
            return false;
55
        }
56
        $this->config = $config;
57
        return true;
58
    }
59
60
    public function reopen()
61
    {
62
    }
63
64 12
    public function open_config(midgard_config $config)
65
    {
66 12
        $this->config = $config;
67 12
        $this->set_loglevel($config->loglevel);
0 ignored issues
show
Bug introduced by
The property loglevel does not exist on midgard\portable\api\config. Did you mean loglevel?
Loading history...
68 12
    }
69
70 1
    public function is_connected()
71
    {
72 1
        return is_object($this->config);
73
    }
74
75
    public function connect($signal, $callback, $userdata = '???')
0 ignored issues
show
Unused Code introduced by
The parameter $userdata is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

75
    public function connect($signal, $callback, /** @scrutinizer ignore-unused */ $userdata = '???')

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $signal is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

75
    public function connect(/** @scrutinizer ignore-unused */ $signal, $callback, $userdata = '???')

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $callback is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

75
    public function connect($signal, /** @scrutinizer ignore-unused */ $callback, $userdata = '???')

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
76
    {
77
    }
78
79 59
    public function get_error()
80
    {
81 59
        return $this->error_code;
82
    }
83
84 124
    public function set_error($errorcode)
85
    {
86 124
        $this->error_code = $errorcode;
87 124
        $this->error_string = null;
88 124
    }
89
90 57
    public function get_error_string()
91
    {
92 57
        if ($this->error_string === null) {
93 50
            return exception::get_error_string($this->error_code);
94
        }
95 23
        return $this->error_string;
96
    }
97
98 43
    public function set_error_string($string)
99
    {
100 43
        $this->error_string = $string;
101 43
    }
102
103 1
    public function get_user()
104
    {
105 1
        if (!$this->is_connected()) {
106 1
            return null;
107
        }
108
        return connection::get_user();
109
    }
110
111 13
    public function set_loglevel($level, $callback = '???')
0 ignored issues
show
Unused Code introduced by
The parameter $callback is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

111
    public function set_loglevel($level, /** @scrutinizer ignore-unused */ $callback = '???')

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
112
    {
113 13
        if (!in_array($level, $this->available_loglevels)) {
114 1
            return false;
115
        }
116 13
        $this->loglevel = $level;
117 13
        return true;
118
    }
119
120 13
    public function get_loglevel()
121
    {
122 13
        return $this->loglevel;
123
    }
124
125
    public function list_auth_types()
126
    {
127
    }
128
129
    public function enable_workspace($toggle)
0 ignored issues
show
Unused Code introduced by
The parameter $toggle is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

129
    public function enable_workspace(/** @scrutinizer ignore-unused */ $toggle)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
130
    {
131
    }
132
133
    public function is_enabled_workspace()
134
    {
135
        return false;
136
    }
137
138
    public function enable_replication($toggle)
139
    {
140
        $this->replication_enabled = (bool) $toggle;
141
    }
142
143
    public function is_enabled_replication()
144
    {
145
        return $this->replication_enabled;
146
    }
147
148
    public function enable_dbus($toggle)
0 ignored issues
show
Unused Code introduced by
The parameter $toggle is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

148
    public function enable_dbus(/** @scrutinizer ignore-unused */ $toggle)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
149
    {
150
    }
151
152
    public function is_enabled_dbus()
153
    {
154
        return false;
155
    }
156
157
    public function enable_quota($toggle)
0 ignored issues
show
Unused Code introduced by
The parameter $toggle is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

157
    public function enable_quota(/** @scrutinizer ignore-unused */ $toggle)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
158
    {
159
    }
160
161
    public function is_enabled_quota()
162
    {
163
        return false;
164
    }
165
166
    public function get_workspace()
167
    {
168
    }
169
170
    public function set_workspace($workspace)
0 ignored issues
show
Unused Code introduced by
The parameter $workspace is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

170
    public function set_workspace(/** @scrutinizer ignore-unused */ $workspace)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
171
    {
172
    }
173
174
    public function get_content_manager()
175
    {
176
    }
177
}
178