Skip to content

Instantly share code, notes, and snippets.

@tadeubdev
Created February 9, 2022 18:09
Show Gist options
  • Select an option

  • Save tadeubdev/8012482a82f240fd2bbca5ac526cc13d to your computer and use it in GitHub Desktop.

Select an option

Save tadeubdev/8012482a82f240fd2bbca5ac526cc13d to your computer and use it in GitHub Desktop.
<?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