Completed
Push — master ( 21003f...1e77f8 )
by Sergey
04:08 queued 01:24
created

Manager::getCurrentUserInfo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 7
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace seregazhuk\HeadHunterApi\EndPoints;
4
5
use seregazhuk\HeadHunterApi\Exceptions\HeadHunterApiException;
6
7
class Manager extends Endpoint
8
{
9
    const RESOURCE = '/employers';
10
11
    /**
12
     * Get manager settings
13
     * @param integer $managerId
14
     * @return array
15
     */
16
    public function preferences($managerId = null)
17
    {
18
        $employerId = $this->getCurrentUserDataId('employer');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $employerId is correct as $this->getCurrentUserDataId('employer') (which targets seregazhuk\HeadHunterApi...:getCurrentUserDataId()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
19
        $managerId = $managerId ?: $this->getCurrentUserDataId('manager');
20
21
        $uri = str_replace(
22
            ['{employer_id}', '{manager_id}'],
23
            [$employerId, $managerId],
24
            '{employer_id}/managers/{manager_id}/settings'
25
        );
26
27
        return $this->getResource($uri);
28
    }
29
30
    /**
31
     * @param $key
32
     * @return null
33
     * @throws HeadHunterApiException
34
     */
35
    protected function getCurrentUserDataId($key)
36
    {
37
        $currentUser = $this->getCurrentUserInfo();
38
39
        if (!isset($currentUser[$key]['id'])) {
40
            throw new HeadHunterApiException("Cannot resolve $key id");
41
        }
42
43
        return $currentUser[$key]['id'];
44
    }
45
46
    /**
47
     * @return array
48
     */
49
    protected function getCurrentUserInfo()
50
    {
51
        /** @var Me $meEndpoint */
52
        $meEndpoint = $this->container->getEndpoint('me');
53
54
        return $meEndpoint->info();
55
    }
56
}