DecrypterFactory::createDecryptor()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 18
ccs 9
cts 9
cp 1
rs 9.4285
cc 3
eloc 9
nc 3
nop 1
crap 3
1
<?php
2
namespace Tartana\Component\Decrypter;
3
4
use Tartana\Mixins\LoggerAwareTrait;
5
6
class DecrypterFactory
7
{
8
	use LoggerAwareTrait;
9
10
	/**
11
	 *
12
	 * @param string $fileName
13
	 * @return \Tartana\Component\Decrypter\DecrypterInterface
14
	 */
15 5
	public function createDecryptor($fileName)
16
	{
17 5
		$className = 'Tartana\\Component\\Decrypter\\' . ucfirst(strtolower(pathinfo($fileName, PATHINFO_EXTENSION)));
18
19
		// Check if the class exists for the host to download
20 5
		if (!class_exists($className)) {
21 2
			return null;
22
		}
23
24 3
		$decrypter = new $className();
25 3
		if (!$decrypter instanceof DecrypterInterface) {
26 1
			return null;
27
		}
28
29 2
		$decrypter->setLogger($this->getLogger());
30
31 2
		return $decrypter;
32
	}
33
}
34