Completed
Pull Request — master (#140)
by
unknown
05:20
created

Clearable   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 47
ccs 10
cts 14
cp 0.7143
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B setUpClearable() 0 17 5
A simulateRemoteCleanup() 0 6 2
1
<?php
2
namespace phpbu\App\Backup\Sync;
3
4
use phpbu\App\Backup\Cleaner;
5
use phpbu\App\Backup\Target;
6
use phpbu\App\Configuration\Backup\Cleanup;
7
use phpbu\App\Factory;
8
use phpbu\App\Result;
9
10
/**
11
 * Clearable trait
12
 *
13
 * @package    phpbu
14
 * @subpackage Sync
15
 * @author     Sebastian Feldmann <[email protected]>
16
 * @author     Vitaly Baev <[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 5.1.0
21
 */
22
trait Clearable
23
{
24
    /**
25
     * @var Cleanup
26
     */
27
    protected $cleanupConfig;
28
29
    /**
30
     * @var Cleaner
31
     */
32
    protected $cleaner;
33
34
    /**
35
     * Check sync clean configuration entities and set up a proper cleaner
36
     *
37
     * @param array $options
38
     * @throws \phpbu\App\Exception
39
     */
40 16
    public function setUpClearable(array $options)
41
    {
42 16
        $config = [];
43 16
        foreach ($options as $key => $value) {
44 16
            if (strpos($key, "cleanup.") === 0) {
45 16
                $config[str_replace('cleanup.', '', $key)] = $value;
46
            }
47
        }
48
49 16
        if (isset($config['type'])) {
50
            $skip = isset($config['skipOnFailure']) ? (bool) $config['skipOnFailure'] : true;
51
            // creating cleanup config
52
            $this->cleanupConfig = new Cleanup($config['type'], $skip, $config);
53
            // creating cleaner
54
            $this->cleaner = (new Factory())->createCleaner($this->cleanupConfig->type, $this->cleanupConfig->options);
55
        }
56 16
    }
57
58
    /**
59
     * @param Target $target
60
     * @param Result $result
61
     */
62 6
    public function simulateRemoteCleanup(Target $target, Result $result)
63
    {
64 6
        if ($this->cleaner) {
65
            $result->debug("  sync cleanup: {$this->cleanupConfig->type}" . PHP_EOL);
66
        }
67
    }
68
}