title: PHP, optimizing for Boolean operators and functions, redundancy and cyclomatic complexity
body: <p>I'm looking at optimizing, formatting and styling a few largish files at the moment. Most of it seems to not be optimally written (probably airing on the side of caution rather than whats best).</p>
  
  <p>One of the things I've specifically been trying to do is reduce cyclomatic complexity where many functions use if() statements that are redundant. More Booleans = more complexity, and while I'm sure it's not terrible (optimizations probably only milliseconds better) I've been seeing a lot of stuff like this:</p>
  
  <pre><code>if (isset($variable) &amp;&amp; !is_null($variable) &amp;&amp; is_object($variable) &amp;&amp; isset($variable-&gt;property))
  </code></pre>
  
  <p>Now I'm fairly sure for example, that:</p>
  
  <pre><code>!is_null($variable) &amp;&amp; is_object($variable)
  </code></pre>
  
  <p>can be shortened to:</p>
  
  <pre><code>is_object($variable)
  </code></pre>
  
  <p>because if $variable is null, then the is_object method will return false anyway - however I'm not 100% this is the case every time. Generally I just wanted to put see what people recommend in terms of lowering the complexity of statements like this, or any other rules for Boolean logic which could lower complexity.</p>