Completed
Push — master ( eaaddc...057168 )
by Sebastian
09:01
created

Crypter::run()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 5
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 5
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 3
crap 2
1
<?php
2
namespace phpbu\App\Runner\Backup;
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\Result;
8
9
/**
10
 * Crypter Runner
11
 *
12
 * @package    phpbu
13
 * @subpackage app
14
 * @author     Sebastian Feldmann <[email protected]>
15
 * @copyright  Sebastian Feldmann <[email protected]>
16
 * @license    https://opensource.org/licenses/MIT The MIT License (MIT)
17
 * @link       https://phpbu.de/
18
 * @since      Class available since Release 3.0.0
19
 */
20 View Code Duplication
class Crypter extends Abstraction
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
{
22
    /**
23
     * Execute or simulate the encryption.
24
     *
25
     * @param  \phpbu\App\Backup\Crypter $crypter
26
     * @param  \phpbu\App\Backup\Target  $target
27
     * @param  \phpbu\App\Result         $result
28
     * @throws \phpbu\App\Exception
29
     */
30 3
    public function run(CrypterExe $crypter, Target $target, Result $result)
31
    {
32 3
        $this->isSimulation() ? $this->simulate($crypter, $target, $result) : $this->crypt($crypter, $target, $result);
33 2
        $target->setCrypter($crypter);
34 2
    }
35
36
    /**
37
     * Execute the encryption.
38
     *
39
     * @param  \phpbu\App\Backup\Crypter $crypter
40
     * @param  \phpbu\App\Backup\Target  $target
41
     * @param  \phpbu\App\Result         $result
42
     * @throws \phpbu\App\Exception
43
     */
44 2
    protected function crypt(CrypterExe $crypter, Target $target, Result $result)
45
    {
46 2
        $crypter->crypt($target, $result);
47 1
    }
48
49
    /**
50
     * Simulate the encryption.
51
     *
52
     * @param  \phpbu\App\Backup\Crypter $crypter
53
     * @param  \phpbu\App\Backup\Target  $target
54
     * @param  \phpbu\App\Result         $result
55
     * @throws \phpbu\App\Exception
56
     */
57 1
    protected function simulate(CrypterExe $crypter, Target $target, Result $result)
58
    {
59 1
        if ($crypter instanceof Simulator) {
60 1
            $crypter->simulate($target, $result);
61
        }
62 1
    }
63
}
64