Completed
Push — master ( 140b29...4dbd37 )
by Sebastian
03:13
created

Crypter::crypt()   A

Complexity

Conditions 1
Paths 1

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 1
eloc 2
nc 1
nop 3
1
<?php
2
namespace phpbu\App\Runner;
3
4
use phpbu\App\Backup\Crypter as CrypterExe;
5
use phpbu\App\Backup\Crypter\Simulator;
6
use phpbu\App\Backup\Target;
7
use phpbu\App\Configuration;
8
use phpbu\App\Result;
9
10
/**
11
 * Crypter Runner
12
 *
13
 * @package    phpbu
14
 * @subpackage app
15
 * @author     Sebastian Feldmann <[email protected]>
16
 * @copyright  Sebastian Feldmann <[email protected]>
17
 * @license    https://opensource.org/licenses/MIT The MIT License (MIT)
18
 * @link       http://phpbu.de/
19
 * @since      Class available since Release 3.0.0
20
 */
21
class Crypter extends Abstraction
22
{
23
    /**
24
     * Execute or simulate the encryption.
25
     *
26
     * @param  \phpbu\App\Backup\Crypter $crypter
27
     * @param  \phpbu\App\Backup\Target  $target
28
     * @param  \phpbu\App\Result         $result
29
     * @throws \phpbu\App\Exception
30
     */
31
    public function run(CrypterExe $crypter, Target $target, Result $result)
32
    {
33
        if ($this->isSimulation()) {
34
            $this->simulate($crypter, $target, $result);
35
        } else {
36
            $this->crypt($crypter, $target, $result);
37
        }
38
        $target->setCrypter($crypter);
39
    }
40
41
    /**
42
     * Execute the encryption.
43
     *
44
     * @param  \phpbu\App\Backup\Crypter $crypter
45
     * @param  \phpbu\App\Backup\Target  $target
46
     * @param  \phpbu\App\Result         $result
47
     * @throws \phpbu\App\Exception
48
     */
49
    protected function crypt(CrypterExe $crypter, Target $target, Result $result)
50
    {
51
        $crypter->crypt($target, $result);
52
    }
53
54
    /**
55
     * Simulate the encryption.
56
     *
57
     * @param  \phpbu\App\Backup\Crypter $crypter
58
     * @param  \phpbu\App\Backup\Target  $target
59
     * @param  \phpbu\App\Result         $result
60
     * @throws \phpbu\App\Exception
61
     */
62
    protected function simulate(CrypterExe $crypter, Target $target, Result $result)
63
    {
64
        if ($crypter instanceof Simulator) {
65
            $crypter->simulate($target, $result);
66
        }
67
    }
68
}
69