Completed
Push — master ( 9c742a...1858b1 )
by Fèvre
14s
created

src/Model/Table/SessionsTable.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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');
20
        $this->displayField('id');
21
        $this->primaryKey('id');
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