Completed
Push — master ( 4f1d49...8186c0 )
by Sebastian
07:15
created

Abstraction::toAbsolutePath()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 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 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 Abstraction extends Cli
23
{
24
    /**
25
     * (non-PHPDoc)
26
     *
27
     * @see    \phpbu\App\Backup\Crypter
28
     * @param  \phpbu\App\Backup\Target $target
29
     * @param  \phpbu\App\Result        $result
30
     * @throws Exception
31
     */
32
    public function crypt(Target $target, Result $result)
33
    {
34
        $crypt = $this->execute($target);
35
        $name  = strtolower(get_class($this));
36
37
        $result->debug($name . ':' . $crypt->getCmd());
38
39
        if (!$crypt->wasSuccessful()) {
40
            throw new Exception($name . ' failed:' . PHP_EOL . $crypt->getStdErr());
41
        }
42
    }
43
44
    /**
45
     * Simulate the encryption.
46
     *
47
     * @param \phpbu\App\Backup\Target $target
48
     * @param \phpbu\App\Result        $result
49
     */
50
    public function simulate(Target $target, Result $result)
51
    {
52
        $result->debug(
53
            'execute encryption:' . PHP_EOL .
54
            $this->getExecutable($target)->getCmd()
0 ignored issues
show
Bug introduced by
The method getCmd() does not seem to exist on object<phpbu\App\Cli\Executable>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
        );
56
    }
57
58
    /**
59
     * Return an absolute path relative to the used file.
60
     *
61
     * @param  string $path
62
     * @param  string $default
63
     * @return string
64
     */
65
    protected function toAbsolutePath($path, $default = null)
66
    {
67
        return !empty($path) ? Util\Cli::toAbsolutePath($path, Util\Cli::getBase('configuration')) : $default;
68
    }
69
}
70