runForMultiple
unexpected-ish behaviour with empty array
#1267
Labels
feature
New feature or request
runForMultiple
unexpected-ish behaviour with empty array
#1267
Description
Not strictly a bug nor a feature, but I'd like to bring some attention to the following situation:
\Stancl\Tenancy\Tenancy::runForMultiple
runs the given callback for all tenants if$tenants
is an empty array. It makes sense that this is the behaviour fornull
, but I'd like to make a case for why this is not the expected behaviour with an empty array. Imagine you have some code that gathers some "candidate" items and then loops over them.I wouldn't expect all potential candidates to have the code in the foreach block executed on if the candidates array is empty after the "gathering" phase -- it doesn't follow naturally that I need to see if the candidates array contains any items first before I move on to the foreach loop. You can see where I'm going with this:
I'd argue there's a small likelihood of this causing very serious bugs. If the developer intends to run the callback for all tenants, they can use
null
for the$tenants
argument explicitly.Updating this behaviour would obviously be a breaking change, but it seems worthwhile to look into this.
The text was updated successfully, but these errors were encountered: