Completed
Pull Request — master (#145)
by Vitaly
02:44
created

Sync::validateConfig()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 3
nop 2
crap 3
1
<?php
2
namespace phpbu\App\Backup;
3
4
use phpbu\App\Backup\Sync\Exception;
5
use phpbu\App\Backup\Sync\Simulator;
6
use phpbu\App\Result;
7
use phpbu\App\Util;
8
9
/**
10
 * Sync
11
 *
12
 * @package    phpbu
13
 * @subpackage Backup
14
 * @author     Sebastian Feldmann <[email protected]>
15
 * @copyright  Sebastian Feldmann <[email protected]>
16
 * @license    https://opensource.org/licenses/MIT The MIT License (MIT)
17
 * @link       http://phpbu.de/
18
 * @since      Class available since Release 1.0.0
19
 */
20
abstract class Sync implements Simulator
21
{
22
    /**
23
     * Setup the Sync object with all xml options.
24
     *
25
     * @param array $options
26
     */
27
    abstract public function setup(array $options);
28
29
    /**
30
     * Execute the Sync
31
     * Copy your backup to another location
32
     *
33
     * @param \phpbu\App\Backup\Target $target
34
     * @param \phpbu\App\Result        $result
35
     */
36
    abstract public function sync(Target $target, Result $result);
0 ignored issues
show
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
37
38
    /**
39
     * Make sure all mandatory keys are present in given config.
40
     *
41
     * @param  array $config
42
     * @param  array $keys
43
     * @throws Exception
44
     */
45 30
    protected function validateConfig(array $config, array $keys)
46
    {
47 30
        foreach ($keys as $option) {
48 30
            if (!Util\Arr::isSetAndNotEmptyString($config, $option)) {
49 30
                throw new Exception($option . ' is mandatory');
50
            }
51
        }
52 13
    }
53
}
54