You are here

public function Counter::increment in Purge 8.3

Increase the counter.

Parameters

int|float $amount: Numeric amount to add up to the current counter value.

Throws

\Drupal\purge\Plugin\Purge\Purger\Exception\BadBehaviorException Thrown when $amount is not a float, integer, when it is zero/negative.

\LogicException Thrown when the object got created without increment permission.

Overrides CounterInterface::increment

File

src/Counter/Counter.php, line 162

Class

Counter
Provides a numeric counter.

Namespace

Drupal\purge\Counter

Code

public function increment($amount = 1.0) {
  if (!$this->permissionIncrement) {
    throw new \LogicException('No ::increment() permission on this object.');
  }
  if (!(is_float($amount) || is_int($amount))) {
    throw new BadBehaviorException('Given $amount is not a integer or float.');
  }
  if (is_int($amount)) {
    $amount = (double) $amount;
  }
  if (!($amount > 0.0)) {
    throw new BadBehaviorException('Given $amount is zero or negative.');
  }
  $this
    ->setDirectly($this->value + $amount);
}