title: How to reduce the number of IF statements?
body: <p>I have many IF sentences that each start a function.<br>
  Is there an obvious way to write this code much simpler?<br>
  Every IF starts different function, but it still looks like an overkill.</p>
  
  <pre><code>    if ($this-&gt;machine == '' AND $this-&gt;date_from == '' AND $this-&gt;date_to == '' AND $this-&gt;date_like == '' AND $this-&gt;article_or_tool == '') {
          $this-&gt;AllTime();
      }
      if ($this-&gt;machine &lt;&gt; 0 AND $this-&gt;date_from == '' AND $this-&gt;date_to == '' AND $this-&gt;date_like == '' AND $this-&gt;article_or_tool == '') {
          $this-&gt;ByMachine();
      }
      if ($this-&gt;machine == '' AND $this-&gt;date_from &lt;&gt; 0 AND $this-&gt;date_to &lt;&gt; 0 AND $this-&gt;date_like == '' AND $this-&gt;article_or_tool == '') {
          $this-&gt;ByDate();
      }
      if ($this-&gt;machine &lt;&gt; 0 AND $this-&gt;date_from &lt;&gt; 0 AND $this-&gt;date_to &lt;&gt; 0 AND $this-&gt;date_like == '' AND $this-&gt;article_or_tool == '') {
          $this-&gt;ByMachineByDate();
      }
      if ($this-&gt;machine == '' AND $this-&gt;date_from == '' AND $this-&gt;date_to == '' AND $this-&gt;date_like &lt;&gt; 0 AND $this-&gt;article_or_tool == '') {
          $this-&gt;ByDateLike();
      }
      if ($this-&gt;machine &lt;&gt; 0 AND $this-&gt;date_from == '' AND $this-&gt;date_to == '' AND $this-&gt;date_like &lt;&gt; 0 AND $this-&gt;article_or_tool == '') {
          $this-&gt;ByMachineByDateLike();
      }
      if ($this-&gt;machine == '' AND $this-&gt;date_from == '' AND $this-&gt;date_to == '' AND $this-&gt;date_like == '' AND $this-&gt;article_or_tool &lt;&gt; 0) {
          $this-&gt;ByArticle();
      }
      if ($this-&gt;machine &lt;&gt; 0 AND $this-&gt;date_from == '' AND $this-&gt;date_to == '' AND $this-&gt;date_like == '' AND $this-&gt;article_or_tool &lt;&gt; 0) {
          $this-&gt;ByMachineByArticle();
      }
      if ($this-&gt;machine == '' AND $this-&gt;date_from &lt;&gt; 0 AND $this-&gt;date_to &lt;&gt; 0 AND $this-&gt;date_like == '' AND $this-&gt;article_or_tool &lt;&gt; 0) {
          $this-&gt;ByDateByArticle();
      }
      if ($this-&gt;machine == '' AND $this-&gt;date_from == '' AND $this-&gt;date_to == '' AND $this-&gt;date_like &lt;&gt; 0 AND $this-&gt;article_or_tool &lt;&gt; 0) {
          $this-&gt;ByDateLikeByArticle();
      }
      if ($this-&gt;machine &lt;&gt; 0 AND $this-&gt;date_from &lt;&gt; 0 AND $this-&gt;date_to &lt;&gt; 0 AND $this-&gt;date_like == '' AND $this-&gt;article_or_tool &lt;&gt; 0) {
          $this-&gt;ByMachineByDateByArticle();
      }
      if ($this-&gt;machine &lt;&gt; 0 AND $this-&gt;date_from == '' AND $this-&gt;date_to == '' AND $this-&gt;date_like &lt;&gt; 0 AND $this-&gt;article_or_tool &lt;&gt; 0) {
          $this-&gt;ByMachineByDateLikeByArticle();
      }
  </code></pre>
  
  <p>SOLUTION<br>
  Here is my code after refactoring it:</p>
  
  <pre><code>function MethodPicker() {
      $machine            = $this-&gt;machine            &lt;&gt; 0;
      $date_from          = $this-&gt;date_from          &lt;&gt; 0;
      $date_to            = $this-&gt;date_to            &lt;&gt; 0;
      $date_like          = $this-&gt;date_like          &lt;&gt; 0;
      $article_or_tool    = $this-&gt;article_or_tool    &lt;&gt; 0;
  
      $decision  = array($machine, $date_from, $date_to, $date_like, $article_or_tool);
      $decisions = array(
                      'AllTime' =&gt;                        array(false,    false,  false,  false,  false   ),
                      'ByMachine' =&gt;                      array(true,     false,  false,  false,  false   ),
                      'ByDate' =&gt;                         array(false,    true,   true,   false,  false   ),
                      'ByMachineByDate' =&gt;                array(true,     true,   true,   false,  false   ),
                      'ByDateLike' =&gt;                     array(false,    false,  false,  true,   false   ),
                      'ByMachineByDateLike' =&gt;            array(true,     false,  false,  true,   false   ),
                      'ByArticle' =&gt;                      array(false,    false,  false,  false,  true    ),
                      'ByMachineByArticle' =&gt;             array(true,     false,  false,  false,  true    ),
                      'ByDateByArticle' =&gt;                array(false,    true,   true,   false,  true    ),
                      'ByDateLikeByArticle' =&gt;            array(false,    false,  false,  true,   true    ),
                      'ByMachineByDateByArticle' =&gt;       array(true,     true,   true,   false,  true    ),
                      'ByMachineByDateLikeByArticle' =&gt;   array(true,     false,  false,  true,   true    ),
      );
      $method = array_keys($decisions, $decision, true);
      $method &amp;&amp; list($method) = $method;
      $method &amp;&amp; $this-&gt;$method();
  }
  </code></pre>