Skip to content

Instantly share code, notes, and snippets.

@ti-ka
Last active August 16, 2016 19:00
Show Gist options
  • Save ti-ka/a1828e9a8e43ea1fa1225d397d46a3f8 to your computer and use it in GitHub Desktop.
Save ti-ka/a1828e9a8e43ea1fa1225d397d46a3f8 to your computer and use it in GitHub Desktop.
<?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