Completed
Push — master ( 4cd686...a44c06 )
by Andreas
05:44
created

midgard_connection::get_loglevel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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

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 = array('error', 'warn', 'warning', 'info', 'message', 'debug');
29
30
    private $replication_enabled = false;
31
32 5
    function __construct()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
33
    {
34
        //??
35 5
    }
36
37 5
    function __destruct()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
38
    {
39
        //??
40 5
    }
41
42 121
    public static function get_instance()
43
    {
44 121
        if (self::$instance === null)
45 121
        {
46
            self::$instance = new static;
47
        }
48 121
        return self::$instance;
49
    }
50
51
    public function copy()
52
    {
53
        return clone self::$instance;
54
    }
55
56 1
    public function open($name)
57
    {
58 1
        if ($this->config !== null)
59 1
        {
60 1
            $this->error_code = exception::INTERNAL;
61 1
            $this->error_string = 'MidgardConfig already associated with MidgardConnection';
62 1
            return false;
63
        }
64 1
        $config = new config;
65 1
        if (!$config->read_file($name, false))
66 1
        {
67 1
            return false;
68
        }
69
        $this->config = $config;
70
        return true;
71
    }
72
73
    public function reopen()
74
    {
75
76
    }
77
78 12
    public function open_config(midgard_config $config)
79
    {
80 12
        $this->config = $config;
0 ignored issues
show
Documentation Bug introduced by
It seems like $config of type object<midgard_config> is incompatible with the declared type object<midgard\portable\api\config> of property $config.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
81 12
        $this->set_loglevel($config->loglevel);
82 12
    }
83
84 1
    public function is_connected()
85
    {
86 1
        return is_object($this->config);
87
    }
88
89
    public function connect($signal, $callback, $userdata = '???' )
0 ignored issues
show
Unused Code introduced by
The parameter $signal is not used and could be removed.

This check looks from 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.

This check looks from 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 $userdata is not used and could be removed.

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

Loading history...
90
    {
91
92
    }
93
94 46
    public function get_error()
95
    {
96 46
        return $this->error_code;
97
    }
98
99 110
    public function set_error($errorcode)
100
    {
101 110
        $this->error_code = $errorcode;
102 110
        $this->error_string = null;
103 110
    }
104
105 44
    public function get_error_string()
106
    {
107 44
        if ($this->error_string === null)
108 44
        {
109 41
            return exception::get_error_string($this->error_code);
110
        }
111 14
        return $this->error_string;
112
    }
113
114 34
    public function set_error_string($string)
115
    {
116 34
        $this->error_string = $string;
117 34
    }
118
119 1
    public function get_user()
120
    {
121 1
        if (!$this->is_connected())
122 1
        {
123 1
            return null;
124
        }
125
        return connection::get_user();
126
    }
127
128 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.

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

Loading history...
129
    {
130 13
        if (!in_array($level, $this->available_loglevels))
131 13
        {
132 1
            return false;
133
        }
134 13
        $this->loglevel = $level;
135 13
        return true;
136
    }
137
138 13
    public function get_loglevel()
139
    {
140 13
        return $this->loglevel;
141
    }
142
143
    public function list_auth_types()
144
    {
145
146
    }
147
148
    public function enable_workspace($toggle)
0 ignored issues
show
Unused Code introduced by
The parameter $toggle is not used and could be removed.

This check looks from 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
153
    public function is_enabled_workspace()
154
    {
155
        return false;
156
    }
157
158
    public function enable_replication($toggle)
159
    {
160
        $this->replication_enabled = (bool) $toggle;
161
    }
162
163
    public function is_enabled_replication()
164
    {
165
        return $this->replication_enabled;
166
    }
167
168
    public function enable_dbus($toggle)
0 ignored issues
show
Unused Code introduced by
The parameter $toggle is not used and could be removed.

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

Loading history...
169
    {
170
171
    }
172
173
    public function is_enabled_dbus()
174
    {
175
        return false;
176
    }
177
178
    public function enable_quota($toggle)
0 ignored issues
show
Unused Code introduced by
The parameter $toggle is not used and could be removed.

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

Loading history...
179
    {
180
181
    }
182
183
    public function is_enabled_quota()
184
    {
185
        return false;
186
    }
187
188
    public function get_workspace()
189
    {
190
191
    }
192
193
    public function set_workspace($workspace)
0 ignored issues
show
Unused Code introduced by
The parameter $workspace is not used and could be removed.

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

Loading history...
194
    {
195
196
    }
197
198
    public function get_content_manager()
199
    {
200
201
    }
202
}
203