From a2f4b2b685182d452867b06aaba48842b007faea Mon Sep 17 00:00:00 2001 From: Netkas Date: Wed, 21 Jun 2023 15:46:28 -0400 Subject: [PATCH] Added method \FederationLib\Classes > Validate > associationType() Refactored \FederationLib\Classes > Validate --- src/FederationLib/Classes/Validate.php | 37 +++++++++++++++++--------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/FederationLib/Classes/Validate.php b/src/FederationLib/Classes/Validate.php index 4252669..497a924 100644 --- a/src/FederationLib/Classes/Validate.php +++ b/src/FederationLib/Classes/Validate.php @@ -5,7 +5,6 @@ use FederationLib\Enums\Standard\PeerType; use FederationLib\Enums\Standard\InternetPeerType; use FederationLib\Enums\Standard\PeerAssociationType; - use FederationLib\Enums\Standard\PermissionRole; use FederationLib\Enums\Standard\UserPeerType; use FederationLib\Exceptions\Standard\InvalidPeerMetadataException; @@ -40,10 +39,7 @@ */ public static function validateEntityType(string $entity_type): bool { - if(self::getEntityType($entity_type) === PeerType::UNKNOWN) - return false; - - return true; + return self::getEntityType($entity_type) !== PeerType::UNKNOWN; } /** @@ -54,8 +50,10 @@ */ public static function peerAssociationType(string $type): bool { - if(in_array(strtolower($type), PeerAssociationType::ALL)) + if (in_array(strtolower($type), PeerAssociationType::ALL)) + { return true; + } return false; } @@ -112,28 +110,43 @@ * @return void * @throws InvalidPeerMetadataException */ - public static function validateMetadata(array $data, array $required, array $optional): void + public static function metadata(array $data, array $required, array $optional): void { - foreach ($required as $property => $type) + foreach($required as $property => $type) { - if (!isset($data[$property])) + if(!isset($data[$property])) { throw new InvalidPeerMetadataException(sprintf('The property "%s" is required in the metadata', $property)); } - if (gettype($data[$property]) !== $type) + if(gettype($data[$property]) !== $type) { throw new InvalidPeerMetadataException(sprintf('The property "%s" must be a %s in metadata, got %s', $property, $type, Security::gettype($data[$property]))); } } - foreach ($optional as $property => $type) + foreach($optional as $property => $type) { - if (isset($data[$property]) && gettype($data[$property]) !== $type) + if(isset($data[$property]) && gettype($data[$property]) !== $type) { throw new InvalidPeerMetadataException(sprintf('The property "%s" must be a %s in metadata, got %s', $property, $type, Security::gettype($data[$property]))); } } } + /** + * Validates if the given association type is valid. + * + * @param string $type + * @return bool + */ + public static function associationType(string $type): bool + { + if(in_array($type, PeerAssociationType::ALL)) + { + return true; + } + + return false; + } } \ No newline at end of file