Skip to content

Instantly share code, notes, and snippets.

@pix-art
Last active April 15, 2016 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pix-art/49487f2c7db486cffa415434377849e2 to your computer and use it in GitHub Desktop.
Save pix-art/49487f2c7db486cffa415434377849e2 to your computer and use it in GitHub Desktop.
<?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