There are multiple places in the code base where the database object is not cached as a variable for re-use. As a result, the code is not DRY and developers may be initially confused by inconsistency when they expect to see $db->quoteName() but $query->quoteName() is written. There are some occurrences where $this->getDbo() is called multiple times within the same method which is not ideal / best practice (I found one occurrence within a loop).
The advised fix does not need to change any behavior and as far as I can tell there is no bug in the current implementation.
To find the occurrences just search on "$this->getDbo()" in your IDE and observe the number of times the getDbo() method is called. If more than one, then declare a variable on the first call and re-use the variable on all subsequent occurrences. If the getDbo() method is called over and over within a loop, declare $db prior to entering the loop and only use $db within the loop.
Labels |
Added:
?
|
Yes, this is a good codestyle, however as @brianteeman stated, pull requests would be welcome. Otherwise I would vote to close this issue for now.
@mickmackusa sir, I have found multiple occurrences of "$this->getDbo()", so, sir can you please upload an screenshot to approach this, so that I will accordingly, and will change in the best manner, thanks in advance :)
Labels |
Added:
?
No Code Attached Yet
Removed: ? |
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2024-09-25 21:08:59 |
Closed_By | ⇒ | Hackwar | |
Labels |
Added:
Feature
Removed: ? |
In the meantime we refactored the code to use the DatabaseAwareTrait. That changed the original issue of this PR only a little bit, however we are in the process of improving this overall in the coming months and years. I don't think we need to keep this issue open for this, so I'm going to close this. Thank you, @mickmackusa, for reporting this. We will try to refactor as you proposed.
Pull requests are welcome