Test Failed
Push — master ( 7faec7...d45337 )
by Luka
02:25
created

CodeGrant   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 33
loc 33
rs 10
wmc 2
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A auth() 10 10 1

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
namespace Baguette\Mastodon\Grant;
4
5
use Baguette\Mastodon\Service\AuthFactory;
6
use Baguette\Mastodon\Service\Scope;
7
use GuzzleHttp\ClientInterface as Client;
8
9
/**
10
 * Mastodon Authorization Code grant
11
 *
12
 * @author    USAMI Kenta <[email protected]>
13
 * @copyright 2017 Baguette HQ
14
 * @license   https://www.gnu.org/licenses/gpl-3.0.html GPL-3.0
15
 * @see https://tools.ietf.org/html/draft-ietf-oauth-v2-22#section-4.1
16
 */
17 View Code Duplication
class CodeGrant extends Grant
0 ignored issues
show
Duplication introduced by
This class 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...
18
{
19
    /** @var string */
20
    private $code;
21
    /** @var string */
22
    private $redirect_uri;
23
24
    /**
25
     * @param string $code
26
     */
27
    public function __construct($code, $redirect_uri)
28
    {
29
        $this->code = $code;
30
        $this->redirect_uri = $redirect_uri;
31
    }
32
33
    /**
34
     * @param  Client      $http
35
     * @param  AuthFactory $factory
36
     * @param  Scope       $scope
37
     * @return \Psr\Http\Message\ResponseInterface
38
     */
39
    public function auth(Client $http, AuthFactory $factory, Scope $scope)
40
    {
41
        return $http->request('POST', static::getPathToOAuthToken($factory->client), [
42
            'form_params' => [
43
                'grant_type' => 'authorization_code',
44
                'code'  => $this->code,
45
                'scope' => (string)$scope,
46
            ] + static::getFormParams($factory),
47
        ]);
48
    }
49
}
50