Force developers to use the correct method to set props to entities

This commit is contained in:
Leo Germani 2018-04-30 10:36:31 -03:00
parent e778fc5532
commit fc1daab3dd
2 changed files with 22 additions and 2 deletions

View File

@ -150,13 +150,33 @@ class Entity {
/**
* set the value of a mapped property
*
* This is a protected method. If you want to set an entity prop
* using the prop name dynamically, use the set() method
*
* @param string $prop id of the property
* @param mixed $value the value to be setted
*/
public function set_mapped_property($prop, $value) {
protected function set_mapped_property($prop, $value) {
$this->set_validated(false);
$this->$prop = $value;
}
/**
* set the value property
*
*
* @param string $prop id of the property
* @param mixed $value the value to be setted
* @return null|mixed Null on failure, the value that was set on success
*/
public function set($prop, $value) {
$method = 'set_' . $prop;
if ( method_exists($this, $method) ) {
return $this->$method($value);
}
return null;
}
/**
* set the status of the entity

View File

@ -145,7 +145,7 @@ class Collections extends TAINACAN_UnitTestCase {
$autor1_id,
];
$collection_test->set_moderators_ids($moderators_ids);
$collection_test->set('moderators_ids', $moderators_ids);
$this->assertEquals(2, sizeof( $collection_test->get_moderators_ids() ));