Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A function should have clearly defined, narrow responsibilities with clearly defined, minimalist return types. If you start to create "god functions" which do everything and the kitchen sink depending on what arguments you pass, you're going heavily into the territory of hard to maintain spaghetti code. You do not want a function that does A and returns B if you pass it X, but does C and returns D if you pass it Y etc...</p> <p>It is a good idea to start <em>concrete</em> and generalize over time as you see similar patterns emerge. So, create the methods you actually need:</p> <pre><code>public function findUserById($id) public function findUserByEmail($email) public function updateCompanyName($id, $newName) </code></pre> <p>If you find you have shared code between these functions, unify the code behind the scenes to keep it DRY:</p> <pre><code>public function findUserById($id) { return $this-&gt;find('SELECT * FROM user WHERE id = ?', $id); } public function findUserByEmail($email) { return $this-&gt;find('SELECT * FROM user WHERE email = ?', $email); } protected function find($query, $arg) { ... } </code></pre> <p>Don't start the other way around, thinking you "only need X,Y and Z" which seem similar enough to be unified into one method, then later finding out there are small differences between X, Y and Z and littering your code with special cases for each. That just leads to functions which are either ginormous or so general they basically do nothing on their own.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload