Skip to content
This repository was archived by the owner on Sep 19, 2022. It is now read-only.

Commit 92883de

Browse files
Merge pull request #25 from BaranekD/refactoring
Refactoring
2 parents 178442d + 5f06544 commit 92883de

File tree

5 files changed

+50
-46
lines changed

5 files changed

+50
-46
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ All notable changes to this project will be documented in this file.
88
#### Changed
99
- Warning in disco-tpl modified due to changes in module perun
1010
- Removed warning template - it is no longer needed here because it was moved to module perun
11+
- is_null() changed to === null
12+
- == and != changed to === and !==
13+
- Double quotes changed to single quotes
1114

1215
## [v2.1.0]
1316
#### Added

lib/Auth/Process/ComputeLoA.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
*/
1515
class ComputeLoA extends \SimpleSAML\Auth\ProcessingFilter
1616
{
17-
const UNIVERSITY = "university";
18-
const AVCR = "avcr";
19-
const LIBRARY = "library";
20-
const HOSPITAL = "hospital";
21-
const OTHER = "other";
22-
const EDUID_IDP_GROUP = "http://eduid.cz/uri/idp-group/";
17+
const UNIVERSITY = 'university';
18+
const AVCR = 'avcr';
19+
const LIBRARY = 'library';
20+
const HOSPITAL = 'hospital';
21+
const OTHER = 'other';
22+
const EDUID_IDP_GROUP = 'http://eduid.cz/uri/idp-group/';
2323
const DEFAULT_ATTR_NAME = 'loa';
2424

2525
private $attrName;
@@ -52,8 +52,8 @@ public function process(&$request)
5252
if (isset($sourceIdpMeta['EntityAttributes']['http://macedir.org/entity-category'])) {
5353
$entityCategoryAttributes = $sourceIdpMeta['EntityAttributes']['http://macedir.org/entity-category'];
5454
} else {
55-
Logger::error("cesnet:ComputeLoA - There are no element with name 'EntityAttributes' "
56-
. "and subelement with name 'http://macedir.org/entity-category' in metadata for IdP with entityId "
55+
Logger::error('cesnet:ComputeLoA - There are no element with name \'EntityAttributes\' '
56+
. 'and subelement with name \'http://macedir.org/entity-category\' in metadata for IdP with entityId '
5757
. $request['saml:sp:IdP'] . "!");
5858
$entityCategoryAttributes = [];
5959
}
@@ -62,7 +62,7 @@ public function process(&$request)
6262
$this->eduPersonScopedAffiliation = $request['Attributes']['eduPersonScopedAffiliation'];
6363
} else {
6464
Logger::error(
65-
"cesnet:ComputeLoA - Attribute with name 'eduPersonScopedAffiliation' did not received from IdP!"
65+
'cesnet:ComputeLoA - Attribute with name \'eduPersonScopedAffiliation\' did not received from IdP!'
6666
);
6767
}
6868

@@ -79,7 +79,7 @@ public function process(&$request)
7979
$loa = $this->getLoA();
8080

8181
$request['Attributes'][$this->attrName] = [$loa];
82-
Logger::debug("cesnet:ComputeLoA: loa '$loa' was saved to attribute " . $this->attrName);
82+
Logger::debug('cesnet:ComputeLoA: loa \'$loa\' was saved to attribute ' . $this->attrName);
8383
}
8484

