GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

AuthRequestAwareTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 74
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setAuthAttribute() 0 4 1
A getAuth() 0 10 2
A getAuthStatus() 0 4 1
A isAuthValid() 0 4 1
1
<?php
2
/**
3
 * Authentication Handler
4
 *
5
 * PHP version 7
6
 *
7
 * Copyright (C) 2019 Jake Johns
8
 *
9
 * This software may be modified and distributed under the terms
10
 * of the MIT license.  See the LICENSE file for details.
11
 *
12
 * @category  Trait
13
 * @package   Vperyod\AuthHandler
14
 * @author    Jake Johns <[email protected]>
15
 * @copyright 2019 Jake Johns
16
 * @license   http://jnj.mit-license.org/2019 MIT License
17
 * @link      https://github.com/vperyod/vperyod.auth-handler
18
 */
19
20
namespace Vperyod\AuthHandler;
21
22
use Psr\Http\Message\ResponseInterface as Response;
23
use Psr\Http\Message\ServerRequestInterface as Request;
24
25
use Aura\Auth\Auth;
26
27
/**
28
 * Auth Request aware trait
29
 *
30
 * Trait for objects which need to know where the auth attribute is stored in
31
 * the request.
32
 *
33
 * @category Trait
34
 * @package  Vperyod\AuthHandler
35
 * @author   Jake Johns <[email protected]>
36
 * @license  http://jnj.mit-license.org/2019 MIT License
37
 * @link     https://github.com/vperyod/vperyod.auth-handler
38
 */
39
trait AuthRequestAwareTrait
40
{
41
    /**
42
     * Attribute on request where auth is stored
43
     *
44
     * @var string
45
     *
46
     * @access protected
47
     */
48
    protected $authAttribute = Auth::class;
49
50
    /**
51
     * Set auth attribute
52
     *
53
     * @param string $attr attribute on request where auth is stored
54
     *
55
     * @return void
56
     *
57
     * @access public
58
     */
59 2
    public function setAuthAttribute($attr)
60
    {
61 2
        $this->authAttribute = $attr;
62 2
    }
63
64
    /**
65
     * Get auth from request
66
     *
67
     * @param Request $request PSR7 Request
68
     *
69
     * @return Auth
70
     * @throws \InvalidArgumentException if auth attribute is not an `Auth`
71
     *
72
     * @access protected
73
     */
74
    protected function getAuth(Request $request) : Auth
75 2
    {
76
        $auth = $request->getAttribute($this->authAttribute);
77 2
        if (! $auth instanceof Auth) {
78 2
            throw new \InvalidArgumentException(
79 1
                'Auth attribute not available in request'
80
            );
81 1
        }
82
        return $auth;
83 1
    }
84
85
    /**
86
     * Get auth status from request
87
     *
88
     * @param Request $request PSR7 Request
89
     *
90
     * @return string
91
     *
92
     * @access protected
93
     */
94
    protected function getAuthStatus(Request $request) : string
95 1
    {
96
        return $this->getAuth($request)->getStatus();
97 1
    }
98
99
    /**
100
     * Is auth status valid?
101
     *
102
     * @param Request $request PSR7 Request
103
     *
104
     * @return bool
105
     *
106
     * @access protected
107
     */
108
    protected function isAuthValid(Request $request) : bool
109 1
    {
110
        return $this->getAuth($request)->isValid();
111 1
    }
112
}
113