User::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
3
namespace Shrikeh\PagerDuty\Hydrator;
4
5
use stdClass;
6
use Shrikeh\PagerDuty\Collection\ContactMethods;
7
use Shrikeh\PagerDuty\Hydrator;
8
use Shrikeh\PagerDuty\Hydrator\ContactMethod as ContactMethodHydrator;
9
use Shrikeh\PagerDuty\Hydrator\Uri as UriHydrator;
10
use Shrikeh\PagerDuty\Entity\User\User as UserEntity;
11
12
final class User implements Hydrator
13
{
14
    private $contactMethodsHydrator;
15
    private $uriHydrator;
16
17
    public function __construct(
18
        ContactMethodHydrator $contactMethodsHydrator,
19
        UriHydrator $uriHydrator
20
    ) {
21
        $this->contactMethodsHydrator = $contactMethodsHydrator;
22
        $this->uriHydrator = $uriHydrator;
23
    }
24
25
    public function hydrate(stdClass $dto)
26
    {
27
        return UserEntity::fromData(
28
            ContactMethods::fromArray(array_map($this->contactMethodsHydrator, $dto->contact_methods)),
29
            $this->uriHydrator->hydrate($dto),
30
            $dto->name,
31
            $dto->email,
32
            $dto->summary
33
        );
34
    }
35
36
    public function supports($token)
37
    {
38
        return ('user' === $token);
39
    }
40
}
41