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

Clearable::simulateRemoteCleanup()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 4
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 2
crap 2.0625
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
}