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’m having problems understanding how File 1 would be more than a couple lines, are you trying the cache query results?
    – Shane Hsu
    Aug 10, 2019 at 10:32
  • Also Database Abstraction Layer is a very specific abstraction method where queries are made database-agnostic. en.m.wikipedia.org/wiki/Database_abstraction_layer If this is not what you mean, please consider editing you title to more precisely describe what you want to achieve.
    – Shane Hsu
    Aug 10, 2019 at 10:37

1 Answer 1


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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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