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.
Completed
Push — master ( a3174d...5adad1 )
by François
02:55
created

OAuthModule   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 101
Duplicated Lines 59.41 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 4
dl 60
loc 101
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 15 15 1
B init() 45 70 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 *  Copyright 2015 François Kooman <[email protected]>.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace fkooman\RemoteStorage\OAuth;
20
21
use fkooman\Http\Request;
22
use fkooman\Http\Response;
23
use fkooman\IO\IO;
24
use fkooman\Rest\Plugin\Authentication\UserInfoInterface;
25
use fkooman\Rest\Service;
26
use fkooman\Rest\ServiceModuleInterface;
27
use fkooman\Tpl\TemplateManagerInterface;
28
29
class OAuthModule implements ServiceModuleInterface
30
{
31
    protected $templateManager;
32
33
    /** @var array */
34
    protected $options = [
35
        'disable_token_endpoint' => false,
36
        'disable_introspect_endpoint' => false,
37
        'route_prefix' => '',
38
    ];
39
40
    /** @var OAuthServer */
41
    protected $server;
42
43 View Code Duplication
    public function __construct(TemplateManagerInterface $templateManager, ClientStorageInterface $clientStorage, ResourceServerStorageInterface $resourceServerStorage, ApprovalStorageInterface $approvalStorage, AuthorizationCodeStorageInterface $authorizationCodeStorage, AccessTokenStorageInterface $accessTokenStorage, array $options = [], IO $io = null)
0 ignored issues
show
Duplication introduced by
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...
44
    {
45
        $this->templateManager = $templateManager;
46
        $this->options = array_merge($this->options, $options);
47
48
        $this->server = new OAuthServer(
49
            $clientStorage,
50
            $resourceServerStorage,
51
            $approvalStorage,
52
            $authorizationCodeStorage,
53
            $accessTokenStorage,
54
            $this->options,
55
            $io
56
        );
57
    }
58
59
    public function init(Service $service)
60
    {
61
        $service->get(
62
            $this->options['route_prefix'].'/authorize',
63 View Code Duplication
            function (Request $request, UserInfoInterface $userInfo) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
64
                $authorize = $this->server->getAuthorize($request, $userInfo);
65
                if ($authorize instanceof Response) {
66
                    return $authorize;
67
                }
68
                // XXX here authorize must be array type!
69
                $response = new Response();
70
                $response->setHeader('X-Frame-Options', 'DENY');
71
                $response->setHeader('Content-Security-Policy', "default-src 'self'");
72
                $response->setBody(
73
                    $this->templateManager->render(
74
                        'getAuthorize',
75
                        $authorize
76
                    )
77
                );
78
79
                return $response;
80
            },
81
            [
82
                'fkooman\Rest\Plugin\Authentication\AuthenticationPlugin' => [
83
                    'activate' => ['user'],
84
                ],
85
            ]
86
        );
87
88
        $service->post(
89
            $this->options['route_prefix'].'/authorize',
90
            function (Request $request, UserInfoInterface $userInfo) {
91
                return $this->server->postAuthorize($request, $userInfo);
92
            },
93
            [
94
                'fkooman\Rest\Plugin\Authentication\AuthenticationPlugin' => [
95
                    'activate' => ['user'],
96
                ],
97
            ]
98
        );
99
100 View Code Duplication
        if (!$this->options['disable_token_endpoint']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
101
            $service->post(
102
                $this->options['route_prefix'].'/token',
103
                function (Request $request, UserInfoInterface $userInfo = null) {
104
                    return $this->server->postToken($request, $userInfo);
105
                },
106
                [
107
                    'fkooman\Rest\Plugin\Authentication\AuthenticationPlugin' => [
108
                        'activate' => ['client'],
109
                        'require' => false,
110
                    ],
111
                ]
112
            );
113
        }
114
115 View Code Duplication
        if (!$this->options['disable_introspect_endpoint']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
116
            $service->post(
117
                $this->options['route_prefix'].'/introspect',
118
                function (Request $request, UserInfoInterface $userInfo) {
119
                    return $this->server->postIntrospect($request, $userInfo);
120
                },
121
                [
122
                    'fkooman\Rest\Plugin\Authentication\AuthenticationPlugin' => [
123
                        'activate' => ['resource_server'],
124
                    ],
125
                ]
126
            );
127
        }
128
    }
129
}
130