Completed
Pull Request — devel (#146)
by Litera
24:35 queued 19:02
created

UserService::getParentUnitDetail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Services\Skautis;
4
5
use Skautis\User;
6
7
/**
8
 * User service
9
 */
10
class UserService extends SkautisService
11
{
12
13
    /**
14
     * @return \Skautis\User
15
     */
16
	public function getUser(): User
17
	{
18
		return $this->getSkautis()->getUser();
19
	}
20
21
	/**
22
	 * Returns Role ID of logged user
23
	 *
24
	 * @param   void
25
	 * @return  type
26
	 */
27
	public function getRoleId()
28
	{
29
		return $this->getSkautis()->getRoleId();
0 ignored issues
show
Bug introduced by
The method getRoleId() does not seem to exist on object<Skautis\Skautis>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
30
	}
31
32
33
	/**
34
	 * Returns all Skautis roles
35
	 *
36
	 * @param   bool   $activeOnly  only active roles
37
	 * @return  array               all roles of logged user
38
	 */
39
	public function getAllSkautISRoles($activeOnly = true)
40
	{
41
		return $this->getSkautis()
0 ignored issues
show
Bug introduced by
The method UserRoleAll() does not seem to exist on object<Skautis\User>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
42
			->user
43
			->UserRoleAll([
44
				'ID_User'  => $this->getUserDetail()->ID,
45
				'IsActive' => $activeOnly,
46
			]);
47
	}
48
49
50
	/**
51
	 * Gets user detail
52
	 *
53
	 * @param   void
54
	 * @return  res
55
	 */
56
	public function getUserDetail()
57
	{
58
		$id = __FUNCTION__;
59
		// cache by the request
60
		if (!($res = $this->load($id))) {
61
			$res = $this->save($id, $this->getSkautis()->user->UserDetail());
0 ignored issues
show
Bug introduced by
The method UserDetail() does not seem to exist on object<Skautis\User>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
62
		}
63
		return $res;
64
	}
65
66
67
	/**
68
	 * Changes the loggeed user Skautis role
69
	 *
70
	 * @param   ID_Role  $id
71
	 * @return  void
72
	 */
73
	public function updateSkautISRole($id)
74
	{
75
		$skautis = $this->getSkautis();
76
77
		$unitId = $this->getSkautis()
0 ignored issues
show
Bug introduced by
The method LoginUpdate() does not seem to exist on object<Skautis\User>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
78
			->user
79
			->LoginUpdate([
80
				'ID_UserRole' => $id,
81
				'ID'          => $skautis->getToken(),
0 ignored issues
show
Bug introduced by
The method getToken() does not seem to exist on object<Skautis\Skautis>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
82
			]);
83
84
		if ($unitId) {
85
			$skautis->setRoleId($id);
0 ignored issues
show
Bug introduced by
The method setRoleId() does not seem to exist on object<Skautis\Skautis>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
86
			$skautis->setUnitId($unitId->ID_Unit);
0 ignored issues
show
Bug introduced by
The method setUnitId() does not seem to exist on object<Skautis\Skautis>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
87
		}
88
	}
89
90
91
	/**
92
	 * Returns complete list of information about logged user
93
	 *
94
	 * @param   void
95
	 * @return  type
96
	 */
97
	public function getPersonalDetail($personId = null)
98
	{
99
		if(!$personId) {
100
			$personId = $this->getUserDetail()->ID_Person;
101
		}
102
103
		return $this->getSkautis()->org->personDetail((["ID" => $personId]));
104
	}
105
106
	/**
107
	 * Returns complete list of information about logged user unit
108
	 *
109
	 * @param   void
110
	 * @return  type
111
	 */
112
	public function getParentUnitDetail($unitId)
113
	{
114
		return $this->getSkautis()->org->unitAll((["ID_UnitChild" => $unitId]));
115
	}
116
117
	/**
118
	 * Returns complete list of information about logged user unit
119
	 *
120
	 * @param   void
121
	 * @return  type
122
	 */
123
	public function getUnitDetail($unitId)
124
	{
125
		return $this->getSkautis()->org->unitDetail((["ID" => $unitId]));
126
	}
127
128
	/**
129
	 * Returns complete list of information about logged user unit
130
	 *
131
	 * @param   void
132
	 * @return  type
133
	 */
134
	public function getPersonUnitDetail($personId)
135
	{
136
		$membership = $this->getSkautis()
137
			->org
138
			->membershipAllPerson(([
139
				'ID_Person'         => $personId,
140
				'ID_MembershipType' => 'radne'
141
			]));
142
143
		return $membership->MembershipAllOutput;
144
	}
145
146
	/**
147
	 * Check if login session is still valid
148
	 *
149
	 * @param   void
150
	 * @return  type
151
	 */
152
	public function isLoggedIn()
153
	{
154
		return $this->getSkautis()->getUser()->isLoggedIn();
155
	}
156
157
158
	/**
159
	 * Resets login data
160
	 *
161
	 * @param   void
162
	 * @return  void
163
	 */
164
	public function resetLoginData()
165
	{
166
		$this->getSkautis()->resetLoginData();
0 ignored issues
show
Bug introduced by
The method resetLoginData() does not exist on Skautis\Skautis. Did you maybe mean setLoginData()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
167
	}
168
169
170
	/**
171
	 * Verify action
172
	 *
173
	 * @param   type  $table      např. ID_EventGeneral, NULL = oveření nad celou tabulkou
174
	 * @param   type  $id         id ověřované akce - např EV_EventGeneral_UPDATE
175
	 * @param   type  $ID_Action  tabulka v DB skautisu
176
	 * @return  BOOL|stdClass|array
177
	 */
178
	public function actionVerify($table, $id = NULL, $ID_Action = NULL)
179
	{
180
		$res = $this->getSkautis()->user->ActionVerify([
0 ignored issues
show
Bug introduced by
The method ActionVerify() does not seem to exist on object<Skautis\User>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
181
			'ID'        => $id,
182
			'ID_Table'  => $table,
183
			'ID_Action' => $ID_Action,
184
		]);
185
186
		// returns boolean if certain function for verifying is set
187
		if ($ID_Action !== NULL) {
188
			if ($res instanceof stdClass) {
0 ignored issues
show
Bug introduced by
The class App\Services\Skautis\stdClass does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
189
				return false;
190
			}
191
			if (is_array($res)) {
192
				return true;
193
			}
194
		}
195
		if (is_array($res)) {
196
			$tmp = array();
197
			foreach ($res as $v) {
198
				$tmp[$v->ID] = $v;
199
			}
200
			return $tmp;
201
		}
202
		return $res;
203
	}
204
205
}
206