Twelve years ago, a company decided they needed a website. They didn’t have any web developers, and they didn’t want to hire any, so they threw a PHP manual at the new hire who happened to “be good with computers”, and called it a day.

Ms. “Good With Computers” actually learned something from the experience, and moved on to a lucrative career in web development. Unfortunately, she left behind the code she learned by doing, and now Bert has been brought in to clean up the code.

Take this block, which translates an airport code into a location name…

``````    switch (\$v) {
case "EIN": \$ori = "Eindhoven";
break;
case "EIN": \$ori = "Eindhoven";
break;
case "EIN": \$ori = "Eindhoven";
break;
case "EIN": \$ori = "Eindhoven";
break;
case "EIN": \$ori = "Eindhoven";
break;
case "EIN": \$ori = "Eindhoven";
break;
default: break;
}

switch (\$b) {
case "WRO": \$des = "Wroclaw";
break;
case "WRO": \$des = "Wroclaw";
break;
case "WRO": \$des = "Wroclaw";
break;
case "WRO": \$des = "Wroclaw";
break;
case "WRO": \$des = "Wroclaw";
break;
case "WRO": \$des = "Wroclaw";
break;
case "WRO": \$des = "Wroclaw";
break;
case "WRO": \$des = "Wroclaw";
break;
case "WRO": \$des = "Wroclaw";
break;
case "WRO": \$des = "Wroclaw";
break;
case "WRO": \$des = "Wroclaw";
break;
case "WRO": \$des = "Wroclaw";
break;
default: break;
}``````

There’s hundreds of lines of this, following the same pattern- one switch block with the same condition repeated many times for each possible airport code. These blocks don’t exist in a function, either- they’re slapped right into the global namespace.

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