We've all seen it before. I dare say we've all been a party to it.

First, we look at a block of code that needs to be modified. Then we determine which criteria needs to be added to address the case that we've been tasked to implement. Next, we add the condition and walk away before the waft from the code smell reaches our nostrils. Over time, a monstrosity like the following arises from the depths. Not something that couldn't be greatly improved by some fava beans and a nice refactor. I'm sure the unit tests that cover your production code base will ensure that your refactoring was successful. Right? Right??

<script type="text/javascript">
   var pageRefresh = true;
   steps_completed[1] = true;
   steps_completed[2] = true;
   if(!$.getCookie('select_level') ) $.setCookie("select_level", 2, 1); 
   if($_SESSION['UserData']['step2'] == true) echo 'steps_completed[3] = true; if(pageRefresh == false) $.setCookie("select_level", 3, 1);'; //it games from register.php
   if($_SESSION['UserData']['step3'] == true) echo 'steps_completed[4] = true; if(pageRefresh == false) $.setCookie("select_level", 4, 1);'; //it games from eshop.php
   if($_POST['register']) echo 'steps_completed[2] = true;$.setCookie("select_level", 2, 1);'; //if i only update my data
   if($_POST['register'] && $this->registerClient->registerClient->getMessage('register_success')) echo '$.setCookie("select_level", 3, 1);'; //if i update data and continue next step 
   if($_GET['auth'] == 'true' && $_SESSION['logged']) echo 'steps_completed[3] = true;$.setCookie("select_level", 3, 1);'; //if i only update my data
   if($_POST['add_financial'] && $_SESSION['logged']) echo 'steps_completed[3] = true;$.setCookie("select_level", 3, 1);'; //if i only update my data 
   if($_POST['add_financial'] && $_SESSION['logged'] && $this->getMessage('financial_success')) echo '$.setCookie("select_level", 4, 1);'; //if i update data and continue next step
   if($_GET['add_financial'] == 'true' && $_SESSION['logged']) echo '$.setCookie("select_level", 4, 1);'; //if i update data and continue next step 
   if($_POST['to_step_2'] && $_SESSION['logged']) echo '$.setCookie("select_level", 2, 1);'; //if i update data and continue next step //if steps1,2,3 is restricted
   if($this->getError('have_order') || $this->getError('have_notcompleted_order')) {
      echo '$.setCookie("select_level", 4, 1);';
      echo 'steps_completed[1] = false;';
      echo 'steps_completed[2] = false;';
      echo 'steps_completed[3] = false;';
      echo 'steps_completed[4] = true;';
   }
</script>

 

Photo credit: Foter / CC BY-SA

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!