Completed
Push — master ( 2c5dd4...1c78ad )
by Nikola
02:14
created

PostRotate::execute()   B

Complexity

Conditions 4
Paths 12

Size

Total Lines 33
Code Lines 16

Duplication

Lines 33
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 33
loc 33
rs 8.5806
cc 4
eloc 16
nc 12
nop 0
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
    public function execute()
39
    {
40
        try {
41
42
            $nominations = $this->profile->getPostRotator()->nominate($this->profile->getDestination()->all());
43
44
            if ($count = count($nominations) > 0) {
45
46
                /**
47
                 * @var BackupInterface $nomination
48
                 */
49
                foreach ($nominations as $nomination) {
50
51
                    $this->profile->getDestination()->delete($nomination->getName());
52
                }
53
            }
54
55
            $this->getLogger()->info(sprintf('Post-rotation successfully executed, %s backups rotated.', $count));
56
            $this->getEventDispatcher()->dispatch(BackupEvents::POST_ROTATE, new BackupEvent($this, $this->profile, $this->backup, $this));
57
58
        } catch (\Exception $e) {
59
60
            $this->getLogger()->error(sprintf('Could not execute post-rotation for profile "%s".', $this->profile->getName()), array(
61
                'message' => $e->getMessage(),
62
                'code' => $e->getCode(),
63
                'file' => $e->getFile(),
64
                'line' => $e->getLine(),
65
                'trace' => $e->getTrace()
66
            ));
67
68
            throw $e;
69
        }
70
    }
71
}