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

Crypter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 44
loc 44
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 5 5 2
A crypt() 4 4 1
A simulate() 6 6 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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