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

SevenzCommand   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 6 1
A isSuccessfullFinished() 0 4 1
A getExtractCommand() 0 10 1
A getFilesToDelete() 0 14 4
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