Completed
Push — master ( 3cfac2...b239b2 )
by Filipe
02:54
created

SessionAwareMethods   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 34
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSessionDriver() 0 7 2
A setSessionDriver() 0 5 1
1
<?php
2
3
/**
4
 * This file is part of slick/mvc package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Mvc\Http;
11
12
use Slick\Http\SessionDriverInterface;
13
use Slick\Mvc\Application;
14
15
/**
16
 * Session Aware Interface methods implementation
17
 * 
18
 * @package Slick\Mvc\Http
19
 * @author  Filipe Silva <[email protected]>
20
 */
21
trait SessionAwareMethods
22
{
23
24
    /**
25
     * @var SessionDriverInterface
26
     */
27
    protected $sessionDriver;
28
29
    /**
30
     * Gets Session driver
31
     *
32
     * @return SessionDriverInterface
33
     */
34 6
    public function getSessionDriver()
35
    {
36 6
        if (null == $this->sessionDriver) {
37 2
            $this->setSessionDriver(Application::container()->get('session'));
38 1
        }
39 6
        return $this->sessionDriver;
40
    }
41
42
    /**
43
     * Sets session driver
44
     *
45
     * @param SessionDriverInterface $driver
46
     *
47
     * @return self|$this
0 ignored issues
show
Comprehensibility Bug introduced by
The return type SessionAwareMethods is a trait, and thus cannot be used for type-hinting in PHP. Maybe consider adding an interface and use that for type-hinting?

In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.

If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.

Loading history...
48
     */
49 6
    public function setSessionDriver(SessionDriverInterface $driver)
50
    {
51 6
        $this->sessionDriver = $driver;
52 6
        return $this;
53
    }
54
}