Code Duplication    Length = 45-45 lines in 2 locations

src/RunOpenCode/Backup/Workflow/PostRotate.php 1 location

@@ 30-74 (lines=45) @@
27
 *
28
 * @package RunOpenCode\Backup\Workflow
29
 */
30
class PostRotate extends BaseActivity implements LoggerAwareInterface, EventDispatcherAwareInterface
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
            $preRotateCount = $this->profile->getDestination()->count();
45
46
            if (count($nominations) > 0) {
47
48
                /**
49
                 * @var BackupInterface $nomination
50
                 */
51
                foreach ($nominations as $nomination) {
52
53
                    $this->profile->getDestination()->delete($nomination->getName());
54
                }
55
            }
56
57
            $this->getEventDispatcher()->dispatch(BackupEvents::POST_ROTATE, new BackupEvent($this, $this->profile, $this->backup, $this));
58
59
            $this->getLogger()->info(sprintf('Post-rotation successfully executed, %s backups rotated.', ($preRotateCount - $this->profile->getDestination()->count())));
60
61
        } catch (\Exception $e) {
62
63
            $this->getLogger()->error(sprintf('Could not execute post-rotation for profile "%s".', $this->profile->getName()), array(
64
                'message' => $e->getMessage(),
65
                'code' => $e->getCode(),
66
                'file' => $e->getFile(),
67
                'line' => $e->getLine(),
68
                'trace' => $e->getTrace()
69
            ));
70
71
            throw $e;
72
        }
73
    }
74
}
75

src/RunOpenCode/Backup/Workflow/PreRotate.php 1 location

@@ 32-76 (lines=45) @@
29
 *
30
 * @package RunOpenCode\Backup\Workflow
31
 */
32
class PreRotate extends BaseActivity implements LoggerAwareInterface, EventDispatcherAwareInterface
33
{
34
    use LoggerAwareTrait;
35
    use EventDispatcherAwareTrait;
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function execute()
41
    {
42
        try {
43
44
            $nominations = $this->profile->getPreRotator()->nominate($this->profile->getDestination()->all());
45
46
            $preRotateCount = $this->profile->getDestination()->count();
47
48
            if (count($nominations) > 0) {
49
50
                /**
51
                 * @var BackupInterface $nomination
52
                 */
53
                foreach ($nominations as $nomination) {
54
55
                    $this->profile->getDestination()->delete($nomination->getName());
56
                }
57
            }
58
59
            $this->getEventDispatcher()->dispatch(BackupEvents::PRE_ROTATE, new BackupEvent($this, $this->profile, $this->backup, $this));
60
61
            $this->getLogger()->info(sprintf('Pre-rotation successfully executed, %s backups rotated.', ($preRotateCount - $this->profile->getDestination()->count())));
62
63
        } catch (\Exception $e) {
64
65
            $this->getLogger()->error(sprintf('Could not execute pre-rotation for profile "%s".', $this->profile->getName()), array(
66
                'message' => $e->getMessage(),
67
                'code' => $e->getCode(),
68
                'file' => $e->getFile(),
69
                'line' => $e->getLine(),
70
                'trace' => $e->getTrace()
71
            ));
72
73
            throw $e;
74
        }
75
    }
76
}
77