Completed
Push — master ( 48abf8...8f7739 )
by C
13:50
created

BaseDecrypter::decrypt()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 26
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 26
ccs 12
cts 12
cp 1
rs 8.8571
cc 3
eloc 13
nc 4
nop 1
crap 3
1
<?php
2
namespace Tartana\Component\Decrypter;
3
use League\Flysystem\Adapter\Local;
4
use Monolog\Logger;
5
use Tartana\Mixins\LoggerAwareTrait;
6
7
abstract class BaseDecrypter implements DecrypterInterface
8
{
9
10
	use LoggerAwareTrait;
11
12 16
	public function decrypt ($dlc)
13
	{
14 16
		$this->log('Started file decrypting', Logger::INFO);
15
16 16
		if (@file_exists(realpath($dlc)))
17
		{
18 7
			$dlc = realpath($dlc);
19 7
			$fs = new Local(dirname($dlc));
20 7
			$content = $fs->read($fs->removePathPrefix($dlc))['contents'];
21
		}
22
		else
23
		{
24 9
			$content = $dlc;
25
		}
26
27 16
		if (! $content)
28
		{
29 3
			throw new \RuntimeException('Empty content.');
30
		}
31
32 13
		$links = $this->getLinks($content);
33
34 7
		$this->log('Finished file decrypting', Logger::INFO);
35
36 7
		return $links;
37
	}
38
39
	abstract protected function getLinks ($content);
40
}