for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* User: alec
* Date: 14.10.18
* Time: 2:18
*/
namespace AlecRabbit\Tools;
use AlecRabbit\Tools\Contracts\CounterInterface;
use AlecRabbit\Tools\Reports\Contracts\ReportableInterface;
use AlecRabbit\Tools\Reports\Traits\Reportable;
use AlecRabbit\Tools\Traits\CounterFields;
class Counter implements CounterInterface, ReportableInterface
{
use CounterFields, Reportable;
* Counter constructor
* @param string|null $name
* @param int $value
public function __construct(?string $name = null, int $value = 0)
$this->name = $this->defaultName($name);
$this->value = $value;
$this->step = 1;
}
* @return int
public function bump(): int
return
$this->bumpUp();
public function bumpUp(): int
$this->value += $this->step;
$this->value;
* @param int $step
* @param bool $setStep
public function bumpWith(int $step, bool $setStep = false): int
$this->value += $this->checkStep($step);
if ($setStep) {
$this->setStep($step);
private function checkStep(int $step): int
if ($step === 0) {
throw new \RuntimeException('Counter step should be non-zero integer.');
return $step;
* @return Counter
public function setStep(int $step): Counter
$this->step = $this->checkStep($step);
return $this;
public function bumpDown(): int
$this->value -= $this->step;