Completed
Push — master ( 0f1023...72f544 )
by Sebastian
08:24 queued 04:31
created

Key   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
c 2
b 0
f 1
lcom 0
cbo 5
dl 0
loc 35
ccs 2
cts 2
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A crypt() 0 11 2
A toAbsolutePath() 0 4 2
1
<?php
2
namespace phpbu\App\Backup\Crypter;
3
4
use phpbu\App\Backup\Cli;
5
use phpbu\App\Backup\Crypter;
6
use phpbu\App\Backup\Target;
7
use phpbu\App\Cli\Executable;
8
use phpbu\App\Result;
9
use phpbu\App\Util;
10
11
/**
12
 * Abstract key crypter class.
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 2.1.6
21
 */
22
abstract class Key extends Cli
23
{
24
25
    /**
26
     * (non-PHPDoc)
27
     *
28
     * @see    \phpbu\App\Backup\Crypter
29
     * @param  \phpbu\App\Backup\Target $target
30 7
     * @param  \phpbu\App\Result        $result
31
     * @throws Exception
32 7
     */
33
    public function crypt(Target $target, Result $result)
34
    {
35
        $crypt = $this->execute($target);
36
        $name  = strtolower(get_class($this));
37
38
        $result->debug($name . ':' . $crypt->getCmd());
39
40
        if (!$crypt->wasSuccessful()) {
41
            throw new Exception($name . ' failed:' . PHP_EOL . $crypt->getStdErr());
42
        }
43
    }
44
45
    /**
46
     * Return an absolute path relative to the used file.
47
     *
48
     * @param  string $path
49
     * @param  string $default
50
     * @return string
51
     */
52
    protected function toAbsolutePath($path, $default = null)
53
    {
54
        return !empty($path) ? Util\Cli::toAbsolutePath($path, Util\Cli::getBase('configuration')) : $default;
55
    }
56
}
57