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

PasswordCredential::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
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
    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