Completed
Push — master ( ed16a6...c74abe )
by C
05:08
created

SevenzCommand::getFileExtension()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
namespace Tartana\Console\Command\Extract;
3
use League\Flysystem\Adapter\AbstractAdapter;
4
use Tartana\Component\Command\Command;
5
use Tartana\Util;
6
7
class SevenzCommand extends ExtractCommand
8
{
9
10 22
	protected function configure ()
11
	{
12 22
		parent::configure();
13
14 22
		$this->setName('7z');
15 22
	}
16
17 19
	protected function isSuccessfullFinished ($output)
18
	{
19 19
		return strpos($output, 'Everything is Ok') !== false;
20
	}
21
22 19
	protected function getExtractCommand ($password, AbstractAdapter $source, AbstractAdapter $destination)
23
	{
24 19
		$command = new Command('7z');
25
		// Extract
26 19
		$command->addArgument('x', false);
27
		// Set all to yes
28 19
		$command->addArgument('-y', false);
29
		// Password
30 19
		$command->addArgument('-p' . $password);
31
		// Input files
32 19
		$command->addArgument($source->applyPathPrefix('*.' . $this->getFileExtension() . '*'));
33
		// Output
34 19
		$command->addArgument('-o' . $destination->getPathPrefix());
35
36 19
		return $command;
37
	}
38
39 8
	protected function getFilesToDelete (AbstractAdapter $source)
40
	{
41 8
		$filesToDelete = [];
42 8
		foreach ($source->listContents() as $file)
43
		{
44
			// Multipart archives do have the naming pattern test.7z.001
45 8
			if (! Util::endsWith($file['path'], '.' . $this->getFileExtension()) && strpos($file['path'], '.7z.') === false)
46
			{
47 4
				continue;
48
			}
49
50 8
			$filesToDelete[] = $file['path'];
51
		}
52 8
		return $filesToDelete;
53
	}
54
55
	/**
56
	 * Returns the file extension this command is processing.
57
	 * Subclasses can override as the 7z command can handle multiple file
58
	 * formats, eg. zip files.
59
	 *
60
	 * @return string
61
	 */
62 10
	protected function getFileExtension ()
63
	{
64 10
		return '7z';
65
	}
66
}
67