From 9b94ae4b2caba6fc49cdc7b672831ffe57c84620 Mon Sep 17 00:00:00 2001 From: Evan Villemez Date: Fri, 24 Aug 2012 11:12:36 -0400 Subject: [PATCH] fixed cs --- Parser/JmsMetadataParser.php | 30 ++++++++++++++++-------------- Tests/Fixtures/Model/JmsNested.php | 2 +- Tests/Fixtures/Model/JmsTest.php | 4 ++-- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Parser/JmsMetadataParser.php b/Parser/JmsMetadataParser.php index ced2ac0..b7e57d9 100644 --- a/Parser/JmsMetadataParser.php +++ b/Parser/JmsMetadataParser.php @@ -67,7 +67,7 @@ class JmsMetadataParser implements ParserInterface 'description' => $this->getDescription($input, $item->name), 'readonly' => $item->readOnly ); - + //check for nested classes w/ JMS metadata if ($nestedInputClass = $this->getNestedClass($item->type)) { $params[$name]['children'] = $this->parse($nestedInputClass); @@ -77,12 +77,12 @@ class JmsMetadataParser implements ParserInterface return $params; } - + /** * There are various ways via JMS to declare arrays of objects, but that's an internal * implementation detail. * - * @param string $type + * @param string $type * @return string */ protected function getNormalizedType($type) @@ -90,25 +90,27 @@ class JmsMetadataParser implements ParserInterface if (in_array($type, array('boolean', 'integer', 'string', 'double', 'array', 'DateTime'))) { return $type; } - - if(false !== strpos($type, "array") || false !== strpos($type, "ArrayCollection")) { + + if (false !== strpos($type, "array") || false !== strpos($type, "ArrayCollection")) { if ($nested = $this->getNestedClassInArray($type)) { $exp = explode("\\", $nested); + return sprintf("array of objects (%s)", end($exp)); } else { return "array"; } } - + $exp = explode("\\", $type); + return sprintf("object (%s)", end($exp)); } - + /** * Check the various ways JMS describes custom classes in arrays, and * get the name of the class in the array, if available. * - * @param string $type + * @param string $type * @return string|false */ protected function getNestedClassInArray($type) @@ -118,18 +120,19 @@ class JmsMetadataParser implements ParserInterface $regEx = "/\<([A-Za-z0-9\\\]*)(\,?\s?(.*))?\>/"; if (preg_match($regEx, $type, $matches)) { $matched = (!empty($matches[3])) ? $matches[3] : $matches[1]; + return in_array($matched, array('boolean', 'integer', 'string', 'double', 'array', 'DateTime')) ? false : $matched; } - + return false; } - + /** * Scan the JMS Serializer types for reference to a class. * * http://jmsyst.com/bundles/JMSSerializerBundle/master/reference/annotations#type * - * @param string $type + * @param string $type * @return string|false */ protected function getNestedClass($type) @@ -137,12 +140,12 @@ class JmsMetadataParser implements ParserInterface if (in_array($type, array('boolean', 'integer', 'string', 'double', 'array', 'DateTime'))) { return false; } - + //could be a nested object of some sort if ($nested = $this->getNestedClassInArray($type)) { return $nested; } - + //or could just be a class name (potentially) return (null === $this->factory->getMetadataForClass($type)) ? false : $type; } @@ -152,7 +155,6 @@ class JmsMetadataParser implements ParserInterface $description = "No description."; //TODO: abstract docblock parsing utility and implement here - return $description; } diff --git a/Tests/Fixtures/Model/JmsNested.php b/Tests/Fixtures/Model/JmsNested.php index 86ba05c..3a29503 100644 --- a/Tests/Fixtures/Model/JmsNested.php +++ b/Tests/Fixtures/Model/JmsNested.php @@ -16,5 +16,5 @@ class JmsNested * @JMS\Type("string"); */ public $bar; - + } diff --git a/Tests/Fixtures/Model/JmsTest.php b/Tests/Fixtures/Model/JmsTest.php index b1968ff..d47741c 100644 --- a/Tests/Fixtures/Model/JmsTest.php +++ b/Tests/Fixtures/Model/JmsTest.php @@ -29,12 +29,12 @@ class JmsTest * @JMS\Type("array"); */ public $arr; - + /** * @JMS\Type("Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsNested"); */ public $nested; - + /** * @JMS\Type("array"); */