Completed
Push — master ( a3f9bd...7a5180 )
by C
05:22
created

SevenzCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
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 19
	protected function configure ()
11
	{
12 19
		parent::configure();
13
14 19
		$this->setName('7z');
15 19
	}
16
17 9
	protected function isSuccessfullFinished ($output)
18
	{
19 9
		return strpos($output, 'Everything is Ok') !== false;
20
	}
21
22 9
	protected function getExtractCommand ($password, AbstractAdapter $source, AbstractAdapter $destination)
23
	{
24
		/*
25
		 * The 7z command:
26
		 * x: extract command with folder structure
27
		 * -p: The password
28
		 */
29 9
		return '7z x -y -p' . escapeshellarg($password) . ' ' . escapeshellarg($source->applyPathPrefix('*.zip')) . ' -o' .
30 9
				 $destination->getPathPrefix() . ' 2>&1';
31
	}
32
33 6
	protected function getFilesToDelete (AbstractAdapter $source)
34
	{
35 6
		$filesToDelete = [];
36 6
		foreach ($source->listContents() as $file)
37
		{
38 6
			if (! Util::endsWith($file['path'], '.7z') && ! Util::endsWith($file['path'], '.zip'))
39
			{
40 3
				continue;
41
			}
42
43 6
			$filesToDelete[] = $file['path'];
44
		}
45 6
		return $filesToDelete;
46
	}
47
}
48