Last active
August 16, 2016 19:00
-
-
Save ti-ka/a1828e9a8e43ea1fa1225d397d46a3f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
This is a sample, concept-only class to demonstrate some refactoring. | |
Not inteneded as a full flegde or perfect example. | |
*/ | |
class Tea { | |
public function shouldServe($guests) : bool { | |
// Assume - HasMilk() and other methods are present | |
if ( $this->HasMilk() && $this->HasLeaves() && $this->HasSugar()) | |
{ | |
if( $this->Temperature > 135 && $this->temperature <= 170){ | |
foreach ( $guests as $guest){ | |
if ( ! $guest->isReady()){ | |
return false; | |
} | |
} | |
return true; | |
} | |
} | |
return false; | |
} | |
} | |
/****************************************************************************************** | |
Maybe you can do this: | |
******************************************************************************************/ | |
class Tea{ | |
public function shouldServe($guests) : bool { | |
return $this->ready() && $this->guestsAreReady($guests); | |
} | |
public function isReady() : bool { | |
return $this->hasMilk() && $this->hasSugar() && $this->temperatureIsReady($this->temperature); | |
} | |
private function temperatureIsReady() : bool{ | |
return $this->Temperature > 135 && $this->temperature <= 170; | |
} | |
private function guestsAreReady($guests) : bool { | |
foreach ( $guests as $guest){ | |
if ( ! $guest->isReady()){ | |
return false; | |
} | |
} | |
return true; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment