Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
113 lines (101 loc) · 3 KB

File metadata and controls

113 lines (101 loc) · 3 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
* PHP Command Line Tools
*
* This source file is subject to the MIT license that is bundled
* with this package in the file LICENSE.
*
* @author James Logsdon <dwarf@girsbrain.org>
* @copyright 2010 James Logsdom (http://girsbrain.org)
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
namespace cli;
/**
* A more complex type of Notifier, `Progress` Notifiers always have a maxim
* value and generally show some form of percent complete or estimated time
* to completion along with the standard Notifier displays.
*
* @see cli\Notify
*/
abstract class Progress extends \cli\Notify {
protected $_total = 0;
/**
* Instantiates a Progress Notifier.
*
* @param string $msg The text to display next to the Notifier.
* @param int $total The total number of ticks we will be performing.
* @param int $interval The interval in milliseconds between updates.
* @throws \InvalidArgumentException Thrown if `$total` is less than 0.
*/
public function __construct($msg, $total, $interval = 100) {
parent::__construct($msg, $interval);
$this->_total = (int)$total;
if ($this->_total < 0) {
throw new \InvalidArgumentException('Maximum value out of range, must be positive.');
}
}
/**
* Behaves in a similar manner to `cli\Notify::current()`, but the output
* is padded to match the length of `cli\Progress::total()`.
*
* @return string The formatted and padded tick count.
* @see cli\Progress::total()
*/
public function current() {
$size = strlen($this->total());
return str_pad(parent::current(), $size);
}
/**
* Returns the formatted total expected ticks.
*
* @return string The formatted total ticks.
*/
public function total() {
return number_format($this->_total);
}
/**
* Calculates the estimated total time for the tick count to reach the
* total ticks given.
*
* @return int The estimated total number of seconds for all ticks to be
* completed. This is not the estimated time left, but total.
* @see cli\Notify::speed()
* @see cli\Notify::elapsed()
*/
public function estimated() {
$speed = $this->speed();
if (!$speed || !$this->elapsed()) {
return 0;
}
$estimated = round($this->_total / $speed);
return $estimated;
}
/**
* Forces the current tick count to the total ticks given at instatiation
* time before passing on to `cli\Notify::finish()`.
*/
public function finish() {
$this->_current = $this->_total;
parent::finish();
}
/**
* Increments are tick counter by the given amount. If no amount is provided,
* the ticker is incremented by 1.
*
* @param int $increment The amount to increment by.
*/
public function increment($increment = 1) {
$this->_current = min($this->_total, $this->_current + $increment);
}
/**
* Calculate the percentage completed.
*
* @return float The percent completed.
*/
public function percent() {
if ($this->_total == 0) {
return 1;
}
return ($this->_current / $this->_total);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.