But if you follow this to the logical extreme and parameterize $prop, you end up with what are essentially static functions
Yes that was what I was getting at about being independent from the object.
I'd stick with Bar, and only refactor into a parameter if it's direly necessary for some unit testing gymnastics.
Because of the less duplication thing right?
I think there are separate reasons to use parameters/locals and properties/globals
But here they seem to do the same. What would you say those reasons are?
The example you gave doesn't say much about what is going on in _a and _b
This is the code in question. Out of context its pretty confusing to look at but as you can see _headerWithoutNotifications() makes lots of _get*($ent) calls
Code: Select all
private function _headerWithoutNotifications()
{
$ent = $this->_entity; // look: the origin of $ent
$attr = array('id' => $ent->id);
if ($ent->isMaster) {
if ($ent->visible) {
return $this->_tagPart('form', 1, $this->_getFormAttr($ent)) // lots
. $this->_tagPart('fieldset', 1, $this->_getFieldSetAttr($ent)) // of
. $this->_getLegend($ent->attributes->label, $ent->accessKey); // calls
}
return $this->_tagPart('form', 1, $this->_getFormAttr($ent)); // and here
}
if ($ent->visible) {
return $this->_tagPart('fieldset', 1, $this->_getFieldSetAttr($ent)) // and here
. $this->_getLegend($ent->attributes->label, $ent->accessKey);
}
return $this->_tagPart('div', 1, $this->_getDivAttr($ent));
}
private function _getFormAttr($ent) // by using this parameter I have avoided...
{
// this line:
// $ent = $this->_entity;
$out = array('id' => $ent->id,
'action' => $ent->action,
'method' => $ent->method,
'accept-charset' => OF::$enc->getName());
if ($ent->visible) {
return $out + $ent->attributes->js->get() + $ent->attributes->custom;
}
$out['title'] = $ent->attributes->tooltip;
return $out;
}
private function _getDivAttr($ent)
{
// same here
return array('id' => $ent->id,
'title' => $ent->attributes->tooltip);
}
private function _getFieldSetAttr($ent)
{
// and here
$out = array('class' => $ent->attributes->class->get(),
'style' => $ent->attributes->css->get(),
'title' => $ent->attributes->tooltip);
if ($ent->isMaster) {
return $out;
}
return $out + array('id' => $ent->id) + $ent->attributes->js->get() + $ent->attributes->custom;
}