From a96bdbdd62c2f1eeb5a7aec142733f021c804c84 Mon Sep 17 00:00:00 2001 From: woutse Date: Fri, 28 Feb 2025 10:13:56 +0100 Subject: [PATCH 1/2] Hydrator fix --- src/Validator/Factory.php | 2 +- src/Validator/RequiredMembers.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Validator/Factory.php b/src/Validator/Factory.php index 4c0d6f6..d0a92aa 100644 --- a/src/Validator/Factory.php +++ b/src/Validator/Factory.php @@ -6,7 +6,7 @@ use PayNL\Sdk\Common\FactoryInterface; use Psr\Container\ContainerInterface; -use PayNL\Sdk\Hydrator\HydratorAwareInterface; +use PayNL\Sdk\Packages\Laminas\Hydrator\HydratorAwareInterface; /** * Class Factory diff --git a/src/Validator/RequiredMembers.php b/src/Validator/RequiredMembers.php index 862dc99..1743d20 100644 --- a/src/Validator/RequiredMembers.php +++ b/src/Validator/RequiredMembers.php @@ -7,8 +7,8 @@ use PayNL\Sdk\Exception\InvalidArgumentException; use PayNL\Sdk\Exception\RuntimeException; use ReflectionClass, ReflectionException; -use PayNL\Sdk\Hydrator\HydratorAwareInterface; -use PayNL\Sdk\Hydrator\HydratorAwareTrait; +use PayNL\Sdk\Packages\Laminas\Hydrator\HydratorAwareInterface; +use PayNL\Sdk\Packages\Laminas\Hydrator\HydratorAwareTrait; /** * Class RequiredMembers From 41953b73a9d811a7a2eff14788c4cc327dff96c7 Mon Sep 17 00:00:00 2001 From: woutse Date: Fri, 28 Feb 2025 11:27:15 +0100 Subject: [PATCH 2/2] Code polish --- src/Validator/Factory.php | 7 +++++-- src/Validator/RequiredMembers.php | 20 ++++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Validator/Factory.php b/src/Validator/Factory.php index d0a92aa..76cad7a 100644 --- a/src/Validator/Factory.php +++ b/src/Validator/Factory.php @@ -16,9 +16,12 @@ class Factory implements FactoryInterface { /** - * @inheritDoc - * + * @param ContainerInterface $container + * @param string $requestedName + * @param array|null $options * @return ValidatorInterface + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ public function __invoke(ContainerInterface $container, string $requestedName, array $options = null): ValidatorInterface { diff --git a/src/Validator/RequiredMembers.php b/src/Validator/RequiredMembers.php index 1743d20..8ebce09 100644 --- a/src/Validator/RequiredMembers.php +++ b/src/Validator/RequiredMembers.php @@ -6,7 +6,9 @@ use PayNL\Sdk\Exception\InvalidArgumentException; use PayNL\Sdk\Exception\RuntimeException; -use ReflectionClass, ReflectionException; +use ReflectionClass, + +ReflectionException; use PayNL\Sdk\Packages\Laminas\Hydrator\HydratorAwareInterface; use PayNL\Sdk\Packages\Laminas\Hydrator\HydratorAwareTrait; @@ -38,9 +40,10 @@ class RequiredMembers extends AbstractValidator implements HydratorAwareInterfac ]; /** - * @inheritDoc + * @param mixed $filledObjectToCheck + * @return boolean */ - public function isValid($filledObjectToCheck): bool + public function isValid(mixed $filledObjectToCheck): bool { $className = get_class($filledObjectToCheck); $required = $this->getRequiredMembers($className); @@ -101,7 +104,8 @@ protected function getRequiredMembers(string $className): array foreach ($ref->getProperties() as $property) { $docComment = $property->getDocComment(); - if (false !== $docComment + if ( + false !== $docComment && false !== preg_match_all("/@(?P\S+)(?:\n|\s(?P.+)\n)/s", $docComment, $annotations) && true === in_array('required', $annotations['tag'], true) ) { @@ -120,7 +124,7 @@ protected function getRequiredMembers(string $className): array * * @return array */ - private function getDataFromObject($objectToExtract): array + private function getDataFromObject(mixed $objectToExtract): array { $hydrator = $this->getHydrator(); if (null === $hydrator) { @@ -149,12 +153,12 @@ private function getDataFromObject($objectToExtract): array * Checks if the given $value is empty. In other words, its an empty string, null or * (if the key is an id field) equal to zero (0). * - * @param string|int $key + * @param string|integer $key * @param mixed $value * - * @return bool + * @return boolean */ - private function isEmpty($key, $value): bool + private function isEmpty(string $key, mixed $value): bool { return null === $value || '' === $value