Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Progress.php
Go to the documentation of this file.
1 <?php
8 
12 class Progress
13 {
19  private $total;
20 
26  private $current;
27 
34  public function __construct($total, $current = 0)
35  {
36  $this->validate($total, $current);
37  $this->total = $total;
38  $this->current = $current;
39  }
40 
46  public function setNext()
47  {
48  $this->validate($this->total, $this->current + 1);
49  $this->current++;
50  }
51 
57  public function finish()
58  {
59  $this->current = $this->total;
60  }
61 
67  public function getCurrent()
68  {
69  return $this->current;
70  }
71 
77  public function getTotal()
78  {
79  return $this->total;
80  }
81 
87  public function getRatio()
88  {
89  return $this->current / $this->total;
90  }
91 
100  private function validate($total, $current)
101  {
102  if (empty($total) || 0 >= $total) {
103  throw new \LogicException('Total number must be more than zero.');
104  }
105  if ($current > $total) {
106  throw new \LogicException('Current cannot exceed total number.');
107  }
108  }
109 }