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

Commit 1db080f

Browse files
BaranekDvyskocilpavel
authored andcommitted
Removed var ===/!== null checks before empty(var) function
1 parent 7588840 commit 1db080f

File tree

7 files changed

+23
-34
lines changed

7 files changed

+23
-34
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ All notable changes to this project will be documented in this file.
6666
#### Changed
6767
- RpcConnector now stores cookie into file
6868
- Set CONNECTTIMEOUT and TIMEOUT in RpcConnector
69+
- Removed checks in ifs that var is (not) null before empty(var) function (empty checks that itself)
6970
- Use new object perunFacility in LDAP to search information about facility
7071
- Configuration for warning on DS is now in module_perun.php
7172

lib/AdapterLdap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ public function getMemberStatusByUserAndVo($user, $vo)
337337
["perunGroupid"]
338338
);
339339

340-
if ($groupId === null || empty($groupId)) {
340+
if (empty($groupId)) {
341341
return Member::INVALID;
342342
}
343343
return Member::VALID;

lib/Auth/Process/PerunAttributes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function process(&$request)
8181
foreach ($this->attrMap as $attrName => $attrValue) {
8282
if (isset($request['Attributes'][$attrValue])) {
8383
$attr = $request['Attributes'][$attrValue];
84-
if ($attr === null || empty($attr)) {
84+
if (empty($attr)) {
8585
array_push($attributes, $attrName);
8686
}
8787
} else {

lib/Auth/Process/PerunIdentity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public function process(&$request)
216216

217217
$groups = $this->adapter->getUsersGroupsOnFacility($this->spEntityId, $user->getId());
218218

219-
if ($this->checkGroupMembership && ($groups === null || empty($groups))) {
219+
if ($this->checkGroupMembership && empty($groups)) {
220220
if ($this->allowRegistrationToGroups) {
221221
$vosForRegistration = $this->getVosForRegistration($user);
222222

templates/listOfSps-tpl.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
<th><?php echo $this->t('{perun:listOfSps:description}') ?></th>
9797
<?php
9898
foreach ($attributesToShow as $attr) {
99-
if ($samlServices !== null && !empty($samlServices)) {
99+
if (!empty($samlServices)) {
100100
echo "<th class='" .
101101
getClass(array_values($samlServices)[0]['facilityAttributes'][$attr]) .
102102
"'>" . array_values($samlServices)[0]['facilityAttributes'][$attr]['displayName']
@@ -109,8 +109,7 @@
109109
<tbody>
110110
<?php
111111
foreach ($allServices as $service) {
112-
if ($service['showOnServiceList'] === null || $service['showOnServiceList']['value'] === null ||
113-
empty($service['showOnServiceList']['value']) ||
112+
if (empty($service['showOnServiceList']['value']) ||
114113
!($service['showOnServiceList']['value'])
115114
) {
116115
continue;
@@ -142,8 +141,7 @@
142141

143142
function printServiceName($service)
144143
{
145-
if ($service['loginURL'] === null || $service['loginURL']['value'] === null ||
146-
empty($service['loginURL']['value'])
144+
if (empty($service['loginURL']['value'])
147145
) {
148146
return $service['facility']->getName();
149147
} else {
@@ -155,7 +153,7 @@ function printServiceName($service)
155153
function printAttributeValue($attribute, $service, $attr)
156154
{
157155
$value = $attribute['value'];
158-
if (($value === null || empty($value)) && $attribute['type'] !== "java.lang.Boolean") {
156+
if (empty($value) && $attribute['type'] !== "java.lang.Boolean") {
159157
return "<td class='center'>&horbar;</td>";
160158
}
161159
$string = '';

www/getSpMetadata.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@
2222
$conf = Configuration::getConfig(CONFIG_FILE_NAME);
2323

2424
$proxyIdentifier = $conf->getString(PROXY_IDENTIFIER);
25-
assert($proxyIdentifier === null || empty($proxyIdentifier));
25+
assert(empty($proxyIdentifier));
2626

2727
$attributesDefinitions = $conf->getArray(ATTRIBUTES_DEFINITIONS);
2828
assert($attributesDefinitions === null || is_array($attributesDefinitions));
2929

3030
$perunProxyIdentifierAttr = $conf->getString(PERUN_PROXY_IDENTIFIER_ATTR_NAME);
3131
$perunProxyEntityIDAttr = $conf->getString(PERUN_PROXY_ENTITY_ID_ATTR_NAME);
32-
assert($perunProxyEntityIDAttr === null || empty($perunProxyEntityIDAttr) ||
33-
$perunProxyIdentifierAttr === null || empty($perunProxyIdentifierAttr));
32+
33+
assert(empty($perunProxyEntityIDAttr) || empty($perunProxyIdentifierAttr));
3434

3535
$absoluteFileName = $conf->getString(ABSOLUTE_FILE_NAME);
36-
assert($absoluteFileName === null || empty($absoluteFileName));
36+
assert(empty($absoluteFileName));
3737

3838
$rpcAdapter = new AdapterRpc();
3939

www/listOfSps.php

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,23 @@
2121
$conf = Configuration::getConfig(CONFIG_FILE_NAME);
2222

2323
$proxyIdentifier = $conf->getString(PROXY_IDENTIFIER);
24-
if ($proxyIdentifier === null || empty($proxyIdentifier)) {
24+
if (empty($proxyIdentifier)) {
2525
throw new Exception(
2626
"perun:listOfSps: missing mandatory config option '" . PROXY_IDENTIFIER
2727
. "'."
2828
);
2929
}
3030

3131
$perunProxyIdentifierAttr = $conf->getString(PERUN_PROXY_IDENTIFIER_ATTR_NAME);
32-
if ($perunProxyIdentifierAttr === null || empty($perunProxyIdentifierAttr)) {
32+
if (empty($perunProxyIdentifierAttr)) {
3333
throw new Exception(
3434
"perun:listOfSps: missing mandatory config option '"
3535
. PERUN_PROXY_IDENTIFIER_ATTR_NAME . "'."
3636
);
3737
}
3838

3939
$attributesDefinitions = $conf->getArray(ATTRIBUTES_DEFINITIONS);
40-
if ($attributesDefinitions === null || empty($attributesDefinitions)) {
40+
if (empty($attributesDefinitions)) {
4141
throw new Exception(
4242
"perun:listOfSps: missing mandatory config option '"
4343
. ATTRIBUTES_DEFINITIONS . "'."
@@ -46,18 +46,15 @@
4646

4747
$showOIDCServices = $conf->getBoolean(SHOW_OIDC_SERVICES, false);
4848
$perunSaml2EntityIdAttr = $conf->getString(PERUN_SAML2_ENTITY_ID_ATTR_NAME);
49-
if ($perunSaml2EntityIdAttr === null || empty($perunSaml2EntityIdAttr)) {
49+
if (empty($perunSaml2EntityIdAttr)) {
5050
throw new Exception(
5151
"perun:listOfSps: missing mandatory config option '"
5252
. PERUN_SAML2_ENTITY_ID_ATTR_NAME . "'."
5353
);
5454
}
5555

5656
$perunOidcClientIdAttr = $conf->getString(PERUN_OIDC_CLIENT_ID_ATTR_NAME);
57-
if ($showOIDCServices
58-
&& ($perunOidcClientIdAttr === null
59-
|| empty($perunOidcClientIdAttr))
60-
) {
57+
if ($showOIDCServices && empty($perunOidcClientIdAttr)) {
6158
throw new Exception(
6259
"perun:listOfSps: missing mandatory config option '"
6360
. PERUN_OIDC_CLIENT_ID_ATTR_NAME . "'."
@@ -78,18 +75,16 @@
7875
$attrNames = [];
7976

8077
array_push($attrNames, $perunSaml2EntityIdAttr);
81-
if ($perunOidcClientIdAttr !== null && !empty($perunOidcClientIdAttr)) {
78+
if (!empty($perunOidcClientIdAttr)) {
8279
array_push($attrNames, $perunOidcClientIdAttr);
8380
}
84-
if ($perunLoginURLAttr !== null && !empty($perunLoginURLAttr)) {
81+
if (!empty($perunLoginURLAttr)) {
8582
array_push($attrNames, $perunLoginURLAttr);
8683
}
87-
if ($perunTestSpAttr !== null && !empty($perunTestSpAttr)) {
84+
if (!empty($perunTestSpAttr)) {
8885
array_push($attrNames, $perunTestSpAttr);
8986
}
90-
if ($perunShowOnServiceListAttr !== null
91-
&& !empty($perunShowOnServiceListAttr)
92-
) {
87+
if (!empty($perunShowOnServiceListAttr)) {
9388
array_push($attrNames, $perunShowOnServiceListAttr);
9489
}
9590
foreach ($attributesDefinitions as $attributeDefinition) {
@@ -107,9 +102,7 @@
107102
foreach ($attributes as $attribute) {
108103
$facilityAttributes[$attribute['name']] = $attribute;
109104
}
110-
if ($facilityAttributes[$perunSaml2EntityIdAttr]['value'] !== null
111-
&& !empty($facilityAttributes[$perunSaml2EntityIdAttr]['value'])
112-
) {
105+
if (!empty($facilityAttributes[$perunSaml2EntityIdAttr]['value'])) {
113106
$samlServices[$facility->getId()] = [
114107
'facility' => $facility,
115108
'loginURL' => $facilityAttributes[$perunLoginURLAttr],
@@ -121,10 +114,7 @@
121114
}
122115
}
123116

124-
if ($showOIDCServices
125-
&& ($facilityAttributes[$perunOidcClientIdAttr]['value'] !== null
126-
&& !empty($facilityAttributes[$perunOidcClientIdAttr]['value']))
127-
) {
117+
if ($showOIDCServices && !empty($facilityAttributes[$perunOidcClientIdAttr]['value'])) {
128118
$oidcServices[$facility->getId()] = [
129119
'facility' => $facility,
130120
'loginURL' => $facilityAttributes[$perunLoginURLAttr],

0 commit comments

Comments
 (0)