Passed
Pull Request — 1.x (#67)
by
unknown
02:09
created

AccountMeEndpoint::verifyPassword()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DigitalCz\DigiSign\Endpoint;
6
7
use DigitalCz\DigiSign\Resource\ApiKey;
8
use DigitalCz\DigiSign\Resource\BaseResource;
9
use DigitalCz\DigiSign\Resource\ResourceInterface;
10
use DigitalCz\DigiSign\Resource\User;
11
12
/**
13
 * @extends ResourceEndpoint<BaseResource>
14
 */
15
final class AccountMeEndpoint extends ResourceEndpoint
16
{
17
    public function __construct(AccountEndpoint $parent)
18
    {
19
        parent::__construct($parent, '/me', BaseResource::class);
20
    }
21
22
    /**
23
     * @return User|ApiKey
24
     */
25
    public function get(): ResourceInterface
26
    {
27
        $result = $this->getRequest();
28
29
        // identify resource User/ApiKey
30
        $resourceClass = isset($result->firstName) ? User::class : ApiKey::class;
0 ignored issues
show
Bug introduced by
Accessing firstName on the interface Psr\Http\Message\ResponseInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
31
32
        return $this->createResource($result, $resourceClass);
33
    }
34
35
    /**
36
     * @param mixed[] $body
37
     * @return User
38
     */
39
    public function put(array $body): User
40
    {
41
        return $this->createResource($this->putRequest('', ['json' => $body]), User::class);
42
    }
43
44
    /**
45
     * @param mixed[] $body
46
     */
47
    public function changePassword(array $body): void
48
    {
49
        $this->postRequest('/change-password', ['json' => $body]);
50
    }
51
52
    /**
53
     * @param mixed[] $body
54
     */
55
    public function verifyPassword(array $body): void
56
    {
57
        $this->postRequest('/verify-password', ['json' => $body]);
58
    }
59
}
60