Completed
Push — master ( c9b303...a5dbf2 )
by Sebastian
04:56
created

Xtp   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 87
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
checkRequirements() 0 1 ?
getProtocolName() 0 1 ?
A setup() 0 18 4
A simulate() 0 10 1
1
<?php
2
namespace phpbu\App\Backup\Sync;
3
4
use phpseclib;
5
use phpbu\App\Result;
6
use phpbu\App\Backup\Sync;
7
use phpbu\App\Backup\Target;
8
use phpbu\App\Util\Arr;
9
use phpbu\App\Util\Str;
10
11
/**
12
 * Sftp sync
13
 *
14
 * @package    phpbu
15
 * @subpackage Backup
16
 * @author     Sebastian Feldmann <[email protected]>
17
 * @copyright  Sebastian Feldmann <[email protected]>
18
 * @license    https://opensource.org/licenses/MIT The MIT License (MIT)
19
 * @link       http://phpbu.de/
20
 * @since      Class available since Release 1.0.0
21
 */
22
abstract class Xtp implements Simulator
23
{
24
    /**
25
     * Host to connect to
26
     *
27
     * @var string
28
     */
29
    protected $host;
30
31
    /**
32
     * User to connect with
33
     *
34
     * @var string
35
     */
36
    protected $user;
37
38
    /**
39
     * Password to authenticate user
40
     *
41
     * @var string
42
     */
43
    protected $password;
44
45
    /**
46
     * Remote path where to put the backup
47
     *
48
     * @var string
49
     */
50
    protected $remotePath;
51
52
    /**
53
     * Check for loaded libraries or extensions.
54
     *
55
     * @throws \phpbu\App\Backup\Sync\Exception
56
     */
57
    abstract protected function checkRequirements();
58
59
    /**
60
     * Return implemented (*)TP protocol name.
61
     *
62
     * @return string
63
     */
64
    abstract protected function getProtocolName();
65
66
    /**
67
     * (non-PHPDoc)
68
     *
69
     * @see    \phpbu\App\Backup\Sync::setup()
70
     * @param  array $config
71
     * @throws \phpbu\App\Backup\Sync\Exception
72
     */
73
    public function setup(array $config)
74
    {
75
        $this->checkRequirements();
76
        if (!Arr::isSetAndNotEmptyString($config, 'host')) {
77
            throw new Exception('option \'host\' is missing');
78
        }
79
        if (!Arr::isSetAndNotEmptyString($config, 'user')) {
80
            throw new Exception('option \'user\' is missing');
81
        }
82
        if (!Arr::isSetAndNotEmptyString($config, 'password')) {
83
            throw new Exception('option \'password\' is missing');
84
        }
85
        $path             = Arr::getValue($config, 'path', '');
86
        $this->host       = $config['host'];
87
        $this->user       = $config['user'];
88
        $this->password   = $config['password'];
89
        $this->remotePath = Str::withoutTrailingSlash(Str::replaceDatePlaceholders($path));
90
    }
91
92
    /**
93
     * Simulate the sync execution.
94
     *
95
     * @param \phpbu\App\Backup\Target $target
96
     * @param \phpbu\App\Result        $result
97
     */
98
    public function simulate(Target $target, Result $result)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
99
    {
100
        $result->debug(
101
            'sync backup to ' . $this->getProtocolName() . ' server' . PHP_EOL
102
            . '  host:     ' . $this->host . PHP_EOL
103
            . '  user:     ' . $this->user . PHP_EOL
104
            . '  password:  ********' . PHP_EOL
105
            . '  path:     ' . $this->remotePath
106
        );
107
    }
108
}
109