PasswordCredential::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
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 password credential 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
 */
16
class PasswordCredential extends Grant
17
{
18
    /** @var string */
19
    private $username;
20
    /** @var string */
21
    private $password;
22
23
    /**
24
     * @param string $username
25
     * @param string $password
26
     */
27 5
    public function __construct($username, $password)
28
    {
29 5
        $this->username = $username;
30 5
        $this->password = $password;
31 5
    }
32
33
    /**
34
     * @param  Client      $http
35
     * @param  AuthFactory $factory
36
     * @param  Scope       $scope
37
     * @return \Psr\Http\Message\ResponseInterface
38
     */
39 View Code Duplication
    public function auth(Client $http, AuthFactory $factory, Scope $scope)
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...
40
    {
41
        return $http->request('POST', static::getPathToOAuthToken($factory->client), [
42
            'form_params' => [
43
                'grant_type' => 'password',
44
                'username' => $this->username,
45
                'password' => $this->password,
46
                'scope' => (string)$scope,
47
            ] + static::getFormParamsWithSecret($factory),
48
        ]);
49
    }
50
}
51