Completed
Branch master (72f544)
by Sebastian
11:13 queued 06:42
created

Key::crypt()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
ccs 0
cts 0
cp 0
rs 9.4285
cc 2
eloc 6
nc 2
nop 2
crap 6
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