1717use SimpleSAML \Module \perun \model \User ;
1818
1919/**
20- * Class IsCesnetEligible
20+ * Class IsCesnetEligible.
2121 *
2222 * This class put the timestamp of last login into list of Attributes, when at least one value of attribute
2323 * 'eduPersonScopedAffiliation' is marked as isCesnetEligible in CESNET LDAP
@@ -87,8 +87,7 @@ public function __construct($config, $reserved)
8787 $ conf = Configuration::loadFromArray ($ config );
8888 if (! isset ($ config [self ::RPC_ATTRIBUTE_NAME ]) || empty ($ config [self ::RPC_ATTRIBUTE_NAME ])) {
8989 throw new Exception (
90- 'cesnet:IsCesnetEligible - missing mandatory configuration option \'' .
91- self ::RPC_ATTRIBUTE_NAME . '\'. '
90+ 'cesnet:IsCesnetEligible - missing mandatory configuration option \'' . self ::RPC_ATTRIBUTE_NAME . '\'. '
9291 );
9392 }
9493
@@ -102,7 +101,7 @@ public function __construct($config, $reserved)
102101 }
103102
104103 if (isset ($ config [self ::INTERFACE_PROPNAME ], $ config [self ::LDAP_ATTRIBUTE_NAME ]) &&
105- $ config [ self ::INTERFACE_PROPNAME ] === self ::LDAP && ! empty ($ config [self ::LDAP_ATTRIBUTE_NAME ])) {
104+ self ::LDAP === $ config [ self ::INTERFACE_PROPNAME ] && ! empty ($ config [self ::LDAP_ATTRIBUTE_NAME ])) {
106105 $ this ->interface = $ config [self ::INTERFACE_PROPNAME ];
107106 $ this ->ldapAttrName = $ config [self ::LDAP_ATTRIBUTE_NAME ];
108107 $ this ->adapter = Adapter::getInstance (Adapter::LDAP );
@@ -150,7 +149,7 @@ public function process(&$request)
150149 }
151150
152151 if (! empty ($ user )) {
153- if ($ this -> interface === self :: LDAP ) {
152+ if (self :: LDAP === $ this -> interface ) {
154153 $ attrs = $ this ->adapter ->getUserAttributes ($ user , [$ this ->ldapAttrName ]);
155154 if (isset ($ attrs [$ this ->ldapAttrName ][0 ])) {
156155 $ this ->cesnetEligibleLastSeenValue = $ attrs [$ this ->ldapAttrName ][0 ];
@@ -188,7 +187,7 @@ public function process(&$request)
188187 }
189188 }
190189
191- if ($ this -> cesnetEligibleLastSeenValue !== null ) {
190+ if (null !== $ this -> cesnetEligibleLastSeenValue ) {
192191 $ request ['Attributes ' ][$ this ->returnAttrName ] = [$ this ->cesnetEligibleLastSeenValue ];
193192 Logger::debug (
194193 'cesnet:IsCesnetEligible - Attribute ' . $ this ->returnAttrName . ' was set to value ' .
@@ -197,7 +196,7 @@ public function process(&$request)
197196 }
198197
199198 $ request ['Attributes ' ]['isCesnetEligible ' ] = ['false ' ];
200- if (($ this -> cesnetEligibleLastSeenValue !== null ) && $ this ->cesnetEligibleLastSeenValue > date (
199+ if ((null !== $ this -> cesnetEligibleLastSeenValue ) && $ this ->cesnetEligibleLastSeenValue > date (
201200 'Y-m-d H:i:s ' ,
202201 strtotime ('-1 year ' )
203202 )) {
@@ -207,7 +206,7 @@ public function process(&$request)
207206 }
208207
209208 /**
210- * Returns true if one of user's affiliation is in allowed affiliations for this IdP , False if not
209+ * Returns true if one of user's affiliation is in allowed affiliations for this IdP , False if not.
211210 *
212211 * @param User $user or Null
213212 */
@@ -218,7 +217,7 @@ private function isCesnetEligible($user): bool
218217 return true ;
219218 }
220219
221- # Check if user has isCesnetEligible by sponsoring in some organization
220+ // Check if user has isCesnetEligible by sponsoring in some organization
222221 try {
223222 if (isset ($ user , $ this ->userAffiliationsAttrName , $ this ->userSponsoringOrganizationsAttrName )) {
224223 $ userAttributes = $ this ->rpcAdapter ->getUserAttributesValues (
@@ -235,10 +234,12 @@ private function isCesnetEligible($user): bool
235234 json_encode ($ perunUserAffiliations ) . ', ' . $ this ->userSponsoringOrganizationsAttrName .
236235 ': ' . json_encode ($ perunUserSponsoringOrganizations ) . '] has empty value! '
237236 );
237+
238238 return false ;
239239 }
240240
241241 $ allowedSponsoredAffiliations = $ this ->getAllowedAffiliations ($ perunUserSponsoringOrganizations );
242+
242243 return $ this ->compareAffiliations ($ perunUserAffiliations , $ allowedSponsoredAffiliations );
243244 }
244245 } catch (\Exception $ exception ) {
@@ -252,9 +253,10 @@ private function isCesnetEligible($user): bool
252253 }
253254
254255 /**
255- * Return list of allowed affiliations for IdP from CESNET LDAP
256+ * Return list of allowed affiliations for IdP from CESNET LDAP.
256257 *
257258 * @param array $idpEntityIds of entityId of IdPs
259+ *
258260 * @return array of allowed affiliations
259261 */
260262 private function getAllowedAffiliations ($ idpEntityIds ): array
@@ -298,7 +300,7 @@ private function getAllowedAffiliations($idpEntityIds): array
298300 /**
299301 * Compare two lists of affiliations and returns true if one of affiliations without scope is in booth lists.
300302 *
301- * @param array $userAffiliations of user scoped affiliations
303+ * @param array $userAffiliations of user scoped affiliations
302304 * @param array $allowedAffiliations of allowed unscoped affiliations
303305 */
304306 private function compareAffiliations ($ userAffiliations , $ allowedAffiliations ): bool
@@ -307,6 +309,7 @@ private function compareAffiliations($userAffiliations, $allowedAffiliations): b
307309 if (! empty ($ result )) {
308310 return true ;
309311 }
312+
310313 return false ;
311314 }
312315}
0 commit comments