Test Setup Failed
Push — master ( d9222f...877bfe )
by Php Easy Api
04:20
created

AuthenticateResponse::getLogoutResult()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Resta\Authenticate;
4
5
trait AuthenticateResponse
6
{
7
    /**
8
     * @var array $params
9
     */
10
    public $params = [];
11
12
    /**
13
     * @return bool
14
     */
15
    private function checkStatus()
16
    {
17
        return isset($this->params['status']) && $this->params['status'];
18
    }
19
20
    /**
21
     * @return void|mixed
22
     */
23
    protected function getCheckResult()
24
    {
25
        // if the status value is true,
26
        // we send output generated from the token value.
27
        if($this->checkStatus()){
28
            $this->setAuthenticateSuccess(true);
29
            return true;
30
        }
31
32
        //return false
33
        return false;
34
    }
35
36
    /**
37
     * @return void|mixed
38
     */
39
    protected function getLogoutResult()
40
    {
41
        // if the status value is true,
42
        // we send output generated from the token value.
43
        if($this->checkStatus()){
44
            return true;
45
        }
46
47
        //logout exception
48
        $this->{$this->params['exception']}();
49
    }
50
51
    /**
52
     * @return array
53
     */
54
    protected function getResult()
55
    {
56
        $result= [];
57
58
        // if the status value is true,
59
        // we send output generated from the token value.
60
        if($this->checkStatus()){
61
            $result['message']                  = 'token success';
62
            $result['token']                    = $this->params['token'];
63
64
            //we send the result value.
65
            return $result;
66
        }
67
68
        //in the params property, we set the exception type according to the exception value.
69
        $exceptionType = (isset($this->params['exception'])) ? $this->params['exception'] : 'credentials';
70
71
        // if the status is unsuccessful,
72
        // the direct exception will be thrown away.
73
        $this->exceptionManager($exceptionType);
0 ignored issues
show
Bug introduced by
It seems like exceptionManager() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

73
        $this->/** @scrutinizer ignore-call */ exceptionManager($exceptionType);
Loading history...
74
    }
75
76
    /**
77
     * set authenticate loaded container value
78
     *
79
     * @param bool $value
80
     */
81
    private function setAuthenticateSuccess($value=true)
82
    {
83
        if(app()->has('authenticateSuccess')){
84
            app()->terminate('authenticateSuccess');
85
        }
86
87
        app()->register('authenticateSuccess',$value);
88
    }
89
90
91
}