CompressedFormat   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 50
ccs 15
cts 20
cp 0.75
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 4
A getSubFormat() 0 4 1
A getInsideStream() 0 12 2
A __toString() 0 4 1
1
<?php
2
3
namespace Mathielen\ImportEngine\Storage\Format;
4
5
class CompressedFormat extends Format
6
{
7
    /**
8
     * @var Format
9
     */
10
    private $subFormat;
11
12
    private $uriInsideArchive;
13
    private $wrapper;
14
15
    protected $name = 'Compressed File';
16
    protected $id = 'compress';
17
18 3
    public function __construct($uriInsideArchive = null, $wrapper = 'zip', Format $subFormat = null)
19
    {
20 3
        if (!is_string($wrapper)) {
21
            throw new \InvalidArgumentException('wrapper argument must be a string');
22
        }
23 3
        if (!is_null($uriInsideArchive) && !is_string($uriInsideArchive)) {
24
            throw new \InvalidArgumentException('uriInsideArchive argument must be a string');
25
        }
26
27 3
        $this->uriInsideArchive = $uriInsideArchive;
28 3
        $this->wrapper = $wrapper;
29 3
        $this->subFormat = $subFormat;
30 3
    }
31
32 1
    public function getSubFormat()
33
    {
34 1
        return $this->subFormat;
35
    }
36
37 1
    public function getInsideStream(\SplFileInfo $file)
38
    {
39 1
        if (is_null($this->uriInsideArchive)) {
40
            throw new \LogicException('This compressed archive has multiple files in it. Cannot create a single stream.');
41
        }
42
43 1
        $streamUri = $this->wrapper.'://'.$file.'#'.$this->uriInsideArchive;
44 1
        $uncompressedUri = tempnam('/tmp', 'compressed');
45 1
        file_put_contents($uncompressedUri, file_get_contents($streamUri));
46
47 1
        return new \SplFileInfo($uncompressedUri);
48
    }
49
50
    public function __toString()
51
    {
52
        return $this->name.' with sub-format: '.$this->subFormat;
53
    }
54
}
55