Zip::getCompressCommand()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 4
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 * This file is part of graze/data-file
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-file/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/data-file
12
 */
13
14
namespace Graze\DataFile\Modify\Compress;
15
16
use Graze\DataFile\Helper\Builder\BuilderAwareInterface;
17
use Graze\DataFile\Helper\GetOptionTrait;
18
use Graze\DataFile\Helper\OptionalLoggerTrait;
19
use Graze\DataFile\Modify\FileProcessTrait;
20
use Graze\DataFile\Node\LocalFileNodeInterface;
21
use Psr\Log\LoggerAwareInterface;
22
23 View Code Duplication
class Zip implements
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...
24
    CompressionTypeInterface,
25
    CompressorInterface,
26
    DeCompressorInterface,
27
    LoggerAwareInterface,
28
    BuilderAwareInterface
29
{
30
    use GetOptionTrait;
31
    use FileProcessTrait;
32
    use OptionalLoggerTrait;
33
    use CompressorTrait;
34
    use DeCompressorTrait;
35
36
    const NAME = 'zip';
37
38
    /**
39
     * Get the extension used by this compressor
40
     *
41
     * @return string
42
     */
43 6
    public function getExtension()
44
    {
45 6
        return 'zip';
46
    }
47
48
    /**
49
     * @return string
50
     */
51 18
    public function getName()
52
    {
53 18
        return static::NAME;
54
    }
55
56
    /**
57
     * Get the command line to compress a file
58
     *
59
     * @param LocalFileNodeInterface $from
60
     * @param LocalFileNodeInterface $to
61
     *
62
     * @return string
63
     */
64 6
    public function getCompressCommand(LocalFileNodeInterface $from, LocalFileNodeInterface $to)
65
    {
66 6
        return sprintf("zip %s %s", escapeshellarg($to->getPath()), escapeshellarg($from->getPath()));
67
    }
68
69
    /**
70
     * Get the command line to decompress a file
71
     *
72
     * @param LocalFileNodeInterface $from
73
     * @param LocalFileNodeInterface $to
74
     *
75
     * @return string
76
     *
77
     */
78 4
    public function getDecompressCommand(LocalFileNodeInterface $from, LocalFileNodeInterface $to)
79
    {
80 4
        return sprintf("unzip -p %s > %s", escapeshellarg($from->getPath()), escapeshellarg($to->getPath()));
81
    }
82
}
83