1
|
|
|
<?php |
2
|
|
|
namespace phpbu\App\Runner; |
3
|
|
|
|
4
|
|
|
use phpbu\App\Backup\Sync as SyncExe; |
5
|
|
|
use phpbu\App\Backup\Sync\Simulator; |
6
|
|
|
use phpbu\App\Backup\Target; |
7
|
|
|
use phpbu\App\Result; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Sync 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 http://phpbu.de/ |
18
|
|
|
* @since Class available since Release 3.0.0 |
19
|
|
|
*/ |
20
|
|
View Code Duplication |
class Sync extends Abstraction |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Execute or simulate the sync. |
24
|
|
|
* |
25
|
|
|
* @param \phpbu\App\Backup\Sync $sync |
26
|
|
|
* @param \phpbu\App\Backup\Target $target |
27
|
|
|
* @param \phpbu\App\Result $result |
28
|
|
|
* @throws \phpbu\App\Exception |
29
|
|
|
*/ |
30
|
|
|
public function run(SyncExe $sync, Target $target, Result $result) |
31
|
|
|
{ |
32
|
|
|
$this->isSimulation() ? $this->simulate($sync, $target, $result) : $this->runSync($sync, $target, $result); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Execute the sync. |
37
|
|
|
* |
38
|
|
|
* @param \phpbu\App\Backup\Sync $sync |
39
|
|
|
* @param \phpbu\App\Backup\Target $target |
40
|
|
|
* @param \phpbu\App\Result $result |
41
|
|
|
* @throws \phpbu\App\Exception |
42
|
|
|
*/ |
43
|
|
|
protected function runSync(SyncExe $sync, Target $target, Result $result) |
44
|
|
|
{ |
45
|
|
|
$sync->sync($target, $result); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Simulate the sync process. |
50
|
|
|
* |
51
|
|
|
* @param \phpbu\App\Backup\Sync $sync |
52
|
|
|
* @param \phpbu\App\Backup\Target $target |
53
|
|
|
* @param \phpbu\App\Result $result |
54
|
|
|
* @throws \phpbu\App\Exception |
55
|
|
|
*/ |
56
|
|
|
protected function simulate(SyncExe $sync, Target $target, Result $result) |
57
|
|
|
{ |
58
|
|
|
if ($sync instanceof Simulator) { |
59
|
|
|
$sync->simulate($target, $result); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
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.