Created
February 9, 2022 18:09
-
-
Save tadeubdev/8012482a82f240fd2bbca5ac526cc13d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| class Example | |
| { | |
| /** @var int */ | |
| private $amount; | |
| public function __construct(int $amount) | |
| { | |
| $this->amount = $amount; | |
| } | |
| public function execute(): string | |
| { | |
| if ($this->amount === 0) { | |
| throw new \InvalidArgumentException('O valor passado precisa ser maior que zero!'); | |
| } else if ($this->amount > 1000) { | |
| throw new \InvalidArgumentException('O valor passado precisa ser menor que mill!'); | |
| } else if ($this->amount < 456) { | |
| return "Amount is less than 456"; | |
| } else { | |
| $db = Database::prepare('SELECT amount FROM item_values;'); | |
| $stmt = $db->execute(); | |
| $values = $stmt->fetchAll(); | |
| $oldValues = array_reduce($values, function ($acc, $value) { | |
| return $acc + $vale->amount; | |
| }, 0); | |
| if ($oldValues < $this->amount) { | |
| throw new \InvalidArgumentException(sprintf( | |
| 'O valor passado deve ser menor que %s!', | |
| $oldValues | |
| )); | |
| } | |
| return "Amount is equal or greather than 456"; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment