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

ResolvesCurrentUser   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getCurrentUserInfo() 0 7 1
A getCurrentUserDataId() 0 10 2
A getCurrentEmployerId() 0 4 1
A getCurrentManagerId() 0 4 1
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
}