DeCompress   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 38
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A flow() 0 11 2
1
<?php
2
/**
3
 * This file is part of graze/data-flow
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/data-flow/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/data-flow
12
 */
13
14
namespace Graze\DataFlow\Flow\File\Compression;
15
16
use Graze\DataFile\Helper\OptionalLoggerTrait;
17
use Graze\DataFile\Modify\Compress\CompressionFactory;
18
use Graze\DataFile\Modify\Exception\InvalidCompressionTypeException;
19
use Graze\DataFile\Node\LocalFile;
20
use Graze\DataFlow\Flow\InvokeTrait;
21
use Graze\DataFlow\FlowInterface;
22
use Graze\DataNode\NodeInterface;
23
use InvalidArgumentException;
24
use Psr\Log\LoggerAwareInterface;
25
use Psr\Log\LogLevel;
26
27
class DeCompress implements FlowInterface, LoggerAwareInterface
28
{
29
    use InvokeTrait;
30
    use OptionalLoggerTrait;
31
32
    /**
33
     * @var array
34
     */
35
    private $options;
36
37
    /**
38
     * Compress constructor.
39
     *
40
     * @param array $options
41
     */
42 4
    public function __construct(array $options = [])
43
    {
44 4
        $this->options = $options;
45 4
    }
46
47
    /**
48
     * @param NodeInterface $node
49
     *
50
     * @return LocalFile
51
     * @throws InvalidCompressionTypeException
52
     */
53 4
    public function flow(NodeInterface $node)
54
    {
55 4
        if (!($node instanceof LocalFile)) {
56 1
            throw new InvalidArgumentException("Node: $node should be an instance of LocalFile");
57
        }
58
59 3
        $factory = new CompressionFactory();
60 3
        $compressor = $factory->getDeCompressor($node->getCompression());
61 3
        $this->log(LogLevel::INFO, "DeCompressing file: '{file}'", ['file' => $node]);
62 3
        return $compressor->decompress($node, $this->options);
63
    }
64
}
65