Flow   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
c 1
b 0
f 0
dl 0
loc 47
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 7 2
A __construct() 0 3 1
A set() 0 4 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2014-2018
6
 * @package MW
7
 * @subpackage Session
8
 */
9
10
11
namespace Aimeos\MW\Session;
12
13
14
/**
15
 * Implementation using Flow sessions.
16
 *
17
 * @package MW
18
 * @subpackage Session
19
 */
20
class Flow extends Base implements \Aimeos\MW\Session\Iface
21
{
22
	private $object;
23
24
25
	/**
26
	 * Initializes the object.
27
	 *
28
	 * @param \Neos\Flow\Session\SessionInterface $object Flow session object
29
	 */
30
	public function __construct( \Neos\Flow\Session\SessionInterface $object )
31
	{
32
		$this->object = $object;
33
	}
34
35
36
	/**
37
	 * Returns the value of the requested session key.
38
	 *
39
	 * If the returned value wasn't a string, it's decoded from its string representation.
40
	 *
41
	 * @param string $name Key of the requested value in the session
42
	 * @param mixed $default Value returned if requested key isn't found
43
	 * @return mixed Value associated to the requested key
44
	 */
45
	public function get( string $name, $default = null )
46
	{
47
		if( $this->object->hasKey( $name ) !== true ) {
48
			return $default;
49
		}
50
51
		return $this->object->getData( $name );
52
	}
53
54
55
	/**
56
	 * Sets the value for the specified key.
57
	 *
58
	 * If the value isn't a string, it's serialized and decoded again when using the get() method.
59
	 *
60
	 * @param string $name Key to the value which should be stored in the session
61
	 * @param mixed $value Value that should be associated with the given key
62
	 */
63
	public function set( string $name, $value ) : Iface
64
	{
65
		$this->object->putData( $name, $value );
66
		return $this;
67
	}
68
}
69