GenericTeleporter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 49
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A teleport() 0 7 1
1
<?php
2
3
namespace Alchemy\Zippy\Resource\Teleporter;
4
5
use Alchemy\Zippy\Exception\InvalidArgumentException;
6
use Alchemy\Zippy\Exception\IOException;
7
use Alchemy\Zippy\Resource\Resource as ZippyResource;
8
use Alchemy\Zippy\Resource\ResourceLocator;
9
use Alchemy\Zippy\Resource\ResourceReaderFactory;
10
use Alchemy\Zippy\Resource\ResourceWriter;
11
12
class GenericTeleporter implements TeleporterInterface
13
{
14
    /**
15
     * @var ResourceReaderFactory
16
     */
17
    private $readerFactory;
18
19
    /**
20
     * @var ResourceWriter
21
     */
22
    private $resourceWriter;
23
24
    /**
25
     * @var ResourceLocator
26
     */
27
    private $resourceLocator;
28
29
    /**
30
     * @param ResourceReaderFactory $readerFactory
31
     * @param ResourceWriter        $resourceWriter
32
     * @param ResourceLocator       $resourceLocator
33
     */
34
    public function __construct(
35
        ResourceReaderFactory $readerFactory,
36
        ResourceWriter $resourceWriter,
37
        ResourceLocator $resourceLocator = null
38
    ) {
39
        $this->readerFactory = $readerFactory;
40
        $this->resourceWriter = $resourceWriter;
41
        $this->resourceLocator = $resourceLocator ?: new ResourceLocator();
42
    }
43
44
    /**
45
     * Teleports a file from a destination to an other
46
     *
47
     * @param ZippyResource $resource A Resource
48
     * @param string        $context  The current context
49
     *
50
     * @throws IOException when file could not be written on local
51
     * @throws InvalidArgumentException when path to file is not valid
52
     */
53
    public function teleport(ZippyResource $resource, $context)
54
    {
55
        $reader = $this->readerFactory->getReader($resource, $context);
56
        $target = $this->resourceLocator->mapResourcePath($resource, $context);
57
58
        $this->resourceWriter->writeFromReader($reader, $target);
59
    }
60
}
61