Completed
Branch 2.x (b1c655)
by Julián
07:53
created

HandlerTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setConfiguration() 0 6 1
A testConfiguration() 0 6 2
1
<?php
2
3
/*
4
 * sessionware (https://github.com/juliangut/sessionware).
5
 * PSR7 session management middleware.
6
 *
7
 * @license BSD-3-Clause
8
 * @link https://github.com/juliangut/sessionware
9
 * @author Julián Gutiérrez <[email protected]>
10
 */
11
12
namespace Jgut\Middleware\Sessionware\Handler;
13
14
use Jgut\Middleware\Sessionware\Configuration;
15
16
/**
17
 * Session handler utility trait.
18
 */
19
trait HandlerTrait
20
{
21
    /**
22
     * @var Configuration
23
     */
24
    protected $configuration;
25
26
    /**
27
     * Set configuration.
28
     *
29
     * @param Configuration $configuration
30
     *
31
     * @return static
32
     */
33
    public function setConfiguration(Configuration $configuration)
34
    {
35
        $this->configuration = $configuration;
36
37
        return $this;
38
    }
39
40
    /**
41
     * Checks if configuration is set.
42
     *
43
     * @throws \RuntimeException
44
     */
45
    protected function testConfiguration()
46
    {
47
        if ($this->configuration === null) {
48
            throw new \RuntimeException('Configuration must be set prior to use');
49
        }
50
    }
51
}
52