Completed
Branch full-rewrite (4754d3)
by Thibaud
03:13
created

TarResourceIterator::current()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 11
loc 11
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace Alchemy\Zippy\Adapter\Pear\Tar;
4
5
use Alchemy\Zippy\MappingArrayIterator;
6
use Alchemy\Zippy\Package\Iterator\AbstractIterator;
7
use Alchemy\Zippy\Package\PackagedResource;
8
use Alchemy\Zippy\Resource\Reader\StringReader;
9
use Alchemy\Zippy\Resource\ResourceReader;
10
use Alchemy\Zippy\Resource\ResourceReaderResolver;
11
use Alchemy\Zippy\Resource\ResourceUri;
12
13 View Code Duplication
class TarResourceIterator extends AbstractIterator implements ResourceReaderResolver
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
14
{
15
    /**
16
     * @var \Archive_Tar
17
     */
18
    private $archive;
19
20
    /**
21
     * @var PackagedResource
22
     */
23
    private $container;
24
25
    /**
26
     * @param PackagedResource $container
27
     */
28
    public function __construct(PackagedResource $container)
29
    {
30
        $this->container = $container;
31
        $this->archive = new \Archive_Tar($container->getRelativeUri()->getResource());
32
    }
33
34
    /**
35
     * @return PackagedResource
36
     */
37
    public function current()
38
    {
39
        $resource = $this->getIterator()->current();
40
41
        return new PackagedResource(
42
            $resource,
43
            $this,
44
            $this->container->getWriterResolver(),
45
            $this->container
46
        );
47
    }
48
49
    /**
50
     * @return \ArrayIterator
51
     */
52
    protected function buildIterator()
53
    {
54
        return new MappingArrayIterator($this->archive->listContent(), function ($current) {
55
            return ResourceUri::fromString($current['filename']);
56
        });
57
    }
58
59
    /**
60
     * Resolves a reader for the given resource URI.
61
     *
62
     * @param ResourceUri $resource
63
     * @return ResourceReader
64
     */
65
    public function resolveReader(ResourceUri $resource)
66
    {
67
        return new StringReader($this->archive->extractInString($resource->getResource()));
68
    }
69
}
70