SessionSerializerFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 28
ccs 6
cts 7
cp 0.8571
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 10 2
A toClassCase() 0 4 1
1
<?php
2
/**
3
 * SessionSerializerFactory.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        http://www.ipublikuj.eu
7
 * @author         Adam Kadlec http://www.ipublikuj.eu
8
 * @package        iPublikuj:WebSocketSession!
9
 * @subpackage     Session
10
 * @since          1.0.0
11
 *
12
 * @date           24.02.17
13
 */
14
15
declare(strict_types = 1);
16
17
namespace IPub\WebSocketsSession\Serializers;
18
19
use IPub;
20
use IPub\WebSocketsSession\Exceptions;
21
22
/**
23
 * Session component provider factory
24
 *
25
 * @package        iPublikuj:WebSocketSession!
26
 * @subpackage     Session
27
 *
28
 * @author         Adam Kadlec <[email protected]>
29
 */
30 1
class SessionSerializerFactory
31
{
32
	/**
33
	 * @return ISessionSerializer
34
	 *
35
	 * @throws Exceptions\RuntimeException
36
	 */
37
	public static function create() : ISessionSerializer
38
	{
39 1
		$serialClass = '\\IPub\\WebSocketsSession\\Serializers\\Session' . self::toClassCase(ini_get('session.serialize_handler')) . 'Serializer'; // awesome/terrible hack, eh?
40
41 1
		if (!class_exists($serialClass)) {
42
			throw new Exceptions\RuntimeException('Unable to parse session serialize handler');
43
		}
44
45 1
		return new $serialClass;
46
	}
47
48
	/**
49
	 * @param string $langDef Input to convert
50
	 *
51
	 * @return string
52
	 */
53
	private static function toClassCase(string $langDef) : string
54
	{
55 1
		return str_replace(' ', '', ucwords(str_replace('_', ' ', $langDef)));
56
	}
57
}
58