Syncer::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 12
cts 12
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 4
nop 2
crap 3
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