Completed
Push — master ( 457d5c...f99e05 )
by Sergey
05:31 queued 02:43
created

ResolvesCurrentUser::getCurrentManagerId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace seregazhuk\HeadHunterApi\Traits;
4
5
use seregazhuk\HeadHunterApi\EndPoints\Me;
6
use seregazhuk\HeadHunterApi\EndPoints\EndpointsContainer;
7
use seregazhuk\HeadHunterApi\Exceptions\HeadHunterApiException;
8
9
/**
10
 * Trait ResolvesCurrentUser
11
 *
12
 * @property EndpointsContainer $container
13
 */
14
trait ResolvesCurrentUser
15
{
16
    /**
17
     * @return array
18
     */
19
    protected function getCurrentUserInfo()
20
    {
21
        /** @var Me $meEndpoint */
22
        $meEndpoint = $this->container->getEndpoint('me');
23
24
        return $meEndpoint->info();
25
    }
26
27
    /**
28
     * @param $key
29
     * @return string
30
     * @throws HeadHunterApiException
31
     */
32
    protected function getCurrentUserDataId($key)
33
    {
34
        $currentUser = $this->getCurrentUserInfo();
35
36
        if (!isset($currentUser[$key]['id'])) {
37
            throw new HeadHunterApiException("Cannot resolve $key id");
38
        }
39
40
        return $currentUser[$key]['id'];
41
    }
42
43
    /**
44
     * @return string
45
     */
46
    protected function getCurrentEmployerId()
47
    {
48
        return $this->getCurrentUserDataId('employer');
49
    }
50
51
    /**
52
     * @return string
53
     */
54
    protected function getCurrentManagerId()
55
    {
56
        return $this->getCurrentUserDataId('employer');
57
    }
58
}