Skip to content

Instantly share code, notes, and snippets.

@petehouston
Last active August 29, 2015 14:09
Show Gist options
  • Save petehouston/44b1109e1c8f8f6f05b2 to your computer and use it in GitHub Desktop.
Save petehouston/44b1109e1c8f8f6f05b2 to your computer and use it in GitHub Desktop.
Refactoring: Nested logical expressions
<?php
public function canBuyALaptop()
{
if( isCheap( $laptopRepository->price() )) {
if( $laptopRepository->isAvailable() ) {
return true;
} else {
return false;
}
} else {
return false;
}
}
<?php
public function canBuyALaptop()
{
if( isCheap( $laptopRepository->price() ) && $laptopRepository->isAvailable() ) {
return true;
}
return false;
}
<?php
public function canBuyALaptop()
{
return isCheap( $laptopRepository->price() ) && $laptopRepository->isAvailable();
}
<?php
public function canBuyALaptop()
{
if( isCheap( $laptopRepository->price() )) {
if( $laptopRepository->isAvailable() ) {
return true;
}
return false;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment