Passed
Pull Request — 2.2 (#20357)
by Wilmer
12:59 queued 04:29
created

SessionHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * @link https://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license https://www.yiiframework.com/license/
6
 */
7
8
namespace yii\web;
9
10
use SessionHandlerInterface;
11
12
/**
13
 * SessionHandler implements an [[\SessionHandlerInterface]] for handling [[Session]] with custom session storage.
14
 *
15
 * @author Viktor Khokhryakov <[email protected]>
16
 * @since 2.0.52
17
 */
18
class SessionHandler implements SessionHandlerInterface
19
{
20
    /**
21
     * @var Session
22
     */
23
    private $_session;
24
25 2
    public function __construct(Session $session)
26
    {
27 2
        $this->_session = $session;
28
    }
29
30
    /**
31
     * @inheritDoc
32
     */
33 2
    public function close(): bool
34
    {
35 2
        return $this->_session->closeSession();
36
    }
37
38
    /**
39
     * @inheritDoc
40
     */
41
    public function destroy($id): bool
42
    {
43
        return $this->_session->destroySession($id);
44
    }
45
46
    /**
47
     * @inheritDoc
48
     */
49
    #[\ReturnTypeWillChange]
50
    public function gc($max_lifetime)
51
    {
52
        return $this->_session->gcSession($max_lifetime);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->_session->gcSession($max_lifetime) returns the type integer which is incompatible with the return type mandated by SessionHandlerInterface::gc() of boolean.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
53
    }
54
55
    /**
56
     * @inheritDoc
57
     */
58 3
    public function open($path, $name): bool
59
    {
60 3
        return $this->_session->openSession($path, $name);
61
    }
62
63
    /**
64
     * @inheritDoc
65
     */
66 3
    #[\ReturnTypeWillChange]
67
    public function read($id)
68
    {
69 3
        return $this->_session->readSession($id);
70
    }
71
72
    /**
73
     * @inheritDoc
74
     */
75 2
    public function write($id, $data): bool
76
    {
77 2
        return $this->_session->writeSession($id, $data);
78
    }
79
}
80