Completed
Push — master ( 420f16...68b944 )
by Alexander
03:24
created

SessionStrategyFactory::createStrategy()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
cc 3
eloc 6
nc 3
nop 1
crap 3
1
<?php
2
/**
3
 * This file is part of the phpunit-mink library.
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 *
7
 * @copyright Alexander Obuhovich <[email protected]>
8
 * @link      https://github.com/aik099/phpunit-mink
9
 */
10
11
namespace aik099\PHPUnit\Session;
12
13
14
use aik099\PHPUnit\IApplicationAware;
15
use aik099\PHPUnit\Application;
16
17
/**
18
 * Produces sessions.
19
 *
20
 * @method \Mockery\Expectation shouldReceive(string $name)
21
 */
22
class SessionStrategyFactory implements ISessionStrategyFactory, IApplicationAware
23
{
24
25
	/**
26
	 * Application.
27
	 *
28
	 * @var Application
29
	 */
30
	protected $application;
31
32
	/**
33
	 * Sets application.
34
	 *
35
	 * @param Application $application The application.
36
	 *
37
	 * @return void
38
	 */
39 9
	public function setApplication(Application $application)
40
	{
41 9
		$this->application = $application;
42 9
	}
43
44
	/**
45
	 * Creates specified session strategy.
46
	 *
47
	 * @param string $strategy_type Session strategy type.
48
	 *
49
	 * @return ISessionStrategy
50
	 * @throws \InvalidArgumentException When session strategy type is invalid.
51
	 */
52 6
	public function createStrategy($strategy_type)
53
	{
54 6
		if ( $strategy_type == ISessionStrategyFactory::TYPE_ISOLATED ) {
55 4
			return $this->application->getObject('isolated_session_strategy');
56
		}
57 2
		elseif ( $strategy_type == ISessionStrategyFactory::TYPE_SHARED ) {
58 1
			return $this->application->getObject('shared_session_strategy');
59
		}
60
61 1
		throw new \InvalidArgumentException('Incorrect session strategy type');
62
	}
63
64
}
65