I'm currently developing an SaaS application in PHP, with Laravel, using its own DB class.

Let's pretend we've got 2 classes under 2 namespaces, plus Laravel's own DB - so


They're our 3 classes.

With our custom classes, we've got File 1: Developer\App\Core\Queries\Section.php

which contains

private function fetchInfoFromTable(string $id) 
    //Pretend there is a bit to check if we've already run the query
    return DB::Query('blablabla');

File 2: Developer\App\Section\XXXXX.php

private function showInfo()
       $data = Section::fetchInfoFromTable(1);
       $data = dostufftomakeitnice($data);
       $data = doMorestufftomakeitnice($data);
       return $data;

Is this worth the amount of effort I've put into typing this question? Or is it worth just putting even the queries into XXXXX.php?


I think it is worth it. I learned that keeping things simple and having shorter functions reduces exponentially the risk of having bugs and also makes it easier to track issues down.

I'd say keep it, as is. I looked at your code and it looks clean.

Nothing wrong with functions that one one line bodies. That's abstraction and it is a good thing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.