Completed
Pull Request — master (#102)
by Litera
11:03
created

UserService::getPersonUnitDetail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Services;
4
5
6
/**
7
 * User service
8
 */
9
class UserService extends BaseService
10
{
11
12
	/**
13
	 * Returns Role ID of logged user
14
	 *
15
	 * @param   void
16
	 * @return  type
17
	 */
18
	public function getRoleId()
19
	{
20
		return $this->skautis->getRoleId();
21
	}
22
23
24
	/**
25
	 * Returns all SkautIS roles
26
	 *
27
	 * @param   bool   $activeOnly  only active roles
28
	 * @return  array               all roles of logged user
29
	 */
30
	public function getAllSkautISRoles($activeOnly = true)
31
	{
32
		return $this->skautis->user->UserRoleAll(array("ID_User" => $this->getUserDetail()->ID, "IsActive" => $activeOnly));
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal ID_User does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal IsActive does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
33
	}
34
35
36
	/**
37
	 * Gets user detail
38
	 *
39
	 * @param   void
40
	 * @return  res
41
	 */
42
	public function getUserDetail()
43
	{
44
		$id = __FUNCTION__;
45
		// cache by the request
46
		if (!($res = $this->load($id))) {
47
			$res = $this->save($id, $this->skautis->user->UserDetail());
48
		}
49
		return $res;
50
	}
51
52
53
	/**
54
	 * Changes the loggeed user SkautIS role
55
	 *
56
	 * @param   ID_Role  $id
57
	 * @return  void
58
	 */
59
	public function updateSkautISRole($id)
60
	{
61
		$unitId = $this->skautis->user->LoginUpdate(array("ID_UserRole" => $id, "ID" => $this->skautis->getToken()));
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal ID_UserRole does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal ID does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
62
		if ($unitId) {
63
			$this->skautis->setRoleId($id);
64
			$this->skautis->setUnitId($unitId->ID_Unit);
65
		}
66
	}
67
68
69
	/**
70
	 * Returns complete list of information about logged user
71
	 *
72
	 * @param   void
73
	 * @return  type
74
	 */
75
	public function getPersonalDetail($personId = null)
76
	{
77
		if(!$personId) {
78
			$personId = $this->getUserDetail()->ID_Person;
79
		}
80
81
		return $this->skautis->org->personDetail((["ID" => $personId]));
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal ID does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
82
	}
83
84
	/**
85
	 * Returns complete list of information about logged user unit
86
	 *
87
	 * @param   void
88
	 * @return  type
89
	 */
90
	public function getParentUnitDetail($unitId)
91
	{
92
		return $this->skautis->org->unitAll((array("ID_UnitChild" => $unitId)));
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal ID_UnitChild does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
93
	}
94
95
	/**
96
	 * Returns complete list of information about logged user unit
97
	 *
98
	 * @param   void
99
	 * @return  type
100
	 */
101
	public function getUnitDetail($unitId)
102
	{
103
		return $this->skautis->org->unitDetail((array("ID" => $unitId)));
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal ID does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
104
	}
105
106
	/**
107
	 * Returns complete list of information about logged user unit
108
	 *
109
	 * @param   void
110
	 * @return  type
111
	 */
112
	public function getPersonUnitDetail($personId)
113
	{
114
		$membership = $this->skautis->org->membershipAllPerson((array('ID_Person' => $personId, "ID_MembershipType" => "radne")));
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal ID_MembershipType does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal radne does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
115
116
		return $membership->MembershipAllOutput;
117
	}
118
119
	/**
120
	 * Check if login session is still valid
121
	 *
122
	 * @param   void
123
	 * @return  type
124
	 */
125
	public function isLoggedIn()
126
	{
127
		return $this->skautis->getUser()->isLoggedIn();
128
	}
129
130
131
	/**
132
	 * Resets login data
133
	 *
134
	 * @param   void
135
	 * @return  void
136
	 */
137
	public function resetLoginData()
138
	{
139
		$this->skautis->resetLoginData();
140
	}
141
142
143
	/**
144
	 * Verify action
145
	 *
146
	 * @param   type  $table      např. ID_EventGeneral, NULL = oveření nad celou tabulkou
147
	 * @param   type  $id         id ověřované akce - např EV_EventGeneral_UPDATE
148
	 * @param   type  $ID_Action  tabulka v DB skautisu
149
	 * @return  BOOL|stdClass|array
150
	 */
151
	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...
152
	{
153
		$res = $this->skautis->user->ActionVerify(array(
154
			"ID" => $id,
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal ID does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
155
			"ID_Table" => $table,
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal ID_Table does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
156
			"ID_Action" => $ID_Action,
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal ID_Action does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
157
		));
158
159
		// returns boolean if certain function for verifying is set
160
		if ($ID_Action !== NULL) {
161
			if ($res instanceof stdClass) {
0 ignored issues
show
Bug introduced by
The class App\Services\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...
162
				return false;
163
			}
164
			if (is_array($res)) {
165
				return true;
166
			}
167
		}
168
		if (is_array($res)) {
169
			$tmp = array();
170
			foreach ($res as $v) {
171
				$tmp[$v->ID] = $v;
172
			}
173
			return $tmp;
174
		}
175
		return $res;
176
	}
177
178
}
179