Completed
Push — master ( da23ca...d8fe59 )
by Sebastian
04:21
created

Location   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 97
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUser() 0 4 1
A setHost() 0 4 1
A setPath() 0 4 1
A isValid() 0 4 1
A toString() 0 4 1
A __toString() 0 17 4
1
<?php
2
namespace phpbu\App\Cli\Executable\Rsync;
3
4
use phpbu\App\Exception;
5
6
/**
7
 * Rsync location class.
8
 *
9
 * @package    phpbu
10
 * @subpackage Backup
11
 * @author     Sebastian Feldmann <[email protected]>
12
 * @copyright  Sebastian Feldmann <[email protected]>
13
 * @license    https://opensource.org/licenses/MIT The MIT License (MIT)
14
 * @link       http://phpbu.de/
15
 * @since      Class available since Release 3.1.4
16
 */
17
class Location
18
{
19
    /**
20
     * Username
21
     *
22
     * @var string
23
     */
24
    private $user;
25
26
    /**
27
     * Hostname
28
     *
29
     * @var string
30
     */
31
    private $host;
32
33
    /**
34
     * Path
35
     *
36
     * @var string
37
     */
38
    private $path;
39
40
    /**
41
     * Set user
42
     *
43
     * @param string $user
44
     */
45
    public function setUser($user)
46
    {
47
        $this->user = $user;
48
    }
49
50
    /**
51
     * Set host.
52
     *
53
     * @param string $host
54
     */
55
    public function setHost($host)
56
    {
57
        $this->host = $host;
58
    }
59
60
    /**
61
     * Set path.
62
     *
63
     * @param string $path
64
     */
65
    public function setPath($path)
66
    {
67
        $this->path = $path;
68
    }
69
70
    /**
71
     * Is path valid
72
     *
73
     * @return bool
74
     */
75
    public function isValid()
76
    {
77
        return !empty($this->path);
78
    }
79
80
    /**
81
     * To string method.
82
     *
83
     * @return string
84
     */
85
    public function toString()
86
    {
87
        return $this->__toString();
88
    }
89
90
    /**
91
     * Magic to string method
92
     *
93
     * @return string
94
     * @throws \phpbu\App\Exception
95
     */
96
    public function __toString()
97
    {
98
        if (!$this->isValid()) {
99
            throw new Exception('invalid rsync path');
100
        }
101
        $return = '';
102
        if (null !== $this->host) {
103
            // remote user
104
            if (null !== $this->user) {
105
                $return .= $this->user . '@';
106
            }
107
            $return .= $this->host . ':';
108
        }
109
        $return .= $this->path;
110
111
        return $return;
112
    }
113
}
114