Hello!
It is just a suggestion to be discussed.
A lot of places on my projects I have codes like:
$companies = $user->companies->count()
? new Collection($user->companies)
: null;
So $companies will be null except if the user has companies.
My suggestion is create some kind of inline conditional to works like that:
$companies = $user->companies->count() => new Collection($user->companies);
If the conditional ($user->companies->count()) is true, then will return
the value (after =>), else will be null.
In my current work project, I have more than 100+ occurrences like that.
So some more examples:
$userCategory ? $userCategory->getTitle() : null
-> It could be optimized to the new nullsafe operator
$userCategory?->getTitle()
return $languageFirst instanceof LanguageExperience
? $languageFirst->title : null;
-> This not, with my suggestion we have:
return $languageFirst instanceof LanguageExperience =>
$languageFirst->title;
The => is just a suggestion, other options using existing keywords is:
return expr() then output();
return expr(): output();
I do not know if other languages support something like that.
Thanks!
Atenciosamente,
David Rodrigues