DEV Community

Discussion on: Improve your factories in Symfony

Collapse
 
dziugasdraksas profile image
DziugasDraksas

I would suggest minor optimization.
Do not create new $channel, since all channels are already initialized.
Just return it:

foreach($this->channels as $channel) {
    if ($type === $channel::getType()) {
        return $channel;
     }
}
Enter fullscreen mode Exit fullscreen mode