Completed
Pull Request — master (#140)
by
unknown
03:01
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
trait Clearable
11
{
12
    /**
13
     * @var Cleanup
14
     */
15
    protected $cleanupConfig;
16
17
    /**
18
     * @var Cleaner
19
     */
20
    protected $cleaner;
21
22
    /**
23
     * Check sync clean configuration entities and set up a proper cleaner
24
     *
25
     * @param array $options
26
     * @throws \phpbu\App\Exception
27
     */
28 14
    public function setUpClearable(array $options)
29
    {
30 14
        $config = [];
31 14
        foreach ($options as $key => $value) {
32 14
            if (strpos($key, "cleanup.") === 0) {
33 14
                $config[str_replace('cleanup.', '', $key)] = $value;
34
            }
35
        }
36
37 14
        if (isset($config['type'])) {
38
            $skip = isset($config['skipOnFailure']) ? (bool) $config['skipOnFailure'] : true;
39
            // creating cleanup config
40
            $this->cleanupConfig = new Cleanup($config['type'], $skip, $config);
41
            // creating cleaner
42
            $this->cleaner = (new Factory())->createCleaner($this->cleanupConfig->type, $this->cleanupConfig->options);
43
        }
44 14
    }
45
46
    /**
47
     * @param Target $target
48
     * @param Result $result
49
     */
50 6
    public function simulateRemoteCleanup(Target $target, Result $result)
51
    {
52 6
        if ($this->cleaner) {
53
            $result->debug("  sync cleanup: {$this->cleanupConfig->type}" . PHP_EOL);
54
        }
55
    }
56
}