Skip to content

Instantly share code, notes, and snippets.

@Anticom
Last active February 9, 2019 02:06
Show Gist options
  • Save Anticom/3a78168a604ab9f9cae2f52aac1d3f18 to your computer and use it in GitHub Desktop.
Save Anticom/3a78168a604ab9f9cae2f52aac1d3f18 to your computer and use it in GitHub Desktop.
refactor extract boolean expression example (PHP)
<?php
class MobilePhone {
// example state
$state = [
'connectedToWifi' => true,
'connectedToCelular' => false,
];
public function isOnlineMsg() {
if($this->state['connectedToWifi'] || $this->state['cellular']) return 'yes';
return 'no';
}
}
<?php
class MobilePhone {
// example state
$state = [
'connectedToWifi' => true,
'connectedToCelular' => false,
];
public function isOnline() {
return $this->state['connectedToWifi'] || $this->state['cellular'];
}
public function isOnlineMsg() {
if($this->isOnline()) return 'yes';
return 'no';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment