samedi 11 novembre 2017

Prevent repeating yourself for repeating code

There is a piece of code that keeps coming back:

foreach ($this->apiDestination->getLanguagesFromCache() as $language) {
    for ($page = 1; $page >= $this->apiSource->calculatePages( 'products' ); $page++) {

Not only with $this->apiDestination but also with other items. I think that i've written this more then 200 times... Is there some way to optimize this and call it in a closure or something? Something like:

$this->handle($pages = 1, $languages = array(), function(){
    //Do my stuff while it is iterating
});

Thanks!



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2yRetsf
via IFTTT

Aucun commentaire:

Enregistrer un commentaire