Skip to content

Commit

Permalink
Added check for number of paramters
Browse files Browse the repository at this point in the history
  • Loading branch information
iwalz committed Jan 5, 2013
1 parent f642ecf commit c83ce7f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions library/Zend/Stdlib/Hydrator/ClassMethods.php
Expand Up @@ -64,6 +64,11 @@ public function extract($object)
continue;
}

$reflectionMethod = new \ReflectionMethod(get_class($object) . '::' . $method);

This comment has been minimized.

Copy link
@iwalz

iwalz Jan 5, 2013

Author 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);
Expand Down
13 changes: 13 additions & 0 deletions tests/ZendTest/Stdlib/HydratorTest.php
Expand Up @@ -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;

/**
Expand All @@ -41,6 +42,11 @@ class HydratorTest extends \PHPUnit_Framework_TestCase
*/
protected $classMethodsUnderscore;

/**
* @var ClassMethodsInvalidParameter
*/
protected $classMethodsInvalidParameter;

/**
* @var ReflectionAsset
*/
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}
}
18 changes: 18 additions & 0 deletions tests/ZendTest/Stdlib/TestAsset/ClassMethodsInvalidParameter.php
@@ -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.