Permalink
Browse files

Added check for number of paramters

  • Loading branch information...
1 parent f642ecf commit c83ce7f2c804a7f6daedbe97fd6eefba3d151bf3 @iwalz committed Jan 5, 2013
@@ -64,6 +64,11 @@ public function extract($object)
continue;
}
+ $reflectionMethod = new \ReflectionMethod(get_class($object) . '::' . $method);
@iwalz

iwalz Jan 5, 2013

Owner

Since we have the reflection, we can use it on line 81 that way:

$attributes[$attribute] = $this->extractValue($attribute, $reflectionMethod->invoke($object));

But I'm not sure about a performance impact/improvement/matter here.

+ if ($reflectionMethod->getNumberOfParameters() > 0) {
+ continue;
+ }
+
$attribute = $method;
if (preg_match('/^get/', $method)) {
$attribute = substr($method, 3);
@@ -15,6 +15,7 @@
use ZendTest\Stdlib\TestAsset\ClassMethodsCamelCase;
use ZendTest\Stdlib\TestAsset\ClassMethodsUnderscore;
use ZendTest\Stdlib\TestAsset\ClassMethodsCamelCaseMissing;
+use ZendTest\Stdlib\TestAsset\ClassMethodsInvalidParameter;
use ZendTest\Stdlib\TestAsset\Reflection as ReflectionAsset;
/**
@@ -42,6 +43,11 @@ class HydratorTest extends \PHPUnit_Framework_TestCase
protected $classMethodsUnderscore;
/**
+ * @var ClassMethodsInvalidParameter
+ */
+ protected $classMethodsInvalidParameter;
+
+ /**
* @var ReflectionAsset
*/
protected $reflection;
@@ -51,6 +57,7 @@ public function setUp()
$this->classMethodsCamelCase = new ClassMethodsCamelCase();
$this->classMethodsCamelCaseMissing = new ClassMethodsCamelCaseMissing();
$this->classMethodsUnderscore = new ClassMethodsUnderscore();
+ $this->classMethodsInvalidParameter = new ClassMethodsInvalidParameter();
$this->reflection = new ReflectionAsset;
}
@@ -203,4 +210,10 @@ public function testHydratorClassMethodsCamelCaseWithSetterMissing()
$this->assertEquals($test->getFooBar(), 'foo');
$this->assertEquals($test->getFooBarBaz(), '2');
}
+
+ public function testHydratorClassMethodsWithServiceManager()
+ {
+ $hydrator = new ClassMethods(false);
+ $datas = $hydrator->extract($this->classMethodsInvalidParameter);
+ }
}
@@ -0,0 +1,18 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Stdlib
+ */
+namespace ZendTest\Stdlib\TestAsset;
+
+class ClassMethodsInvalidParameter
+{
+ public function hasAlias($alias)
+ {
+ return $alias;
+ }
+}

0 comments on commit c83ce7f

Please sign in to comment.