SessionsTable::findExpires()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
namespace App\Model\Table;
3
4
use Cake\Core\Configure;
5
use Cake\ORM\Query;
6
use Cake\ORM\Table;
7
8
class SessionsTable extends Table
9
{
10
11
    /**
12
     * Initialize method.
13
     *
14
     * @param array $config The configuration for the Table.
15
     * @return void
16
     */
17 View Code Duplication
    public function initialize(array $config)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
    {
19
        $this->table('sessions');
0 ignored issues
show
Deprecated Code introduced by
The method Cake\ORM\Table::table() has been deprecated with message: 3.4.0 Use setTable()/getTable() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
20
        $this->displayField('id');
0 ignored issues
show
Deprecated Code introduced by
The method Cake\ORM\Table::displayField() has been deprecated with message: 3.4.0 Use setDisplayField()/getDisplayField() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
21
        $this->primaryKey('id');
0 ignored issues
show
Deprecated Code introduced by
The method Cake\ORM\Table::primaryKey() has been deprecated with message: 3.4.0 Use setPrimaryKey()/getPrimaryKey() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
22
23
        $this->addBehavior('Timestamp');
24
25
        $this->belongsTo('Users', [
26
            'foreignKey' => 'user_id'
27
        ]);
28
    }
29
30
    /**
31
     * Custom finder for select sessions no-expired.
32
     *
33
     * @param \Cake\ORM\Query $query The query finder.
34
     *
35
     * @return \Cake\ORM\Query
36
     */
37
    public function findExpires(Query $query)
38
    {
39
        $timeout = Configure::read('Session.handler.timeoutOnline') ? Configure::read('Session.handler.timeoutOnline') : 5;
40
        $expire = time() + ini_get('session.gc_maxlifetime') - (60 * $timeout);
41
42
        return $query->where(['Sessions.expires >=' => $expire]);
43
    }
44
}
45