Skip to content

Commit 69e4c73

Browse files
jlogsdonRyan
authored andcommitted
Explicit use statements and Streams instead of cli\funcs
1 parent 5d54ae4 commit 69e4c73

File tree

8 files changed

+52
-35
lines changed

8 files changed

+52
-35
lines changed

lib/cli/Arguments.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313
namespace cli;
1414

15+
use cli\arguments\Argument;
16+
use cli\arguments\HelpScreen;
17+
use cli\arguments\InvalidArguments;
18+
use cli\arguments\Lexer;
19+
1520
/**
1621
* Parses command line arguments.
1722
*/
@@ -63,7 +68,7 @@ public function getArguments() {
6368
}
6469

6570
public function getHelpScreen() {
66-
return new arguments\HelpScreen($this);
71+
return new HelpScreen($this);
6772
}
6873

6974
/**
@@ -82,7 +87,7 @@ public function asJSON() {
8287
* @return bool
8388
*/
8489
public function offsetExists($offset) {
85-
if ($offset instanceOf arguments\Argument) {
90+
if ($offset instanceOf Argument) {
8691
$offset = $offset->key;
8792
}
8893

@@ -96,7 +101,7 @@ public function offsetExists($offset) {
96101
* @return mixed
97102
*/
98103
public function offsetGet($offset) {
99-
if ($offset instanceOf arguments\Argument) {
104+
if ($offset instanceOf Argument) {
100105
$offset = $offset->key;
101106
}
102107

@@ -112,7 +117,7 @@ public function offsetGet($offset) {
112117
* @param mixed $value The value to set
113118
*/
114119
public function offsetSet($offset, $value) {
115-
if ($offset instanceOf arguments\Argument) {
120+
if ($offset instanceOf Argument) {
116121
$offset = $offset->key;
117122
}
118123

@@ -125,7 +130,7 @@ public function offsetSet($offset, $value) {
125130
* @param mixed $offset An Argument object or the name of the argument.
126131
*/
127132
public function offsetUnset($offset) {
128-
if ($offset instanceOf arguments\Argument) {
133+
if ($offset instanceOf Argument) {
129134
$offset = $offset->key;
130135
}
131136

@@ -274,7 +279,7 @@ public function getInvalidArguments() {
274279
* @return array
275280
*/
276281
public function getFlag($flag) {
277-
if ($flag instanceOf \cli\arguments\Argument) {
282+
if ($flag instanceOf Argument) {
278283
$obj = $flag;
279284
$flag = $flag->value;
280285
}
@@ -335,7 +340,7 @@ public function isStackable($flag) {
335340
* @return array
336341
*/
337342
public function getOption($option) {
338-
if ($option instanceOf arguments\Argument) {
343+
if ($option instanceOf Argument) {
339344
$obj = $option;
340345
$option = $option->value;
341346
}
@@ -380,12 +385,12 @@ public function isOption($argument) {
380385
* if a long name is not given.
381386
*
382387
* @return array
383-
* @throws arguments\InvalidArguments
388+
* @throws arguments\InvalidArguments
384389
*/
385390
public function parse() {
386391
$this->_invalid = array();
387392
$this->_parsed = array();
388-
$this->_lexer = new arguments\Lexer($this->_input);
393+
$this->_lexer = new Lexer($this->_input);
389394

390395
foreach ($this->_lexer as $argument) {
391396
if ($this->_parseFlag($argument)) {
@@ -399,7 +404,7 @@ public function parse() {
399404
}
400405

401406
if ($this->_strict && !empty($this->_invalid)) {
402-
throw new arguments\InvalidArguments($this->_invalid);
407+
throw new InvalidArguments($this->_invalid);
403408
}
404409
}
405410

lib/cli/Notify.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
namespace cli;
1414

15+
use cli\Streams;
16+
1517
/**
1618
* The `Notify` class is the basis of all feedback classes, such as Indicators
1719
* and Progress meters. The default behaviour is to refresh output after 100ms
@@ -127,9 +129,9 @@ public function formatTime($time) {
127129
* @see cli\Notify::display()
128130
*/
129131
public function finish() {
130-
\cli\out("\r");
132+
Streams::out("\r");
131133
$this->display(true);
132-
\cli\line();
134+
Streams::line();
133135
}
134136

135137
/**
@@ -176,7 +178,7 @@ public function tick($increment = 1) {
176178
$this->increment($increment);
177179

178180
if ($this->shouldUpdate()) {
179-
\cli\out("\r");
181+
Streams::out("\r");
180182
$this->display();
181183
}
182184
}

lib/cli/Shell.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ class Shell {
2424
* @todo Test on more systems.
2525
*/
2626
static public function columns() {
27-
if ( file_exists('/usr/bin/env') ) {
28-
return exec('/usr/bin/env tput cols');
29-
}
30-
return 80; // default width of cmd window on Windows OS, maybe force using MODE CON COLS=XXX?
27+
if (stripos(PHP_OS, 'indows') === false) {
28+
return exec('/usr/bin/env tput cols');
29+
}
30+
return 80; // default width of cmd window on Windows OS, maybe force using MODE CON COLS=XXX?
3131
}
3232

3333
/**

lib/cli/Table.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212

1313
namespace cli;
1414

15+
use cli\Shell;
16+
use cli\Streams;
17+
use cli\table\Ascii;
18+
use cli\table\Renderer;
19+
use cli\table\Tabular;
20+
1521
/**
1622
* The `Table` class is used to display data in a tabular format.
1723
*/
@@ -36,7 +42,7 @@ class Table {
3642
*
3743
* @param array $headers Headers used in this table. Optional.
3844
* @param array $rows The rows of data for this table. Optional.
39-
* @param array $footers Footers used in this table. Optional.
45+
* @param array $footers Footers used in this table. Optional.
4046
*/
4147
public function __construct(array $headers = null, array $rows = null, array $footers = null) {
4248
if (!empty($headers)) {
@@ -60,10 +66,10 @@ public function __construct(array $headers = null, array $rows = null, array $fo
6066
$this->setFooters($footers);
6167
}
6268

63-
if (\cli\Shell::isPiped()) {
64-
$this->setRenderer(new \cli\table\Tabular());
69+
if (Shell::isPiped()) {
70+
$this->setRenderer(new Tabular());
6571
} else {
66-
$this->setRenderer(new \cli\table\Ascii());
72+
$this->setRenderer(new Ascii());
6773
}
6874
}
6975

@@ -84,7 +90,7 @@ public function resetTable()
8490
* @see table\Ascii
8591
* @see table\Tabular
8692
*/
87-
public function setRenderer(table\Renderer $renderer) {
93+
public function setRenderer(Renderer $renderer) {
8894
$this->_renderer = $renderer;
8995
}
9096

@@ -120,25 +126,25 @@ public function display() {
120126
$border = $this->_renderer->border();
121127

122128
if (isset($border)) {
123-
\cli\line($border);
129+
Streams::line($border);
124130
}
125-
\cli\line($this->_renderer->row($this->_headers));
131+
Streams::line($this->_renderer->row($this->_headers));
126132
if (isset($border)) {
127-
\cli\line($border);
133+
Streams::line($border);
128134
}
129135

130136
foreach ($this->_rows as $row) {
131-
\cli\line($this->_renderer->row($row));
137+
Streams::line($this->_renderer->row($row));
132138
}
133139

134140
if (isset($border)) {
135-
\cli\line($border);
141+
Streams::line($border);
136142
}
137143

138144
if ($this->_footers) {
139-
\cli\line($this->_renderer->row($this->_footers));
145+
Streams::line($this->_renderer->row($this->_footers));
140146
if (isset($border)) {
141-
\cli\line($border);
147+
Streams::line($border);
142148
}
143149
}
144150

lib/cli/notify/Dots.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace cli\notify;
1414

1515
use cli\Notify;
16+
use cli\Streams;
1617

1718
/**
1819
* A Notifer that displays a string of periods.
@@ -28,7 +29,7 @@ class Dots extends Notify {
2829
* @param string $msg The text to display next to the Notifier.
2930
* @param int $dots The number of dots to iterate through.
3031
* @param int $interval The interval in milliseconds between updates.
31-
* @throws \InvalidArgumentException
32+
* @throws \InvalidArgumentException
3233
*/
3334
public function __construct($msg, $dots = 3, $interval = 100) {
3435
parent::__construct($msg, $interval);
@@ -60,6 +61,6 @@ public function display($finish = false) {
6061
$speed = number_format(round($this->speed()));
6162
$elapsed = $this->formatTime($this->elapsed());
6263

63-
\cli\out_padded($this->_format, compact('msg', 'dots', 'speed', 'elapsed'));
64+
Streams::out_padded($this->_format, compact('msg', 'dots', 'speed', 'elapsed'));
6465
}
6566
}

lib/cli/notify/Spinner.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace cli\notify;
1414

1515
use cli\Notify;
16+
use cli\Streams;
1617

1718
/**
1819
* The `Spinner` Notifier displays an ASCII spinner.
@@ -39,6 +40,6 @@ public function display($finish = false) {
3940
$speed = number_format(round($this->speed()));
4041
$elapsed = $this->formatTime($this->elapsed());
4142

42-
\cli\out_padded($this->_format, compact('msg', 'char', 'elapsed', 'speed'));
43+
Streams::out_padded($this->_format, compact('msg', 'char', 'elapsed', 'speed'));
4344
}
4445
}

lib/cli/progress/Bar.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use cli;
1616
use cli\Progress;
1717
use cli\Shell;
18+
use cli\Streams;
1819

1920
/**
2021
* Displays a progress bar spanning the entire shell.
@@ -47,11 +48,11 @@ public function display($finish = false) {
4748

4849
$percent = str_pad(floor($_percent * 100), 3);;
4950
$msg = $this->_message;
50-
$msg = cli\render($this->_formatMessage, compact('msg', 'percent'));
51+
$msg = Streams::render($this->_formatMessage, compact('msg', 'percent'));
5152

5253
$estimated = $this->formatTime($this->estimated());
5354
$elapsed = str_pad($this->formatTime($this->elapsed()), strlen($estimated));
54-
$timing = cli\render($this->_formatTiming, compact('elapsed', 'estimated'));
55+
$timing = Streams::render($this->_formatTiming, compact('elapsed', 'estimated'));
5556

5657
$size = Shell::columns();
5758
$size -= strlen($msg . $timing);
@@ -60,6 +61,6 @@ public function display($finish = false) {
6061
// substr is needed to trim off the bar cap at 100%
6162
$bar = substr(str_pad($bar, $size, ' '), 0, $size);
6263

63-
cli\out($this->_format, compact('msg', 'bar', 'timing'));
64+
Streams::out($this->_format, compact('msg', 'bar', 'timing'));
6465
}
6566
}

lib/cli/table/Ascii.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212

1313
namespace cli\table;
14+
1415
use cli\Colors;
1516

1617
/**

0 commit comments

Comments
 (0)