Completed
Pull Request — master (#361)
by
unknown
03:09
created

DBTerminateSessionsService::run()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 0
cts 11
cp 0
rs 9.8333
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/yii2-usuario project.
5
 *
6
 * (c) 2amigOS! <http://2amigos.us/>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Da\User\Service\SessionHistory;
13
14
15
use yii\web\DbSession;
16
17
class DBTerminateSessionsService implements TerminateSessionsServiceInterface
18
{
19
    protected $sessionIds;
20
    protected $dbSession;
21
    protected $fieldName;
22
23
    public function __construct(array $sessionIds, DbSession $dbSession, $fieldName = 'id')
24
    {
25
        $this->sessionIds = $sessionIds;
26
        $this->dbSession = $dbSession;
27
        $this->fieldName = $fieldName;
28
    }
29
30
    public function run()
31
    {
32
        if (in_array(session_id(), $this->sessionIds)) {
33
            session_write_close();
34
        }
35
36
        $this->dbSession->db->createCommand()->delete(
37
            $this->dbSession->sessionTable,
38
            [$this->fieldName => $this->sessionIds]
39
        )->execute();
40
41
        return true;
42
    }
43
}