Skip to content

Instantly share code, notes, and snippets.

@pix-art pix-art/ExampleService.php Secret
Last active Apr 15, 2016

Embed
What would you like to do?
<?php
class ExampleService
{
//Dry Violation
public function doThis(Example $example)
{
if (!$example->isAwesome()) {
throw new NotAwesomeException("This is not an awesome example!");
}
//Do this
}
public function doThat(Example $example)
{
if (!$example->isAwesome()) {
throw new NotAwesomeException("This is not an awesome example!");
}
//Do that
}
//Good example:
public function doThis(Example $example)
{
$this->isAwesomeExample($example);
//Do this
}
public function doThat(Example $example)
{
$this->isAwesomeExample($example);
//Do that
}
private function isAwesomeExample(Example $example)
{
if (!$example->isAwesome()) {
throw new NotAwesomeException("This is not an awesome example!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.