As much as I love WordPress…

Seems that some WP developers are fans of refuctoring.

if ( ($fQ=strpos($Fid,'"'))!==false )
    $Fname = sanitize_title_with_dashes(substr( $Fid, $fQ+1, strpos($Fid,'"',$fQ+1)-$fQ-1 ));
### wrapped in <p> ?
   $p_offset = ($p_close < $p_open) ? $a-(strlen($part_content)-$p_open) : $a;

Argh. Guys, seriously, how about some objects? How about some readable variables? How about instead of nesting function calls and using ugly ternary operators… ugh. Nevermind.

transactions

function run() {
  ...
  //DONT TOUCH !!! -&gt; THIS DB TRANS STARTS, BECAUSE XYZ MODUL CONSIST OF DB::Commit() clausule
  DB::Trans();
  return $returnVal;
}

Hey guys, let’s start a transaction here and expect that no one will ever change the code in any of the other 2000 files. And if they do, I’m sure that while they’ll be editing “modul” XYZ, I’m sure they will know that transaction starts here.

Hardcoding FTW

function _getCRServices($data)
  {
    if (is_array($data)) {
      //this is ehmmmm, d*ment requirement from client
      $not_cr = array(3006, 2416, 1026, 5604, 3501);
      ...
    }
  }

Makes one wonder if there was a demented requirement, or just a demented programming technique.

OCD code?

if (!empty(fetchResult()) and isObject(fetchResult()) and is_a(fetchResult(), "objectType")) {
  $result = fetchResult();
  doSomethingElse();
}
elseif (isObject(fetchResult()) {
  $result = fetchResult();
}

I think the guy who wrote it was slightly OCD. And he definitely forgot that fetchResult() fetches results… from the database.

After optimizing aforementioned code and singleton-ifying the fetchResult(), number of queries made in one pageload went down to 300 from 800. Our code is just awesome.