CopyClient   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 37
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A sync() 0 13 1
1
<?php
2
3
namespace SyncFS\Client;
4
5
use Symfony\Component\Filesystem\Filesystem;
6
use SyncFS\Event;
7
8
/**
9
 * Class CopyClient
10
 *
11
 * @package SyncFS\Client
12
 * @author  Matej Velikonja <[email protected]>
13
 */
14
class CopyClient implements ClientInterface
15
{
16
    /**
17
     * @var \Symfony\Component\Filesystem\Filesystem
18
     */
19
    private $fs;
20
21
    public function __construct()
22
    {
23
        $this->fs = new Filesystem();
24
    }
25
26
    /**
27
     * Sync $origin directory with $target one.
28
     *
29
     * @param string   $src
30
     * @param string   $dst
31
     * @param Callable $callback
32
     *
33
     * @throws ClientException
34
     *
35
     * @return int|null
36
     */
37
    public function sync($src, $dst, $callback = null)
38
    {
39
        $cleanupEvent  = new Event(sprintf('Cleaning up destination (`%s`).', $dst));
40
        $copyEvent     = new Event(sprintf('Copying source `%s` to destination `%s`.', $src, $dst));
41
        $finishedEvent = new Event(sprintf('Finished copying.'));
42
43
        call_user_func($callback, $cleanupEvent);
44
        $this->fs->remove($dst);
45
46
        call_user_func($callback, $copyEvent);
47
        $this->fs->mirror($src, $dst);
48
        call_user_func($callback, $finishedEvent);
49
    }
50
}
51