If a method that takes no parameters, gets some data from a database, and then sets it as a property within the class.
Is that method considered a getter, setter, both, neither or is it doing too much?
If a method that takes no parameters, gets some data from a database, and then sets it as a property within the class.
Is that method considered a getter, setter, both, neither or is it doing too much?
You current method is not a getter
. Because it doesn't return data from the object.
And it contains a setter
that you should extract as a real setData()
method.
You should indeed split it in 2 methods:
function retrieveData() {
// get data from the database
return $data;
}
function setData($data);
$this->data = $data;
}
function yourCurrentMethod() {
$data = $this->retrieveData();
$this->setData($data);
}