Last active
September 6, 2018 16:28
-
-
Save iRynoh/8a5df9e4e05538a5d65b89726b8eab67 to your computer and use it in GitHub Desktop.
This file contains 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 | |
public function verify() { | |
$statistic = $this->getStatistic(); | |
if ($statistic) { | |
if ($statistic->getTotalCount() === 0) { | |
$incident = IncidentFactory::CtIncident(); | |
$incident->registerIncident(); | |
} else { | |
$failurePercentage = $statistic->getFailCount() / $statistic->getTotalCount() * 100; | |
if ($failurePercentage > 40) { | |
$incident = IncidentFactory::CtIncident(); | |
$incident->registerIncident(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'd probably at least rewrite it like this:
Treat the falsey check like a guard clause and handle it separately at the beginning of the method, move the logic for calculating the failure percentage right into the statistic since it holds all the relevant data, and make it all a single compound conditional to avoid duplicating the incident factory stuff.