Skip to content

Commit 23794c5

Browse files
committed
style: styleci
1 parent b5e2bf8 commit 23794c5

File tree

9 files changed

+42
-46
lines changed

9 files changed

+42
-46
lines changed

src/Helper/OutputHelper.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Ahc\Cli\Input\Parameter;
2020
use Ahc\Cli\Output\Writer;
2121
use Throwable;
22+
2223
use function array_map;
2324
use function array_shift;
2425
use function asort;
@@ -44,6 +45,7 @@
4445
use function trim;
4546
use function uasort;
4647
use function var_export;
48+
4749
use const STR_PAD_LEFT;
4850

4951
/**

src/Helper/Shell.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Ahc\Cli\Exception\RuntimeException;
1515

16-
use function defined;
1716
use function fclose;
1817
use function function_exists;
1918
use function fwrite;
@@ -25,10 +24,6 @@
2524
use function proc_terminate;
2625
use function stream_get_contents;
2726
use function stream_set_blocking;
28-
use function strtoupper;
29-
use function str_starts_with;
30-
31-
use const DIRECTORY_SEPARATOR;
3227

3328
/**
3429
* A thin proc_open wrapper to execute shell commands.

src/Helper/Terminal.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use function is_array;
1919
use function preg_match_all;
2020

21-
2221
/**
2322
* A thin to find some information about the current terminal (width, height, ect...).
2423
*
@@ -44,23 +43,23 @@ public static function isWindows(): bool
4443
}
4544

4645
/**
47-
* Get the width of the terminal
46+
* Get the width of the terminal.
4847
*/
4948
public function width(): ?int
5049
{
5150
return $this->getDimension('width');
5251
}
5352

5453
/**
55-
* Get the height of the terminal
54+
* Get the height of the terminal.
5655
*/
5756
public function height(): ?int
5857
{
5958
return $this->getDimension('height');
6059
}
6160

6261
/**
63-
* Get specified terminal dimension
62+
* Get specified terminal dimension.
6463
*/
6564
protected function getDimension(string $key): ?int
6665
{
@@ -77,7 +76,7 @@ protected function getDimension(string $key): ?int
7776
}
7877

7978
/**
80-
* Get information about the dimensions of the Windows terminal
79+
* Get information about the dimensions of the Windows terminal.
8180
*
8281
* @codeCoverageIgnore
8382
*

src/Input/Command.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Ahc\Cli\Output\ProgressBar;
2121
use Ahc\Cli\Output\Writer;
2222
use Closure;
23+
2324
use function array_filter;
2425
use function array_keys;
2526
use function end;

src/Output/ProgressBar.php

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use function count;
1818
use function iterator_to_array;
1919
use function min;
20-
use function round ;
20+
use function round;
2121
use function str_repeat;
2222
use function strlen;
2323
use function trim;
@@ -30,37 +30,37 @@
3030
class ProgressBar
3131
{
3232
/**
33-
* The total number of items involved
33+
* The total number of items involved.
3434
*/
3535
protected int $total = 0;
3636

3737
/**
38-
* The current item that the progress bar represents
38+
* The current item that the progress bar represents.
3939
*/
4040
protected int $current = 0;
4141

4242
/**
43-
* The current percentage displayed
43+
* The current percentage displayed.
4444
*/
4545
protected string $currentPercentage = '';
4646

4747
/**
48-
* The string length of the bar when at 100%
48+
* The string length of the bar when at 100%.
4949
*/
5050
protected int $barStrLen = 0;
5151

5252
/**
53-
* Flag indicating whether we are writing the bar for the first time
53+
* Flag indicating whether we are writing the bar for the first time.
5454
*/
5555
protected bool $firstLine = true;
5656

5757
/**
58-
* Current status bar label
58+
* Current status bar label.
5959
*/
6060
protected string $label = '';
6161

6262
/**
63-
* Options for progress bar
63+
* Options for progress bar.
6464
*/
6565
private array $options = [
6666
'pointer' => '>',
@@ -70,7 +70,7 @@ class ProgressBar
7070
];
7171

7272
/**
73-
* Force a redraw every time
73+
* Force a redraw every time.
7474
*/
7575
protected bool $forceRedraw = false;
7676

@@ -86,7 +86,7 @@ class ProgressBar
8686
protected Terminal $terminal;
8787

8888
/**
89-
* If they pass in a total, set the total
89+
* If they pass in a total, set the total.
9090
*/
9191
public function __construct(?int $total = null, ?Writer $writer = null)
9292
{
@@ -100,7 +100,7 @@ public function __construct(?int $total = null, ?Writer $writer = null)
100100
}
101101

102102
/**
103-
* Set the total property
103+
* Set the total property.
104104
*/
105105
public function total(int $total): self
106106
{
@@ -110,7 +110,7 @@ public function total(int $total): self
110110
}
111111

112112
/**
113-
* Set progress bar options
113+
* Set progress bar options.
114114
*/
115115
public function option(string|array $key, ?string $value = null): self
116116
{
@@ -128,10 +128,11 @@ public function option(string|array $key, ?string $value = null): self
128128
}
129129

130130
/**
131-
* Determines the current percentage we are at and re-writes the progress bar
131+
* Determines the current percentage we are at and re-writes the progress bar.
132132
*
133-
* @return void
134133
* @throws UnexpectedValueException
134+
*
135+
* @return void
135136
*/
136137
public function current(int $current, string $label = '')
137138
{
@@ -151,17 +152,17 @@ public function current(int $current, string $label = '')
151152
}
152153

153154
/**
154-
* Increments the current position we are at and re-writes the progress bar
155+
* Increments the current position we are at and re-writes the progress bar.
155156
*
156-
* @param integer $increment The number of items to increment by
157+
* @param int $increment The number of items to increment by
157158
*/
158159
public function advance(int $increment = 1, string $label = '')
159160
{
160161
$this->current($this->current + $increment, $label);
161162
}
162163

163164
/**
164-
* Force the progress bar to redraw every time regardless of whether it has changed or not
165+
* Force the progress bar to redraw every time regardless of whether it has changed or not.
165166
*/
166167
public function forceRedraw(bool $force = true): self
167168
{
@@ -170,11 +171,10 @@ public function forceRedraw(bool $force = true): self
170171
return $this;
171172
}
172173

173-
174174
/**
175175
* Update a progress bar using an iterable.
176176
*
177-
* @param iterable $items Array or any other iterable object
177+
* @param iterable $items Array or any other iterable object
178178
* @param callable $callback A handler to run on each item
179179
*/
180180
public function each($items, callable $callback = null)
@@ -196,9 +196,8 @@ public function each($items, callable $callback = null)
196196
}
197197
}
198198

199-
200199
/**
201-
* Draw the progress bar, if necessary
200+
* Draw the progress bar, if necessary.
202201
*/
203202
protected function drawProgressBar(int $current, string $label)
204203
{
@@ -212,7 +211,7 @@ protected function drawProgressBar(int $current, string $label)
212211
}
213212

214213
/**
215-
* Build the progress bar str and return it
214+
* Build the progress bar str and return it.
216215
*/
217216
protected function getProgressBar(int $current, string $label): string
218217
{
@@ -226,8 +225,8 @@ protected function getProgressBar(int $current, string $label): string
226225
// Move the cursor up and clear it to the end
227226
$lines = $this->hasLabelLine ? 2 : 1;
228227
$bar = $this->cursor->up($lines);
229-
$bar .= $this->cr() . $this->cursor->eraseLine();
230-
$bar .= $this->getProgressBarStr($current, $label);
228+
$bar .= $this->cr() . $this->cursor->eraseLine();
229+
$bar .= $this->getProgressBarStr($current, $label);
231230

232231
// If this line has a label then set that this progress bar has a label line
233232
if (strlen($label) > 0) {
@@ -239,7 +238,7 @@ protected function getProgressBar(int $current, string $label): string
239238

240239
/**
241240
* Get the progress bar string, basically:
242-
* =============> 50% label
241+
* =============> 50% label.
243242
*/
244243
protected function getProgressBarStr(int $current, string $label): string
245244
{
@@ -256,14 +255,14 @@ protected function getProgressBarStr(int $current, string $label): string
256255
$label = $this->labelFormatted('');
257256
}
258257

259-
$bar = '<' . $this->options['color'] . '>' . $bar . ' ' . $number. '</end>';
258+
$bar = '<' . $this->options['color'] . '>' . $bar . ' ' . $number . '</end>';
260259
$label = '<' . $this->options['labelColor'] . '>' . $label . '</end>';
261260

262261
return trim($bar . $label);
263262
}
264263

265264
/**
266-
* Get the string for the actual bar based on the current length
265+
* Get the string for the actual bar based on the current length.
267266
*/
268267
protected function getBar(int $length): string
269268
{
@@ -274,7 +273,7 @@ protected function getBar(int $length): string
274273
}
275274

276275
/**
277-
* Get the length of the bar string based on the width of the terminal window
276+
* Get the length of the bar string based on the width of the terminal window.
278277
*/
279278
protected function getBarStrLen(): int
280279
{
@@ -287,31 +286,31 @@ protected function getBarStrLen(): int
287286
}
288287

289288
/**
290-
* Format the percentage so it looks pretty
289+
* Format the percentage so it looks pretty.
291290
*/
292291
protected function percentageFormatted(float $percentage): string
293292
{
294293
return round($percentage * 100) . '%';
295294
}
296295

297296
/**
298-
* Format the label so it is positioned correctly
297+
* Format the label so it is positioned correctly.
299298
*/
300299
protected function labelFormatted(string $label): string
301300
{
302301
return "\n" . $this->cr() . $this->cursor->eraseLine() . $label;
303302
}
304303

305304
/**
306-
* Determine whether the progress bar has changed and we need to redrew
305+
* Determine whether the progress bar has changed and we need to redrew.
307306
*/
308307
protected function shouldRedraw(string $percentage, string $label): bool
309308
{
310-
return ($this->forceRedraw || $percentage != $this->currentPercentage || $label != $this->label);
309+
return $this->forceRedraw || $percentage != $this->currentPercentage || $label != $this->label;
311310
}
312311

313312
protected function cr(): string
314313
{
315-
return Terminal::isWindows() ? "\r" : "";
314+
return Terminal::isWindows() ? "\r" : '';
316315
}
317316
}

src/Output/Writer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use function stripos;
2020
use function strpos;
2121
use function ucfirst;
22+
2223
use const PHP_EOL;
2324
use const STDERR;
2425
use const STDOUT;

tests/Helper/OutputHelperTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
use Ahc\Cli\Output\Writer;
2020
use DateTime;
2121
use PHPUnit\Framework\TestCase;
22-
use RuntimeException;
23-
use Throwable;
2422

2523
use function file;
2624
use function implode;

tests/Input/CommandTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use InvalidArgumentException;
1818
use PHPUnit\Framework\TestCase;
1919
use RuntimeException;
20+
2021
use function debug_backtrace;
2122

2223
class CommandTest extends TestCase

tests/Output/ProgressBarTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function test_progress_bar()
2828
$progress->advance(1, "$i x label");
2929
if ($i === 2) {
3030
$progress->forceRedraw(true);
31-
$progress->current(2, "2 x label");
31+
$progress->current(2, '2 x label');
3232
$progress->forceRedraw(false);
3333
}
3434
}

0 commit comments

Comments
 (0)