SlideShare a Scribd company logo
1 of 20
Download to read offline
Smelling Your Code
Raju Mazumder
Sr. Software Engineer
Tasawr Interactive

Rubyist, Java and PHP Developer
like to work fun and challenging environment

Web: www.rajumazumder.com
Twitter: @rajuniit
What is Code Smell?
Wikipedia Definition

“ code smell is any symptom in the source code of a program
  that possibly indicates a deeper problem. ”
Speculative Generality

Large Class            Long Method

Dead Code             Comment
Switch Case        Primitive Obsession

    Duplicated Code
          Long Parameter List
   Meaningful Names
Divergent Change      Shotgun Surgery
Dead Code
Harder to comprehend the code base.

Wasted time - reading through, or even changing dead code.



Meaningful Names
public $d; // what does it mean? Days or diameter

public $days; // clean

public function getinvcdtlmt() {
    //do something
}

public function getInvoiceableCreditLimit() {
    //do something
}
Comment is smell

Which one is clearer?

//check is employee active
if ( $employee->isActive() ) {
      //do something;
}

if ( $employee->isActive() ) {
      //do something;
}
Duplicate Code
Code repeated in multiple places.
Bad Example
<?php
function displayPHPExperSpeakerInfo($speakerId)
{
    $speaker = new Speaker();
    $speaker = $speaker->find($speakerId);

   if($speaker->isSixMinuteSpeaker()) {
        $name = $speaker->getName();
        $designation = $speaker->getDesignation();
        echo "Name: ". $name;
        echo "Designation:". $designation;
   } else {
        $name = $speaker->getName();
        $designation = $speaker->getDesignation();
        $topic = $speaker->getTopicName();
        echo "Name:". $name;
        echo "Designation: " . $designation;
        echo "Topic: ". $topic;
   }
}
displayPHPExperSpeakerInfo(2);
Refactor continue...
<?php
function displayPHPExperSpeakerInfo($speakerId)
{
    $speaker = new Speaker();
    $speaker = $speaker->find($speakerId);

    displayGeneralInformation($speaker);

    if ($speaker->isTwelveMinuteSpeaker()) {
          $topic = $speaker->getTopicName();
          echo "Topic: " . $topic;
    }
}
function displayGeneralInformation($speaker)
{
  $name = $speaker->getName();
  $designation = $speaker->getDesignation();
  echo "Name: " . $name;
  echo "Designation:" . $designation;
}

displayPHPExperSpeakerInfo(2);

                            Note: We can imrove it more. Its just an example
Long Method
Longer Methods are difficult to understand
Too many conditions and loops

Long Class
Single responsibility Principle Violated
Bad Example

function gotoPhpExpertsSeminar2011() {
   //wake up morning
    //taking my breakfast
    //take vehicle
    //check confirmation code
   //take a seat
}
Refactor Continue...


function gotoPhpExpertsSeminar2011() {
    wakeUpMorning();
    takeBreakFast();
    takeVehicle();
    checkConfirmationCode();
   takeSeat();
}




                      Note: We can imrove it more. Its just an example
Long Parameter List
Lots of parameters will make code harder to
understand.
Bad Example..
function getSpeakers($type = '', $experience = 0,
  $zce = null, $newSpeaker = null)
{
  $criteria = array();
  if ($type) {
      $criteria[] = "type = '{$type}' ";
  }
  .......
  ........
  if ($criteria) {
      $condition = implode('AND ', $criteria);
  } else {
      $condition = '1=1';
  }
  $speakers = $db->fetchQuery("select * from speakers
           WHERE {$condition}");
  return $speakers;
}

$sixMinuteSpeakers = getSpeakers('six_minute');
$zecSpeakers = getSpeakers('',0,true);
$tweleveMinuteSpeakers = getSpeakers('twelve_minute');
Refactor continue..
function getSpeakersByType($type = 'six_minute')
{
  $speakers = $db->fetchQuery("select * from speakers
         WHERE type = '{$type}'");
  return $speakers;
}

function getZceSpeakers()
{
  $speakers = $db->fetchQuery("select * from speakers
         WHERE zce = 1");
  return $speakers;
}

$sixMinuteSpeakers = getSpeakersByType();
$zecSpeakers = getZceSpeakers();
$tweleveMinuteSpeakers = getSpeakersByType('twelve_minute');




                           Note: We can imrove it more. Its just an example
Refactor continue..
function getSpeakersByOptions(array $options)
{
  $condition = prepareWhere($options);
  $speakers = $db->fetchQuery("select * from speakers
           WHERE {$condition}");
  return $speakers;
}
function prepareWhere($options)
{
  $criteria = array();
  foreach ($options as $option => $value) {
      switch ($option) {
        case 'type': $criteria[] = "type = '{$value}' "; break;
        case 'zce': $criteria[] = "zce = '{$value}' "; break;
        case 'experience': $criteria[] = "experience = '{$value}' "; break;
        default: break;
      }
  }
  if ($criteria) {
      $condition = implode('AND ', $criteria);
  } else {
      $condition = '1=1';
  }
  return $condition;
}                                   Note: We can imrove it more. Its just an example
Refactor Continue...
$options = array('type' => 'six_minute');
$sixFameSpeakers = getSpeakersByOptions($options);

$options = array('zce' => 1);
$zecSpeakers = getSpeakersByOptions($options);

$options = array('type' => 'twelve_minute');
$tweleveMinuteSpeakers = getSpeakersByOptions($options);




                          Note: We can imrove it more. Its just an example
Smell Detection Tools
Phpcpd
https://github.com/sebastianbergmann/phpcpd

PHP Code Sniffer
http://pear.php.net/package/PHP_CodeSniffer/redirected

Phpdepend
http://pdepend.org/download/index.html

phploc
https://github.com/sebastianbergmann/phploc

phpmd
http://phpmd.org/
Resources
Clean Code
– Robert C. Martin
Refactoring: Improved the design of existing code
– Martin Fowler
Thanks
“Code is the mirror of the developer”
“So let's Write Beautiful Code”



Questions?

More Related Content

What's hot

Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4
Fabien Potencier
 
R57shell
R57shellR57shell
R57shell
ady36
 
Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3
Fabien Potencier
 
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Fabien Potencier
 
Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8
PrinceGuru MS
 
Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2
Fabien Potencier
 
Doctrine fixtures
Doctrine fixturesDoctrine fixtures
Doctrine fixtures
Bill Chang
 

What's hot (20)

PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data Objects
 
Things I Believe Now That I'm Old
Things I Believe Now That I'm OldThings I Believe Now That I'm Old
Things I Believe Now That I'm Old
 
Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010
 
php plus mysql
php plus mysqlphp plus mysql
php plus mysql
 
Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4
 
R57shell
R57shellR57shell
R57shell
 
Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3
 
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
 
Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)
 
Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8
 
Perforce Object and Record Model
Perforce Object and Record Model  Perforce Object and Record Model
Perforce Object and Record Model
 
PHP 5.4
PHP 5.4PHP 5.4
PHP 5.4
 
Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2
 
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersTeaching Your Machine To Find Fraudsters
Teaching Your Machine To Find Fraudsters
 
Doctrine fixtures
Doctrine fixturesDoctrine fixtures
Doctrine fixtures
 
Object Calisthenics Adapted for PHP
Object Calisthenics Adapted for PHPObject Calisthenics Adapted for PHP
Object Calisthenics Adapted for PHP
 
Pim Elshoff "Technically DDD"
Pim Elshoff "Technically DDD"Pim Elshoff "Technically DDD"
Pim Elshoff "Technically DDD"
 
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 Version
 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6
 
Presentation1
Presentation1Presentation1
Presentation1
 

Similar to Smelling your code

Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 
Mocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnitMocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnit
mfrost503
 

Similar to Smelling your code (20)

Symfony2 - extending the console component
Symfony2 - extending the console componentSymfony2 - extending the console component
Symfony2 - extending the console component
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
PHPSpec BDD for PHP
PHPSpec BDD for PHPPHPSpec BDD for PHP
PHPSpec BDD for PHP
 
Functional programming with php7
Functional programming with php7Functional programming with php7
Functional programming with php7
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolve
 
Php functions
Php functionsPhp functions
Php functions
 
Mocking Demystified
Mocking DemystifiedMocking Demystified
Mocking Demystified
 
Mocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnitMocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnit
 
PHP Tips & Tricks
PHP Tips & TricksPHP Tips & Tricks
PHP Tips & Tricks
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
 
Php & my sql
Php & my sqlPhp & my sql
Php & my sql
 
PHPSpec BDD Framework
PHPSpec BDD FrameworkPHPSpec BDD Framework
PHPSpec BDD Framework
 
Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?
 
Your code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnConYour code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnCon
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrow
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5
 
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 

Smelling your code

  • 1. Smelling Your Code Raju Mazumder Sr. Software Engineer Tasawr Interactive Rubyist, Java and PHP Developer like to work fun and challenging environment Web: www.rajumazumder.com Twitter: @rajuniit
  • 2. What is Code Smell?
  • 3. Wikipedia Definition “ code smell is any symptom in the source code of a program that possibly indicates a deeper problem. ”
  • 4. Speculative Generality Large Class Long Method Dead Code Comment Switch Case Primitive Obsession Duplicated Code Long Parameter List Meaningful Names Divergent Change Shotgun Surgery
  • 5. Dead Code Harder to comprehend the code base. Wasted time - reading through, or even changing dead code. Meaningful Names public $d; // what does it mean? Days or diameter public $days; // clean public function getinvcdtlmt() { //do something } public function getInvoiceableCreditLimit() { //do something }
  • 6. Comment is smell Which one is clearer? //check is employee active if ( $employee->isActive() ) { //do something; } if ( $employee->isActive() ) { //do something; }
  • 7. Duplicate Code Code repeated in multiple places.
  • 8. Bad Example <?php function displayPHPExperSpeakerInfo($speakerId) { $speaker = new Speaker(); $speaker = $speaker->find($speakerId); if($speaker->isSixMinuteSpeaker()) { $name = $speaker->getName(); $designation = $speaker->getDesignation(); echo "Name: ". $name; echo "Designation:". $designation; } else { $name = $speaker->getName(); $designation = $speaker->getDesignation(); $topic = $speaker->getTopicName(); echo "Name:". $name; echo "Designation: " . $designation; echo "Topic: ". $topic; } } displayPHPExperSpeakerInfo(2);
  • 9. Refactor continue... <?php function displayPHPExperSpeakerInfo($speakerId) { $speaker = new Speaker(); $speaker = $speaker->find($speakerId); displayGeneralInformation($speaker); if ($speaker->isTwelveMinuteSpeaker()) { $topic = $speaker->getTopicName(); echo "Topic: " . $topic; } } function displayGeneralInformation($speaker) { $name = $speaker->getName(); $designation = $speaker->getDesignation(); echo "Name: " . $name; echo "Designation:" . $designation; } displayPHPExperSpeakerInfo(2); Note: We can imrove it more. Its just an example
  • 10. Long Method Longer Methods are difficult to understand Too many conditions and loops Long Class Single responsibility Principle Violated
  • 11. Bad Example function gotoPhpExpertsSeminar2011() { //wake up morning //taking my breakfast //take vehicle //check confirmation code //take a seat }
  • 12. Refactor Continue... function gotoPhpExpertsSeminar2011() { wakeUpMorning(); takeBreakFast(); takeVehicle(); checkConfirmationCode(); takeSeat(); } Note: We can imrove it more. Its just an example
  • 13. Long Parameter List Lots of parameters will make code harder to understand.
  • 14. Bad Example.. function getSpeakers($type = '', $experience = 0, $zce = null, $newSpeaker = null) { $criteria = array(); if ($type) { $criteria[] = "type = '{$type}' "; } ....... ........ if ($criteria) { $condition = implode('AND ', $criteria); } else { $condition = '1=1'; } $speakers = $db->fetchQuery("select * from speakers WHERE {$condition}"); return $speakers; } $sixMinuteSpeakers = getSpeakers('six_minute'); $zecSpeakers = getSpeakers('',0,true); $tweleveMinuteSpeakers = getSpeakers('twelve_minute');
  • 15. Refactor continue.. function getSpeakersByType($type = 'six_minute') { $speakers = $db->fetchQuery("select * from speakers WHERE type = '{$type}'"); return $speakers; } function getZceSpeakers() { $speakers = $db->fetchQuery("select * from speakers WHERE zce = 1"); return $speakers; } $sixMinuteSpeakers = getSpeakersByType(); $zecSpeakers = getZceSpeakers(); $tweleveMinuteSpeakers = getSpeakersByType('twelve_minute'); Note: We can imrove it more. Its just an example
  • 16. Refactor continue.. function getSpeakersByOptions(array $options) { $condition = prepareWhere($options); $speakers = $db->fetchQuery("select * from speakers WHERE {$condition}"); return $speakers; } function prepareWhere($options) { $criteria = array(); foreach ($options as $option => $value) { switch ($option) { case 'type': $criteria[] = "type = '{$value}' "; break; case 'zce': $criteria[] = "zce = '{$value}' "; break; case 'experience': $criteria[] = "experience = '{$value}' "; break; default: break; } } if ($criteria) { $condition = implode('AND ', $criteria); } else { $condition = '1=1'; } return $condition; } Note: We can imrove it more. Its just an example
  • 17. Refactor Continue... $options = array('type' => 'six_minute'); $sixFameSpeakers = getSpeakersByOptions($options); $options = array('zce' => 1); $zecSpeakers = getSpeakersByOptions($options); $options = array('type' => 'twelve_minute'); $tweleveMinuteSpeakers = getSpeakersByOptions($options); Note: We can imrove it more. Its just an example
  • 18. Smell Detection Tools Phpcpd https://github.com/sebastianbergmann/phpcpd PHP Code Sniffer http://pear.php.net/package/PHP_CodeSniffer/redirected Phpdepend http://pdepend.org/download/index.html phploc https://github.com/sebastianbergmann/phploc phpmd http://phpmd.org/
  • 19. Resources Clean Code – Robert C. Martin Refactoring: Improved the design of existing code – Martin Fowler
  • 20. Thanks “Code is the mirror of the developer” “So let's Write Beautiful Code” Questions?