According to the Law of Demeter, can you call methods on returned objects?
E.g.
<?php
class O
{
public function m($http)
{
$response = $http->get('http://www.google.com');
return $response->getBody(); // violation?
}
}
?>
$http->get() returns an object. Does this count as an object created/instantiated within M? If you can not call methods on it (according to LoD), how would you handle this situation?
This is not a violation of the Law of Demeter, given:
Since $response is an object that is created within M, you can invoke a method upon that object without violation. However, it would be a violation to access properties beyond
getBody():Sometimes you can say that the law can be simplified by saying it’s the “one dot” rule, meaning that you can access one property or method deep.