Completed
Pull Request — master (#2)
by
unknown
02:18
created

Config   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 16
lcom 0
cbo 0
dl 0
loc 68
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
D __construct() 0 50 13
A getHost() 0 4 1
A getPort() 0 4 1
A getDb() 0 4 1
1
<?php
2
3
namespace Kraken\Redis;
4
5
use InvalidArgumentException;
6
7
class Config
8
{
9
    public function __construct($target)
10
    {
11
        if ($target === null) {
12
            $target = 'tcp://127.0.0.1';
13
        }
14
15
        if (strpos($target, '://') === false) {
16
            $target = 'tcp://' . $target;
17
        }
18
19
        $parts = parse_url($target);
20
        if ($parts === false || !isset($parts['host']) || $parts['scheme'] !== 'tcp') {
21
            throw new InvalidArgumentException('Given URL can not be parsed');
22
        }
23
24
        if (!isset($parts['port'])) {
25
            $parts['port'] = 6379;
26
            $this->port = 6379;
0 ignored issues
show
Bug introduced by
The property port does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
27
        }
28
29
        if ($parts['host'] === 'localhost') {
30
            $parts['host'] = '127.0.0.1';
31
            $this->host = '127.0.0.1';
0 ignored issues
show
Bug introduced by
The property host does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
32
        }
33
34
        $auth = null;
35
        if (isset($parts['user'])) {
36
            $auth = $parts['user'];
37
            $this->auth = $auth;
0 ignored issues
show
Bug introduced by
The property auth does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
38
        }
39
40
        if (isset($parts['pass'])) {
41
            $auth .= ':' . $parts['pass'];
42
        }
43
44
        if ($auth !== null) {
45
            $parts['auth'] = $auth;
46
        }
47
48
        if (isset($parts['path']) && $parts['path'] !== '') {
49
            $parts['db'] = substr($parts['path'], 1);
50
        }
51
52
        unset($parts['scheme'], $parts['user'], $parts['pass'], $parts['path']);
53
54
        $this->host = $parts['host'];
55
        $this->port = $parts['port'];
56
        $this->auth = $auth;
57
        $this->db =  $parts['db'];
0 ignored issues
show
Bug introduced by
The property db does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
58
    }
59
60
    public function getHost()
61
    {
62
63
    }
64
65
    public function getPort()
66
    {
67
68
    }
69
70
    public function getDb()
71
    {
72
73
    }
74
}