44
55namespace SimpleSAML \OpenID \Federation \EntityCollection ;
66
7- use SimpleSAML \OpenID \Codebooks \ClaimsEnum ;
87use SimpleSAML \OpenID \Exceptions \OpenIdException ;
98use SimpleSAML \OpenID \Helpers ;
109
@@ -17,16 +16,16 @@ public function __construct(
1716
1817
1918 /**
20- * Sort entities by one or more claims nested inside their metadata .
19+ * Sort entities by one or more claims nested inside their payload .
2120 *
2221 * @param array<string, array<string, mixed>> $entities Keyed by entity ID
2322 * @param non-empty-array<int, non-empty-string[]> $claimPaths Array of
24- * nested claim paths within the metadata object
25- * (e.g. [['openid_provider', 'display_name'], ['federation_entity', 'display_name']])
23+ * nested claim paths within the entity payload object
24+ * (e.g. [['metadata', ' openid_provider', 'display_name'], ['metadata', 'federation_entity', 'display_name']])
2625 * @param 'asc'|'desc' $direction
2726 * @return array<string, array<string, mixed>> Sorted copy
2827 */
29- public function sortByMetadataClaims (
28+ public function sort (
3029 array $ entities ,
3130 array $ claimPaths ,
3231 string $ direction = 'asc ' ,
@@ -36,21 +35,15 @@ public function sortByMetadataClaims(
3635 }
3736
3837 uasort ($ entities , function (array $ a , array $ b ) use ($ claimPaths , $ direction ): int {
39- $ metadataA = $ a [ClaimsEnum::Metadata->value ] ?? [];
40- $ metadataA = is_array ($ metadataA ) ? $ metadataA : [];
41-
42- $ metadataB = $ b [ClaimsEnum::Metadata->value ] ?? [];
43- $ metadataB = is_array ($ metadataB ) ? $ metadataB : [];
44-
4538 foreach ($ claimPaths as $ claimPath ) {
4639 try {
47- $ valA = $ this ->helpers ->arr ()->getNestedValue ($ metadataA , ...$ claimPath );
40+ $ valA = $ this ->helpers ->arr ()->getNestedValue ($ a , ...$ claimPath );
4841 } catch (OpenIdException $ e ) {
4942 // If the claim path doesn't exist, treat it as null
5043 $ valA = null ;
5144 }
5245 try {
53- $ valB = $ this ->helpers ->arr ()->getNestedValue ($ metadataB , ...$ claimPath );
46+ $ valB = $ this ->helpers ->arr ()->getNestedValue ($ b , ...$ claimPath );
5447 } catch (OpenIdException $ e ) {
5548 // If the claim path doesn't exist, treat it as null
5649 $ valB = null ;
0 commit comments