|
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(); |
|
|
|
|
|
|
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() |
|
|
|
|
|
|
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() |
|
|
|
|
|
|
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
|
|
|
} |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
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.