GetUserAndRefresh::handle()   B
last analyzed

Complexity

Conditions 6
Paths 8

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 6.0359

Importance

Changes 4
Bugs 2 Features 0
Metric Value
c 4
b 2
f 0
dl 0
loc 18
ccs 9
cts 10
cp 0.9
rs 8.8571
cc 6
eloc 9
nc 8
nop 3
crap 6.0359
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Claudio Cardinale <[email protected]>
5
 * Date: 24/12/15
6
 * Time: 22.53
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
 */
19
20
namespace plunner\Http\Middleware;
21
22
23
use Tymon\JWTAuth\Exceptions\JWTException;
24
25
class GetUserAndRefresh extends \Tymon\JWTAuth\Middleware\GetUserAndRefresh
26
{
27 285
    public function handle($request, \Closure $next, $custom = '')
28
    {
29 285
        $remember = false;
30
        try {
31 285
            if ($this->auth->setRequest($request)->getToken() && ($remember = $this->auth->getPayload()->get('remember')) &&
32 95
                $remember == 'true'
33 190
            ) {
34 95
                \JWTFactory::setTTL(43200);
35
                //config(['jwt.ttl' =>'43200']); //30 days
36
            }
37 190
        }catch(JWTException $e)
38
        {}
39
40
        //this to add the remember me mode field in the new token, but we have the custom check that is an useless
41
        //overhead
42 285
        $custom = $custom . ';remember-' . $remember == 'true' ? 'true' : 'false';
43 285
        return parent::handle($request, $next, $custom);
44
    }
45
46
47
}