Test Failed
Push — master ( c83fb3...05e696 )
by Luka
02:24
created

PasswordCredential   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A auth() 0 11 1
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
    public function __construct($username, $password)
28
    {
29
        $this->username = $username;
30
        $this->password = $password;
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' => 'password',
44
                'username' => $this->username,
45
                'password' => $this->password,
46
                'scope' => (string)$scope,
47
            ] + static::getFormParams($factory),
48
        ]);
49
    }
50
}
51