I've got a class that is a facade class (encapsulates complex-ish behaviour for reusability). It has a function called manage
(the class is called Manager):
function manage()
{
$entityBuilder = 'Some builder';
$someData = 'Some data';
foreach ($someData as $someDatum) {
if (!$entityBuilder->doesNeedBuilding($someDatum)) {
continue;
}
if (!$entityBuilder->canBuild($someDatum)) {
continue;
}
try {
$entityBuilder->build($someDatum);
} catch (Exception $e) {
}
}
}
I would like to log the result to another table something like this:
function manage()
{
$entityBuilder = 'Some builder';
$someData = 'Some data';
foreach ($someData as $someDatum) {
if (!$entityBuilder->doesNeedBuilding($someDatum)) {
// Log status 'Skipped'.
continue;
}
if (!$entityBuilder->canBuild($someDatum)) {
// Log status 'Failed'.
continue;
}
try {
$entityBuilder->build($someDatum);
// Log status 'Success'.
} catch (Exception $e) {
// Log status 'Failed'.
}
}
}
But of course it convolutes the function; and even it has a very vague name, logging clearly breaks SRP.
I usually use decorators for these kinds of stuff, but since this is a facade and since it encapsulates a number of steps, I can't simply use a decorator here.
I also thought about returning a list of statuses for each operation and then log somewhere else, but it also is some sort of convolution.
Are there any good architects around that can guide me on solving this one?