Completed
Push — master ( 1ce70a...0adf65 )
by Litera
11:25 queued 21s
created

UserService::getPersonUnitDetail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Services\SkautIS;
4
5
/**
6
 * User service
7
 */
8
class UserService extends SkautisService
9
{
10
11
	/**
12
	 * Returns Role ID of logged user
13
	 *
14
	 * @param   void
15
	 * @return  type
16
	 */
17
	public function getRoleId()
18
	{
19
		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...
20
	}
21
22
23
	/**
24
	 * Returns all SkautIS roles
25
	 *
26
	 * @param   bool   $activeOnly  only active roles
27
	 * @return  array               all roles of logged user
28
	 */
29
	public function getAllSkautISRoles($activeOnly = true)
30
	{
31
		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...
32
			->user
33
			->UserRoleAll([
34
				'ID_User'  => $this->getUserDetail()->ID,
35
				'IsActive' => $activeOnly,
36
			]);
37
	}
38
39
40
	/**
41
	 * Gets user detail
42
	 *
43
	 * @param   void
44
	 * @return  res
45
	 */
46
	public function getUserDetail()
47
	{
48
		$id = __FUNCTION__;
49
		// cache by the request
50
		if (!($res = $this->load($id))) {
51
			$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...
52
		}
53
		return $res;
54
	}
55
56
57
	/**
58
	 * Changes the loggeed user SkautIS role
59
	 *
60
	 * @param   ID_Role  $id
61
	 * @return  void
62
	 */
63
	public function updateSkautISRole($id)
64
	{
65
		$skautis = $this->getSkautis();
66
67
		$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...
68
			->user
69
			->LoginUpdate([
70
				'ID_UserRole' => $id,
71
				'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...
72
			]);
73
74
		if ($unitId) {
75
			$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...
76
			$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...
77
		}
78
	}
79
80
81
	/**
82
	 * Returns complete list of information about logged user
83
	 *
84
	 * @param   void
85
	 * @return  type
86
	 */
87
	public function getPersonalDetail($personId = null)
88
	{
89
		if(!$personId) {
90
			$personId = $this->getUserDetail()->ID_Person;
91
		}
92
93
		return $this->getSkautis()->org->personDetail((["ID" => $personId]));
94
	}
95
96
	/**
97
	 * Returns complete list of information about logged user unit
98
	 *
99
	 * @param   void
100
	 * @return  type
101
	 */
102
	public function getParentUnitDetail($unitId)
103
	{
104
		return $this->getSkautis()->org->unitAll((["ID_UnitChild" => $unitId]));
105
	}
106
107
	/**
108
	 * Returns complete list of information about logged user unit
109
	 *
110
	 * @param   void
111
	 * @return  type
112
	 */
113
	public function getUnitDetail($unitId)
114
	{
115
		return $this->getSkautis()->org->unitDetail((["ID" => $unitId]));
116
	}
117
118
	/**
119
	 * Returns complete list of information about logged user unit
120
	 *
121
	 * @param   void
122
	 * @return  type
123
	 */
124
	public function getPersonUnitDetail($personId)
125
	{
126
		$membership = $this->getSkautis()
127
			->org
128
			->membershipAllPerson(([
129
				'ID_Person'         => $personId,
130
				'ID_MembershipType' => 'radne'
131
			]));
132
133
		return $membership->MembershipAllOutput;
134
	}
135
136
	/**
137
	 * Check if login session is still valid
138
	 *
139
	 * @param   void
140
	 * @return  type
141
	 */
142
	public function isLoggedIn()
143
	{
144
		return $this->getSkautis()->getUser()->isLoggedIn();
145
	}
146
147
148
	/**
149
	 * Resets login data
150
	 *
151
	 * @param   void
152
	 * @return  void
153
	 */
154
	public function resetLoginData()
155
	{
156
		$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...
157
	}
158
159
160
	/**
161
	 * Verify action
162
	 *
163
	 * @param   type  $table      např. ID_EventGeneral, NULL = oveření nad celou tabulkou
164
	 * @param   type  $id         id ověřované akce - např EV_EventGeneral_UPDATE
165
	 * @param   type  $ID_Action  tabulka v DB skautisu
166
	 * @return  BOOL|stdClass|array
167
	 */
168
	public function actionVerify($table, $id = NULL, $ID_Action = NULL)
0 ignored issues
show
Coding Style Naming introduced by
The parameter $ID_Action is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
169
	{
170
		$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...
171
			'ID'        => $id,
172
			'ID_Table'  => $table,
173
			'ID_Action' => $ID_Action,
174
		]);
175
176
		// returns boolean if certain function for verifying is set
177
		if ($ID_Action !== NULL) {
178
			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...
179
				return false;
180
			}
181
			if (is_array($res)) {
182
				return true;
183
			}
184
		}
185
		if (is_array($res)) {
186
			$tmp = array();
187
			foreach ($res as $v) {
188
				$tmp[$v->ID] = $v;
189
			}
190
			return $tmp;
191
		}
192
		return $res;
193
	}
194
195
}
196