Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

[BC] Remove need of setter in ClassMethods hydrator #2426

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 0 additions & 7 deletions library/Zend/Stdlib/Hydrator/ClassMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,11 @@ public function extract($object)
continue;
}
if (preg_match('/^get/', $method)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simplify :

$attribute = $method;
if (preg_match('/^get/', $method)) {
$attribute = substr($attribute, 3);
$attribute = lcfirst($attribute);
}

And remove the "else"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, done.

// setter verification
$setter = preg_replace('/^get/', 'set', $method);
$attribute = substr($method, 3);
$attribute = lcfirst($attribute);
} else {
// setter verification
$setter = 'set' . ucfirst($method);
$attribute = $method;
}
if (!in_array($setter, $methods)) {
continue;
}
if ($this->underscoreSeparatedKeys) {
$attribute = preg_replace_callback('/([A-Z])/', $transform, $attribute);
}
Expand Down
14 changes: 0 additions & 14 deletions tests/ZendTest/Stdlib/HydratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,6 @@ public function testHydratorClassMethodsCamelCase()
$this->assertEquals($test->hasBar(), false);
}

public function testHydratorClassMethodsCamelCaseWithSetterMissing()
{
$hydrator = new ClassMethods(false);
$datas = $hydrator->extract($this->classMethodsCamelCaseMissing);
$this->assertTrue(isset($datas['fooBar']));
$this->assertEquals($datas['fooBar'], '1');
$this->assertFalse(isset($datas['fooBarBaz']));
$this->assertFalse(isset($datas['foo_bar']));
$test = $hydrator->hydrate(array('fooBar' => 'foo'), $this->classMethodsCamelCaseMissing);
$this->assertSame($this->classMethodsCamelCaseMissing, $test);
$this->assertEquals($test->getFooBar(), 'foo');
$this->assertEquals($test->getFooBarBaz(), '2');
}

public function testHydratorClassMethodsUnderscore()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should to update the test instead of removing no ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not really understand it to be honest. I can't understand the use case nor the test, so I can't really update it :/.

{
$hydrator = new ClassMethods(true);
Expand Down