Skip to content

Commit 947a726

Browse files
author
Ryan
committed
Fix most of the namespaces and phpdocs
1 parent df851e9 commit 947a726

11 files changed

+49
-39
lines changed

http-console.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
* An example application using php-cli-tools and Buzz
44
*/
55

6+
require_once __DIR__ . '/vendor/autoload.php';
7+
68
define('BUZZ_PATH', realpath('../Buzz'));
7-
define('TOOL_PATH', realpath('./'));
89
define('SCRIPT_NAME', array_shift($argv));
910

1011
require_once BUZZ_PATH . '/lib/Buzz/ClassLoader.php';
1112
Buzz\ClassLoader::register();
1213

13-
require_once TOOL_PATH . '/lib/cli/cli.php';
14-
\cli\register_autoload();
15-
1614
class HttpConsole {
1715
protected $_host;
1816
protected $_prompt;

lib/cli/Arguments.php

+10-15
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@
1212

1313
namespace cli;
1414

15-
require 'lib/cli/Memoize.php';
16-
require 'lib/cli/arguments/Argument.php';
17-
require 'lib/cli/arguments/HelpScreen.php';
18-
require 'lib/cli/arguments/InvalidArguments.php';
19-
require 'lib/cli/arguments/Lexer.php';
20-
2115
/**
2216
* Parses command line arguments.
2317
*/
@@ -69,7 +63,7 @@ public function getArguments() {
6963
}
7064

7165
public function getHelpScreen() {
72-
return new \cli\arguments\HelpScreen($this);
66+
return new arguments\HelpScreen($this);
7367
}
7468

7569
/**
@@ -88,7 +82,7 @@ public function asJSON() {
8882
* @return bool
8983
*/
9084
public function offsetExists($offset) {
91-
if ($offset instanceOf \cli\arguments\Argument) {
85+
if ($offset instanceOf arguments\Argument) {
9286
$offset = $offset->key;
9387
}
9488

@@ -102,7 +96,7 @@ public function offsetExists($offset) {
10296
* @return mixed
10397
*/
10498
public function offsetGet($offset) {
105-
if ($offset instanceOf \cli\arguments\Argument) {
99+
if ($offset instanceOf arguments\Argument) {
106100
$offset = $offset->key;
107101
}
108102

@@ -118,7 +112,7 @@ public function offsetGet($offset) {
118112
* @param mixed $value The value to set
119113
*/
120114
public function offsetSet($offset, $value) {
121-
if ($offset instanceOf \cli\arguments\Argument) {
115+
if ($offset instanceOf arguments\Argument) {
122116
$offset = $offset->key;
123117
}
124118

@@ -131,7 +125,7 @@ public function offsetSet($offset, $value) {
131125
* @param mixed $offset An Argument object or the name of the argument.
132126
*/
133127
public function offsetUnset($offset) {
134-
if ($offset instanceOf \cli\arguments\Argument) {
128+
if ($offset instanceOf arguments\Argument) {
135129
$offset = $offset->key;
136130
}
137131

@@ -197,7 +191,7 @@ public function addFlags($flags) {
197191
/**
198192
* Adds an option (string argument) to the argument list.
199193
*
200-
* @param mixed $flag A string representing the option, or an array of strings.
194+
* @param mixed $option A string representing the option, or an array of strings.
201195
* @param array $settings An array of settings for this option.
202196
* @setting string description A description to be shown in --help.
203197
* @setting bool default The default value for this option.
@@ -341,7 +335,7 @@ public function isStackable($flag) {
341335
* @return array
342336
*/
343337
public function getOption($option) {
344-
if ($option instanceOf \cli\arguments\Argument) {
338+
if ($option instanceOf arguments\Argument) {
345339
$obj = $option;
346340
$option = $option->value;
347341
}
@@ -386,11 +380,12 @@ public function isOption($argument) {
386380
* if a long name is not given.
387381
*
388382
* @return array
383+
* @throws arguments\InvalidArguments
389384
*/
390385
public function parse() {
391386
$this->_invalid = array();
392387
$this->_parsed = array();
393-
$this->_lexer = new \cli\arguments\Lexer($this->_input);
388+
$this->_lexer = new arguments\Lexer($this->_input);
394389

395390
foreach ($this->_lexer as $argument) {
396391
if ($this->_parseFlag($argument)) {
@@ -404,7 +399,7 @@ public function parse() {
404399
}
405400

406401
if ($this->_strict && !empty($this->_invalid)) {
407-
throw new \cli\arguments\InvalidArguments($this->_invalid);
402+
throw new arguments\InvalidArguments($this->_invalid);
408403
}
409404
}
410405

lib/cli/Colors.php

+5
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ static public function shouldColorize($colored = null) {
7474
* Set the color.
7575
*
7676
* @param string $color The name of the color or style to set.
77+
* @return string
7778
*/
7879
static public function color($color) {
7980
if (!is_array($color)) {
@@ -105,7 +106,9 @@ static public function color($color) {
105106
* Colorize a string using helpful string formatters. If the `Streams::$out` points to a TTY coloring will be enabled,
106107
* otherwise disabled. You can control this check with the `$colored` parameter.
107108
*
109+
* @param string $string
108110
* @param boolean $colored Force enable or disable the colorized output. If left as `null` the TTY will control coloring.
111+
* @return string
109112
*/
110113
static public function colorize($string, $colored = null) {
111114
static $conversions = array(
@@ -161,6 +164,7 @@ static public function colorize($string, $colored = null) {
161164
* Return the length of the string without color codes.
162165
*
163166
* @param string $string the string to measure
167+
* @return string
164168
*/
165169
static public function length($string) {
166170
return strlen(self::colorize($string, false));
@@ -171,6 +175,7 @@ static public function length($string) {
171175
*
172176
* @param string $string the string to pad
173177
* @param integer $length the display length
178+
* @return string
174179
*/
175180
static public function pad($string, $length) {
176181
$real_length = strlen($string);

lib/cli/Notify.php

-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ public function speed() {
117117
* @return string The formatted time span.
118118
*/
119119
public function formatTime($time) {
120-
$minutes = $time / 60;
121-
$seconds = $time % 60;
122120
return floor($time / 60) . ':' . str_pad($time % 60, 2, 0, STR_PAD_LEFT);
123121
}
124122

lib/cli/arguments/Argument.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212

1313
namespace cli\arguments;
1414

15+
use cli\Memoize;
16+
1517
/**
1618
* Represents an Argument or a value and provides several helpers related to parsing an argument list.
1719
*/
18-
class Argument extends \cli\Memoize {
20+
class Argument extends Memoize {
1921
/**
2022
* The canonical name of this argument, used for aliasing.
2123
*

lib/cli/arguments/HelpScreen.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
namespace cli\arguments;
1414

15+
use cli\Arguments;
16+
1517
/**
1618
* Arguments help screen renderer
1719
*/
@@ -21,27 +23,27 @@ class HelpScreen {
2123
protected $_options = array();
2224
protected $_maxOption = 0;
2325

24-
public function __construct(\cli\Arguments $arguments) {
26+
public function __construct(Arguments $arguments) {
2527
$this->setArguments($arguments);
2628
}
2729

2830
public function __toString() {
2931
return $this->render();
3032
}
3133

32-
public function setArguments(\cli\Arguments $arguments) {
34+
public function setArguments(Arguments $arguments) {
3335
$this->consumeArgumentFlags($arguments);
3436
$this->consumeArgumentOptions($arguments);
3537
}
3638

37-
public function consumeArgumentFlags(\cli\Arguments $arguments) {
39+
public function consumeArgumentFlags(Arguments $arguments) {
3840
$data = $this->_consume($arguments->getFlags());
3941

4042
$this->_flags = $data[0];
4143
$this->_flagMax = $data[1];
4244
}
4345

44-
public function consumeArgumentOptions(\cli\Arguments $arguments) {
46+
public function consumeArgumentOptions(Arguments $arguments) {
4547
$data = $this->_consume($arguments->getOptions());
4648

4749
$this->_options = $data[0];

lib/cli/arguments/Lexer.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
namespace cli\arguments;
1414

15-
class Lexer extends \cli\Memoize implements \Iterator {
15+
use cli\Memoize;
16+
17+
class Lexer extends Memoize implements \Iterator {
1618
private $_items = array();
1719
private $_index = 0;
1820
private $_length = 0;
@@ -37,10 +39,10 @@ public function current() {
3739
/**
3840
* Peek ahead to the next token without moving the cursor.
3941
*
40-
* @return cli\arguments\Argument
42+
* @return Argument
4143
*/
4244
public function peek() {
43-
return new \cli\arguments\Argument($this->_items[0]);
45+
return new Argument($this->_items[0]);
4446
}
4547

4648
/**
@@ -103,7 +105,7 @@ public function end() {
103105
}
104106

105107
private function _shift() {
106-
$this->_item = new \cli\arguments\Argument(array_shift($this->_items));
108+
$this->_item = new Argument(array_shift($this->_items));
107109
$this->_index += 1;
108110
$this->_explode();
109111
$this->_unmemo('peek');

lib/cli/notify/Dots.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212

1313
namespace cli\notify;
1414

15+
use cli\Notify;
16+
1517
/**
1618
* A Notifer that displays a string of periods.
1719
*/
18-
class Dots extends \cli\Notify {
20+
class Dots extends Notify {
1921
protected $_dots;
2022
protected $_format = '{:msg}{:dots} ({:elapsed}, {:speed}/s)';
2123
protected $_iteration;
@@ -26,6 +28,7 @@ class Dots extends \cli\Notify {
2628
* @param string $msg The text to display next to the Notifier.
2729
* @param int $dots The number of dots to iterate through.
2830
* @param int $interval The interval in milliseconds between updates.
31+
* @throws \InvalidArgumentException
2932
*/
3033
public function __construct($msg, $dots = 3, $interval = 100) {
3134
parent::__construct($msg, $interval);

lib/cli/notify/Spinner.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212

1313
namespace cli\notify;
1414

15+
use cli\Notify;
16+
1517
/**
1618
* The `Spinner` Notifier displays an ASCII spinner.
1719
*/
18-
class Spinner extends \cli\Notify {
20+
class Spinner extends Notify {
1921
protected $_chars = '-\|/';
2022
protected $_format = '{:msg} {:char} ({:elapsed}, {:speed}/s)';
2123
protected $_iteration = 0;

lib/cli/progress/Bar.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212

1313
namespace cli\progress;
1414

15+
use cli;
16+
1517
/**
1618
* Displays a progress bar spanning the entire shell.
1719
*
1820
* Basic format:
1921
*
2022
* ^MSG PER% [======================= ] 00:00 / 00:00$
2123
*/
22-
class Bar extends \cli\Progress {
24+
class Bar extends Progress {
2325
protected $_bars = '=>';
2426
protected $_formatMessage = '{:msg} {:percent}% [';
2527
protected $_formatTiming = '] {:elapsed} / {:estimated}';
@@ -43,19 +45,19 @@ public function display($finish = false) {
4345

4446
$percent = str_pad(floor($_percent * 100), 3);;
4547
$msg = $this->_message;
46-
$msg = \cli\render($this->_formatMessage, compact('msg', 'percent'));
48+
$msg = cli\render($this->_formatMessage, compact('msg', 'percent'));
4749

4850
$estimated = $this->formatTime($this->estimated());
4951
$elapsed = str_pad($this->formatTime($this->elapsed()), strlen($estimated));
50-
$timing = \cli\render($this->_formatTiming, compact('elapsed', 'estimated'));
52+
$timing = cli\render($this->_formatTiming, compact('elapsed', 'estimated'));
5153

52-
$size = \cli\Shell::columns();
54+
$size = cli\Shell::columns();
5355
$size -= strlen($msg . $timing);
5456

5557
$bar = str_repeat($this->_bars[0], floor($_percent * $size)) . $this->_bars[1];
5658
// substr is needed to trim off the bar cap at 100%
5759
$bar = substr(str_pad($bar, $size, ' '), 0, $size);
5860

59-
\cli\out($this->_format, compact('msg', 'bar', 'timing'));
61+
cli\out($this->_format, compact('msg', 'bar', 'timing'));
6062
}
6163
}

lib/cli/table/Ascii.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212

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

1516
/**
1617
* The ASCII renderer renders tables with ASCII borders.
@@ -63,10 +64,10 @@ public function row(array $row) {
6364
array_unshift($row, ''); // First border
6465
array_push($row, ''); // Last border
6566

66-
return join($this->_characters['border'], $row);
67+
return join($this->_characters['border'], $row);
6768
}
6869

6970
private function padColumn($content, $column) {
70-
return ' ' . \cli\Colors::pad($content, $this->_widths[$column]) . ' ';
71+
return ' ' . Colors::pad($content, $this->_widths[$column]) . ' ';
7172
}
7273
}

0 commit comments

Comments
 (0)