diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 3170dc3..6336d8e 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -51,3 +51,5 @@ e85fae4f7290329ac9cfae159e19c1bb55062e4b c400a3c655b1157b8ff30f5c2ead30563fad972a 13d4e52a568b9263cefd6830a1759c7c2a2f0ea3 9ceb35f77a0bfefe8bf4b51d5026399f12ad79b0 +8614c245e767ac74c2ca65697553b70bf54394ad +e7d3e86c6e045f09131ec7cdb3e2cf0887e7eb21 diff --git a/src/Objects/Once.php b/src/Objects/Once.php index 82d46a6..3eeb94b 100644 --- a/src/Objects/Once.php +++ b/src/Objects/Once.php @@ -1,12 +1,21 @@ output)) { $this->output = $input; diff --git a/src/Objects/Serializers/Attributes/MapOutputName.php b/src/Objects/Serializers/Attributes/MapOutputName.php index 14bdce9..9748f1d 100644 --- a/src/Objects/Serializers/Attributes/MapOutputName.php +++ b/src/Objects/Serializers/Attributes/MapOutputName.php @@ -1,4 +1,5 @@ getAttributes(MapName::class)) || - !empty($reflection->getAttributes(MapInputName::class)) || - !empty($reflection->getAttributes(MapOutputName::class))) { + if ($reflection->getAttributes(MapName::class) !== [] || + $reflection->getAttributes(MapInputName::class) !== [] || + $reflection->getAttributes(MapOutputName::class) !== []) { return true; } - foreach ($reflection->getProperties() as $property) { - if (!empty($property->getAttributes(MapName::class)) || - !empty($property->getAttributes(MapInputName::class)) || - !empty($property->getAttributes(MapOutputName::class))) { + foreach ($reflection->getProperties() as $reflectionProperty) { + if (!empty($reflectionProperty->getAttributes(MapName::class)) || + !empty($reflectionProperty->getAttributes(MapInputName::class)) || + !empty($reflectionProperty->getAttributes(MapOutputName::class))) { return true; } } @@ -81,25 +83,25 @@ private static function serializeWithMapName(object $object): string $reflection = new ReflectionClass($object); $data = []; - foreach ($reflection->getProperties() as $property) { - $property->setAccessible(true); - $propertyName = $property->getName(); - $value = $property->getValue($object); + foreach ($reflection->getProperties() as $reflectionProperty) { + $reflectionProperty->setAccessible(true); + $propertyName = $reflectionProperty->getName(); + $value = $reflectionProperty->getValue($object); - $mappedName = self::getMappedOutputName($property, $reflection) ?? $propertyName; + $mappedName = self::getMappedOutputName($reflectionProperty, $reflection) ?? $propertyName; $data[$mappedName] = $value; } $json = json_encode($data); if ($json === false) { - throw new RuntimeException('Failed to encode JSON'); + throw new RuntimeException("Failed to encode JSON"); } return $json; } /** - * @param class-string $class + * @param class-string $class */ private static function deserializeWithMapName(string $class, string $jsonData): mixed { @@ -112,14 +114,14 @@ private static function deserializeWithMapName(string $class, string $jsonData): } $args = []; - foreach ($constructor->getParameters() as $parameter) { - $args[] = self::resolveParameterValue($parameter, $reflection, $data); + foreach ($constructor->getParameters() as $reflectionParameter) { + $args[] = self::resolveParameterValue($reflectionParameter, $reflection, $data); } return $reflection->newInstanceArgs($args); } - private static function resolveParameterValue(\ReflectionParameter $parameter, ReflectionClass $reflection, array $data): mixed + private static function resolveParameterValue(ReflectionParameter $parameter, ReflectionClass $reflection, array $data): mixed { $parameterName = $parameter->getName(); $property = $reflection->hasProperty($parameterName) ? $reflection->getProperty($parameterName) : null; @@ -154,11 +156,12 @@ private static function getMapperResult(string|IPropertyMapper $mapper, string $ { if (is_string($mapper)) { if (class_exists($mapper)) { - $mapperInstance = new $mapper(); + $mapperInstance = new $mapper; if ($mapperInstance instanceof IPropertyMapper) { return $mapperInstance->map($propertyName); } } + return $mapper; } @@ -170,12 +173,12 @@ private static function getMapperForDirection(ReflectionProperty|ReflectionClass $specificAttributeClass = $direction === self::MAPPER_DIRECTION_INPUT ? MapInputName::class : MapOutputName::class; $specificAttributes = $reflector->getAttributes($specificAttributeClass); - if (!empty($specificAttributes)) { + if ($specificAttributes !== []) { return self::getMapperResult($specificAttributes[0]->newInstance()->mapper, $propertyName); } $mapNameAttributes = $reflector->getAttributes(MapName::class); - if (!empty($mapNameAttributes)) { + if ($mapNameAttributes !== []) { $mapNameInstance = $mapNameAttributes[0]->newInstance(); $mapper = $direction === self::MAPPER_DIRECTION_OUTPUT ? ($mapNameInstance->output ?? $mapNameInstance->input) diff --git a/src/Objects/Serializers/Mappers/CamelCaseMapper.php b/src/Objects/Serializers/Mappers/CamelCaseMapper.php index 01abc95..22848db 100644 --- a/src/Objects/Serializers/Mappers/CamelCaseMapper.php +++ b/src/Objects/Serializers/Mappers/CamelCaseMapper.php @@ -1,4 +1,5 @@