Fetch   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 8
dl 0
loc 36
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B execute() 0 30 3
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\Event\BackupEvent;
16
use RunOpenCode\Backup\Event\BackupEvents;
17
use RunOpenCode\Backup\Exception\EmptySourceException;
18
19
/**
20
 * Class Fetch
21
 *
22
 * Activity "Fetch": fetch backups from sources.
23
 *
24
 * @package RunOpenCode\Backup\Workflow
25
 */
26
class Fetch extends BaseActivity
27
{
28
    /**
29
     * {@inheritdoc}
30
     */
31 10
    public function execute()
32
    {
33
        try {
34
35 10
            $this->backup->addFiles($this->profile->getSource()->fetch());
36 8
            $this->getEventDispatcher()->dispatch(BackupEvents::FETCH, new BackupEvent($this, $this->profile, $this->backup, $this));
37
38 6
        } catch (\Exception $e) {
39
40 2
            $this->getLogger()->error(sprintf('Could not fetch source files for profile "%s".', $this->profile->getName()), array(
41 2
                'message' => $e->getMessage(),
42 2
                'code' => $e->getCode(),
43 2
                'file' => $e->getFile(),
44 2
                'line' => $e->getLine(),
45 2
                'trace' => $e->getTrace()
46 1
            ));
47
48 2
            throw $e;
49
        }
50
51 8
        if (count($this->backup->getFiles()) == 0) {
52
53 2
            throw new EmptySourceException('Nothing to backup.');
54
55
        } else {
56
57 6
            $this->getLogger()->info(sprintf('Source files successfully fetched, %s total files are scheduled for backup.', count($this->backup->getFiles())));
58
59
        }
60 6
    }
61
}
62