Syncer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 47
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 3
A sync() 0 10 1
1
<?php
2
3
namespace SyncFS;
4
5
use Symfony\Component\Console\Output\OutputInterface;
6
use SyncFS\Client\Factory;
7
use SyncFS\Client\ClientInterface;
8
use SyncFS\Map\FileSystemMapFactory;
9
use SyncFS\Map\MapBag;
10
use SyncFS\Syncer\FolderSyncer;
11
12
/**
13
 * Class Syncer
14
 *
15
 * @package SyncFS
16
 * @author  Matej Velikonja <[email protected]>
17
 */
18
class Syncer
19
{
20
    /**
21
     * @var MapBag
22
     */
23
    private $map;
24
25
    /**
26
     * @var ClientInterface
27
     */
28
    private $defaultClient;
29
30
    /**
31
     * @param array   $config
32
     * @param Factory $clientFactory
33
     */
34 2
    public function __construct(array $config, Factory $clientFactory = null)
35
    {
36 2
        if (! $clientFactory) {
37 2
            $clientFactory = new Factory();
38 2
        }
39
40 2
        $clientConfig = array();
41
42 2
        if (isset($config['timeout'])) {
43 2
            $clientConfig ['timeout'] = $config['timeout'];
44 2
        }
45
46 2
        $mapFactory          = new FileSystemMapFactory();
47 2
        $this->map           = $mapFactory->create($config['maps']);
48 2
        $this->defaultClient = $clientFactory->create($config['default_client'], $clientConfig);
49 2
    }
50
51
    /**
52
     * @param OutputInterface $output
53
     */
54 2
    public function sync(OutputInterface $output)
55
    {
56 2
        $folderSyncer = new FolderSyncer($this->defaultClient);
57 2
        $folderSyncer->sync(
58 2
            $this->map,
59 2
            function (EventInterface $event) use ($output) {
60 2
                $output->write($event->getBuffer());
61 2
            }
62 2
        );
63 2
    }
64
}
65