Passed
Push — master ( 5621d4...3d9624 )
by mingyoung
02:21
created

HasStateParameter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 22
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A makeState() 0 4 1
A hasValidState() 0 3 2
1
<?php
2
3
/*
4
 * This file is part of the mingyoung/dingtalk.
5
 *
6
 * (c) 张铭阳 <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace EasyDingTalk\Auth;
13
14
use function EasyDingTalk\str_random;
15
use function EasyDingTalk\tap;
16
17
trait HasStateParameter
18
{
19
    /**
20
     * Generate state.
21
     *
22
     * @return string
23
     */
24
    protected function makeState()
25
    {
26
        return tap(str_random(64), function ($state) {
27
            $this->app['request']->getSession()->set('state', $state);
28
        });
29
    }
30
31
    /**
32
     * @param string|null $state
33
     *
34
     * @return bool
35
     */
36
    protected function hasValidState($state)
37
    {
38
        return !is_null($state) && ($state === $this->app['request']->getSession()->get('state'));
39
    }
40
}
41