PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 3.8.2
WP STAGING – WordPress Backup, Restore, Migration & Clone v3.8.2
4.9.2 4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Backup / Dto / StepsDto.php
wp-staging / Backup / Dto Last commit date
File 2 years ago Interfaces 2 years ago Job 2 years ago Service 2 years ago Task 2 years ago Traits 1 year ago AbstractDto.php 3 years ago AbstractTaskDto.php 2 years ago JobDataDto.php 2 years ago StepsDto.php 2 years ago TaskResponseDto.php 2 years ago
StepsDto.php
106 lines
1 <?php
2
3 // TODO PHP7.x declare(strict_types=1);
4 // TODO PHP7.x type-hints & return types
5
6 namespace WPStaging\Backup\Dto;
7
8 class StepsDto extends AbstractDto
9 {
10 /** @var int */
11 private $total;
12
13 /** @var int */
14 private $current;
15
16 /** @var int */
17 private $manualPercentage;
18
19 /**
20 * @return int
21 */
22 public function getTotal()
23 {
24 return $this->total;
25 }
26
27 /**
28 * @param int $total
29 */
30 public function setTotal($total)
31 {
32 $this->total = (int) $total;
33 }
34
35 /**
36 * @return int
37 */
38 public function getCurrent()
39 {
40 return $this->current;
41 }
42
43 /**
44 * @param int $current
45 */
46 public function setCurrent($current)
47 {
48 $this->current = (int) $current;
49 }
50
51 /**
52 * Sometimes we can't know how many steps there will be in total,
53 * so we can mimic an percentage using this method.
54 *
55 * For instance: FileScannerTask doesn't know how many total
56 * steps it will have to process, so we can set a manual estimate.
57 *
58 * @param int $manualPercentage
59 */
60 public function setManualPercentage($manualPercentage)
61 {
62 $this->manualPercentage = (int)$manualPercentage;
63 }
64
65 /**
66 * @return int
67 */
68 public function getPercentage()
69 {
70 if (!empty($this->manualPercentage)) {
71 return $this->manualPercentage;
72 }
73
74 if ($this->total < 1) {
75 return 100;
76 }
77
78 $percentage = (int) round(($this->current / $this->total) * 100);
79 return max(0, min(100, $percentage));
80 }
81
82 public function incrementCurrentStep()
83 {
84 if ($this->current < $this->total) {
85 $this->current++;
86 }
87 }
88
89 public function decreaseCurrentStep()
90 {
91 if ($this->current > 0) {
92 $this->current--;
93 }
94 }
95
96 public function isFinished()
97 {
98 return $this->total <= $this->current;
99 }
100
101 public function finish()
102 {
103 $this->current = $this->total;
104 }
105 }
106