PostRotate   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 10

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 10
dl 45
loc 45
ccs 18
cts 20
cp 0.9
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B execute() 36 36 4

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
/*
3
 * This file is part of the Backup package, an RunOpenCode project.
4
 *
5
 * (c) 2015 RunOpenCode
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * This project is fork of "kbond/php-backup", for full credits info, please
11
 * view CREDITS file that was distributed with this source code.
12
 */
13
namespace RunOpenCode\Backup\Workflow;
14
15
use RunOpenCode\Backup\Contract\BackupInterface;
16
use RunOpenCode\Backup\Contract\EventDispatcherAwareInterface;
17
use RunOpenCode\Backup\Contract\LoggerAwareInterface;
18
use RunOpenCode\Backup\Event\BackupEvent;
19
use RunOpenCode\Backup\Event\BackupEvents;
20
use RunOpenCode\Backup\Event\EventDispatcherAwareTrait;
21
use RunOpenCode\Backup\Log\LoggerAwareTrait;
22
23
/**
24
 * Class PostRotate
25
 *
26
 * Activity "PostRotation": nominate backups for rotation after backup is uploaded to destination.
27
 *
28
 * @package RunOpenCode\Backup\Workflow
29
 */
30 View Code Duplication
class PostRotate extends BaseActivity implements LoggerAwareInterface, EventDispatcherAwareInterface
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...
31
{
32
    use LoggerAwareTrait;
33
    use EventDispatcherAwareTrait;
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 8
    public function execute()
39
    {
40
        try {
41
42 8
            $nominations = $this->profile->getPostRotator()->nominate($this->profile->getDestination()->all());
43
44 8
            $preRotateCount = $this->profile->getDestination()->count();
45
46 8
            if (count($nominations) > 0) {
47
48
                /**
49
                 * @var BackupInterface $nomination
50
                 */
51 2
                foreach ($nominations as $nomination) {
52
53 2
                    $this->profile->getDestination()->delete($nomination->getName());
54
                }
55
            }
56
57 6
            $this->getEventDispatcher()->dispatch(BackupEvents::POST_ROTATE, new BackupEvent($this, $this->profile, $this->backup, $this));
58
59 6
            $this->getLogger()->info(sprintf('Post-rotation successfully executed, %s backups rotated.', ($preRotateCount - $this->profile->getDestination()->count())));
60
61 5
        } catch (\Exception $e) {
62
63 2
            $this->getLogger()->error(sprintf('Could not execute post-rotation for profile "%s".', $this->profile->getName()), array(
64 2
                'message' => $e->getMessage(),
65 2
                'code' => $e->getCode(),
66 2
                'file' => $e->getFile(),
67 2
                'line' => $e->getLine(),
68 2
                'trace' => $e->getTrace()
69 1
            ));
70
71 2
            throw $e;
72
        }
73 6
    }
74
}
75