8585
/**
@@ -89,17 +89,17 @@ public function process(&$request)
8989
private function getLoA()
9090
{
9191

92-
if (is_null($this->entityCategory) || empty($this->entityCategory)) {
92+
if ($this->entityCategory === null || empty($this->entityCategory)) {
9393
return 0;
9494
} elseif ($this->entityCategory === self::UNIVERSITY) {
9595
foreach ($this->eduPersonScopedAffiliation as $affiliation) {
9696
if (preg_match(
97-
"/(^employee@.+\.cz$)|" .
98-
"(^faculty@.+\.cz$)|" .
99-
"(^member@.+\.cz$)|" .
100-
"(^student@.+\.cz$)|" .
101-
"(^staff@.+\.cz$)|" .
102-
"(^alum@.+\.cz$)/",
97+
'/(^employee@.+\.cz$)|' .
98+
'(^faculty@.+\.cz$)|' .
99+
'(^member@.+\.cz$)|' .
100+
'(^student@.+\.cz$)|' .
101+
'(^staff@.+\.cz$)|' .
102+
'(^alum@.+\.cz$)/',
103103
$affiliation,
104104
$matches
105105
)) {
@@ -108,25 +108,25 @@ private function getLoA()
108108
}
109109
} elseif ($this->entityCategory === self::AVCR) {
110110
foreach ($this->eduPersonScopedAffiliation as $affiliation) {
111-
if (preg_match("/^member@.+\.cz$/", $affiliation, $matches)) {
111+
if (preg_match('/^member@.+\.cz$/', $affiliation, $matches)) {
112112
return 2;
113113
}
114114
}
115115
} elseif ($this->entityCategory === self::LIBRARY) {
116116
foreach ($this->eduPersonScopedAffiliation as $affiliation) {
117-
if (preg_match("/^employee@.+\.cz$/", $affiliation, $matches)) {
117+
if (preg_match('/^employee@.+\.cz$/', $affiliation, $matches)) {
118118
return 2;
119119
}
120120
}
121121
} elseif ($this->entityCategory === self::HOSPITAL) {
122122
foreach ($this->eduPersonScopedAffiliation as $affiliation) {
123-
if (preg_match("/^employee@.+\.cz$/", $affiliation, $matches)) {
123+
if (preg_match('/^employee@.+\.cz$/', $affiliation, $matches)) {
124124
return 2;
125125
}
126126
}
127127
} elseif ($this->entityCategory === self::OTHER) {
128128
foreach ($this->eduPersonScopedAffiliation as $affiliation) {
129-
if (preg_match("/(^employee@.+\.cz$)|(^member@.+\.cz$)/", $affiliation, $matches)) {
129+
if (preg_match('/(^employee@.+\.cz$)|(^member@.+\.cz$)/', $affiliation, $matches)) {
130130
return 2;
131131
}
132132
}

lib/Auth/Process/IsCesnetEligible.php

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ class IsCesnetEligible extends ProcessingFilter
2323
const CONFIG_FILE_NAME = 'module_cesnet_IsCesnetEligible.php';
2424
const ORGANIZATION_LDAP_BASE = 'ou=Organizations,o=eduID.cz,o=apps,dc=cesnet,dc=cz';
2525

26-
const HOSTEL_ENTITY_ID = "https://idp.hostel.eduid.cz/idp/shibboleth";
26+
const HOSTEL_ENTITY_ID = 'https://idp.hostel.eduid.cz/idp/shibboleth';
2727

28-
const INTERFACE_PROPNAME = "interface";
29-
const ATTR_NAME = "attrName";
30-
const RPC_ATTRIBUTE_NAME = "RPC.attributeName";
28+
const INTERFACE_PROPNAME = 'interface';
29+
const ATTR_NAME = 'attrName';
30+
const RPC_ATTRIBUTE_NAME = 'RPC.attributeName';
3131
const LDAP_ATTRIBUTE_NAME = 'LDAP.attributeName';
3232
const DEFAULT_ATTR_NAME = 'isCesnetEligibleLastSeen';
3333
const LDAP = 'LDAP';
@@ -65,8 +65,8 @@ public function __construct($config, $reserved)
6565

6666
if (!isset($config[self::RPC_ATTRIBUTE_NAME]) || empty($config[self::RPC_ATTRIBUTE_NAME])) {
6767
throw new Exception(
68-
"cesnet:IsCesnetEligible - missing mandatory configuration option '" .
69-
self::RPC_ATTRIBUTE_NAME . "'."
68+
'cesnet:IsCesnetEligible - missing mandatory configuration option \'' .
69+
self::RPC_ATTRIBUTE_NAME . '\'.'
7070
);
7171
}
7272

@@ -86,8 +86,8 @@ public function __construct($config, $reserved)
8686
$this->ldapAdapter = new AdapterLdap();
8787
} else {
8888
Logger::warning(
89-
"cesnet:IsCesnetEligible - One of " . self::INTERFACE_PROPNAME . self::LDAP_ATTRIBUTE_NAME .
90-
" is missing or empty. RPC interface will be used"
89+
'cesnet:IsCesnetEligible - One of ' . self::INTERFACE_PROPNAME . self::LDAP_ATTRIBUTE_NAME .
90+
' is missing or empty. RPC interface will be used'
9191
);
9292
}
9393
}
@@ -100,8 +100,8 @@ public function process(&$request)
100100
$user = $request['perun']['user'];
101101
} else {
102102
Logger::debug(
103-
"cesnet:IsCesnetEligible - " .
104-
"Request doesn't contain User, so attribute 'isCesnetEligible' won't be stored."
103+
'cesnet:IsCesnetEligible - ' .
104+
'Request doesn\'t contain User, so attribute \'isCesnetEligible\' won\'t be stored.'
105105
);
106106
$user = null;
107107
}
@@ -113,17 +113,18 @@ public function process(&$request)
113113
= $request['Attributes']['eduPersonScopedAffiliation'];
114114
} else {
115115
Logger::error(
116-
"cesnet:IsCesnetEligible - Attribute with name 'eduPersonScopedAffiliation' did not received from IdP!"
116+
'cesnet:IsCesnetEligible - ' .
117+
'Attribute with name \'eduPersonScopedAffiliation\' did not received from IdP!'
117118
);
118119
}
119120

120121
$isHostelVerified = false;
121122
if ($request['saml:sp:IdP'] === self::HOSTEL_ENTITY_ID &&
122123
isset($request['Attributes']['loa'])
123-
&& $request['Attributes']['loa'][0] == 2
124+
&& $request['Attributes']['loa'][0] === 2
124125
) {
125126
$isHostelVerified = true;
126-
Logger::debug("cesnet:IsCesnetEligible - The user was verified by Hostel.");
127+
Logger::debug('cesnet:IsCesnetEligible - The user was verified by Hostel.');
127128
}
128129

129130
try {
@@ -144,7 +145,7 @@ public function process(&$request)
144145
}
145146

146147
if ($isHostelVerified || (!empty($this->eduPersonScopedAffiliation) && $this->isCesnetEligible())) {
147-
$this->cesnetEligibleLastSeenValue = date("Y-m-d H:i:s");
148+
$this->cesnetEligibleLastSeenValue = date('Y-m-d H:i:s');
148149

149150
if (!empty($user)) {
150151
if ($this->cesnetEligibleLastSeenAttribute === null) {
@@ -163,19 +164,19 @@ public function process(&$request)
163164
);
164165

165166
Logger::debug(
166-
"cesnet:IsCesnetEligible - Value of attribute isCesnetEligibleLastSeen was updated to " .
167-
$this->cesnetEligibleLastSeenValue . "in Perun system."
167+
'cesnet:IsCesnetEligible - Value of attribute isCesnetEligibleLastSeen was updated to ' .
168+
$this->cesnetEligibleLastSeenValue . 'in Perun system.'
168169
);
169170
}
170171
}
171172
} catch (Exception $ex) {
172-
Logger::warning("cesnet:IsCesnetEligible - " . $ex->getMessage());
173+
Logger::warning('cesnet:IsCesnetEligible - ' . $ex->getMessage());
173174
}
174175

175176
if ($this->cesnetEligibleLastSeenValue !== null) {
176177
$request['Attributes'][$this->returnAttrName] = [$this->cesnetEligibleLastSeenValue];
177178
Logger::debug(
178-
"cesnet:IsCesnetEligible - Attribute " . $this->returnAttrName . " was set to value " .
179+
'cesnet:IsCesnetEligible - Attribute ' . $this->returnAttrName . ' was set to value ' .
179180
$this->cesnetEligibleLastSeenValue
180181
);
181182
}
@@ -190,8 +191,8 @@ private function isCesnetEligible()
190191
$allowedAffiliations
191192
= $this->getAllowedAffiliations($this->idpEntityId);
192193
foreach ($this->eduPersonScopedAffiliation as $userAffiliation) {
193-
$userAffiliationWithoutScope = explode("@", $userAffiliation)[0];
194-
if (!is_null($userAffiliationWithoutScope) &&
194+
$userAffiliationWithoutScope = explode('@', $userAffiliation)[0];
195+
if ($userAffiliationWithoutScope !== null &&
195196
!empty($userAffiliationWithoutScope) &&
196197
in_array($userAffiliationWithoutScope, $allowedAffiliations)
197198
) {
@@ -218,15 +219,15 @@ private function getAllowedAffiliations($idpEntityId)
218219
)['cesnetcustomeraffiliation'];
219220

220221
if (empty($affiliations)) {
221-
Logger::debug("cesnet:IsCesnetEligible - Received empty response from LDAP, entityId "
222-
. $idpEntityId . " was probably not found.");
222+
Logger::debug('cesnet:IsCesnetEligible - Received empty response from LDAP, entityId '
223+
. $idpEntityId . ' was probably not found.');
223224
} else {
224225
foreach ($affiliations as $affiliation) {
225226
array_push($allowedAffiliations, $affiliation);
226227
}
227228
}
228229
} catch (Exception $ex) {
229-
Logger::warning("cesnet:IsCesnetEligible - Unable to connect to LDAP!");
230+
Logger::warning('cesnet:IsCesnetEligible - Unable to connect to LDAP!');
230231
}
231232

232233
return $allowedAffiliations;

themes/cesnet/default/includes/header.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
$version = $jquery['version'];
6969
}
7070

71-
if ($version == '1.8') {
71+
if ($version === '1.8') {
7272
if (isset($jquery['core']) && $jquery['core']) {
7373
echo(
7474
'<script type="text/javascript" src="/' . $this->data['baseurlpath'] .

themes/cesnet/perun/disco-tpl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
header('Location: https://ds.eduid.cz/wayf.php' . $url . '&filter=' . $defaultFilter);
126126
exit;
127127
} else {
128-
throw new Exception("cesnet:disco-tpl: Filter did not set. ");
128+
throw new Exception('cesnet:disco-tpl: Filter did not set. ');
129129
}
130130
}
131131
}

0 commit comments

Comments
 (0)