Completed
Push — master ( c07173...5d7f79 )
by Sergey
02:36
created

Manager::preferences()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 13
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
1
<?php
2
3
namespace seregazhuk\HeadHunterApi\EndPoints;
4
5
use seregazhuk\HeadHunterApi\Exceptions\HeadHunterApiException;
6
7
class Manager extends Endpoint
8
{
9
10
    const RESOURCE = '/employers/{employer_id}/managers/{manager_id}/settings';
11
12
    /**
13
     * @var array
14
     */
15
    protected $currentUser;
16
17
    /**
18
     * Get manager settings
19
     * @param integer $managerId
20
     * @return array
21
     */
22
    public function preferences($managerId = null)
23
    {
24
        $employerId = $this->getCurrentEmployerId();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $employerId is correct as $this->getCurrentEmployerId() (which targets seregazhuk\HeadHunterApi...:getCurrentEmployerId()) 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...
25
        $managerId = $managerId ? : $this->getCurrentManagerId();
26
27
        $resource = str_replace(
28
            ['{employer_id}', '{manager_id}'],
29
            [$employerId, $managerId],
30
            self::RESOURCE);
31
32
33
        return $this->request->get($resource);
34
    }
35
36
    /**
37
     * @return null
38
     * @throws HeadHunterApiException
39
     */
40 View Code Duplication
    protected function getCurrentEmployerId()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42
        $currentUser = $this->getCurrentUser();
43
44
        if(!isset($currentUser['employer']['id'])) {
45
            throw new HeadHunterApiException('Cannot resolve employer id');
46
        }
47
48
        return $currentUser['employer']['id'];
49
    }
50
51
    protected function getCurrentUser()
52
    {
53
        if(!empty($this->currentUser)) return $this->currentUser;
54
55
        $this->currentUser = $this->request->get(Me::RESOURCE);
56
57
        return $this->currentUser;
58
    }
59
60 View Code Duplication
    protected function getCurrentManagerId()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
    {
62
        $currentUser = $this->getCurrentUser();
63
64
        if(!isset($currentUser['manager']['id'])) {
65
            throw new HeadHunterApiException('Cannot resolve manager id');
66
        }
67
68
        return $currentUser['manager']['id'];
69
    }
70
}