From 9f16d2b51f3816f4c41608de1ca92ee74489d685 Mon Sep 17 00:00:00 2001 From: Emily Shepherd Date: Sat, 11 Mar 2017 01:52:38 +0000 Subject: [PATCH 1/3] Fix native type parsing with context --- src/Factory/Reflection/ReflectionMethodFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Factory/Reflection/ReflectionMethodFactory.php b/src/Factory/Reflection/ReflectionMethodFactory.php index 403e86c..79e1eca 100644 --- a/src/Factory/Reflection/ReflectionMethodFactory.php +++ b/src/Factory/Reflection/ReflectionMethodFactory.php @@ -182,7 +182,7 @@ protected function addParameter { $parameter = new ReflectionParameter(); $accessor = new RawPropertyAccessor($parameter); - $type = $this->typeParser->parse((string)$reflect->getType()); + $type = (new TypeParser())->parse((string)$reflect->getType()); $this->parameters['$' . $reflect->getName()] = $accessor; $this->accessor->rawAddToValue('parameters', $parameter); From e5288dd6235f5921fa5ec1367399647bc60860ac Mon Sep 17 00:00:00 2001 From: Emily Shepherd Date: Sat, 11 Mar 2017 01:53:02 +0000 Subject: [PATCH 2/3] Don't auto construct properties with 'new' not set --- src/Service/PropertyAccessor.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Service/PropertyAccessor.php b/src/Service/PropertyAccessor.php index a637f64..813b632 100644 --- a/src/Service/PropertyAccessor.php +++ b/src/Service/PropertyAccessor.php @@ -112,14 +112,14 @@ public function constructObject(...$args) */ protected function buildProperty(ReflectionProperty $property) { - if ($property->type instanceof ObjectType) + if (!$property->type instanceof ObjectType) { - $class = $property->type->classname; - $this->setRawValue($property->name, new $class()); + $this->setAnyValue($property, 0); } - else + elseif ($property->builtInConstructor) { - $this->setAnyValue($property, 0); + $class = $property->type->classname; + $this->setRawValue($property->name, new $class()); } } From 251fe6743a8ca0c23582746bbf788a31ae9d8e18 Mon Sep 17 00:00:00 2001 From: Emily Shepherd Date: Sat, 11 Mar 2017 01:53:25 +0000 Subject: [PATCH 3/3] Update exception messages --- src/Factory/Reflection/ReflectionMethodFactory.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Factory/Reflection/ReflectionMethodFactory.php b/src/Factory/Reflection/ReflectionMethodFactory.php index 79e1eca..0f845a1 100644 --- a/src/Factory/Reflection/ReflectionMethodFactory.php +++ b/src/Factory/Reflection/ReflectionMethodFactory.php @@ -152,7 +152,11 @@ protected function addParamAnnotation($name, $value) : void if (!$this->parameters->containsKey($param)) { - throw new \Exception(); + throw new \Exception + ( + 'Tried to set param annotation for non existant ' + . 'parameter: ' . $param + ); } $comparator = new TypeComparator(); @@ -162,7 +166,7 @@ protected function addParamAnnotation($name, $value) : void if (!$comparator->compatible($nativeType, $type)) { - throw new \Exception(); + throw new \Exception('Types are incompatible'); } $param->setRawValue('type', $type);