Skip to content

Commit ee112c0

Browse files
committed
Updated for PHP7.2+
1 parent 93a4250 commit ee112c0

File tree

6 files changed

+26
-26
lines changed

6 files changed

+26
-26
lines changed

composer.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
"authors": [
77
{
88
"name": "Alannah Kearney",
9-
"email": "alannah@ruleandmake.com"
9+
"email": "hi@alannahkearney.com"
1010
}
1111
],
1212
"autoload": {
1313
"psr-4": {
1414
"CLILib\\": "src/CLILib"
1515
}
1616
},
17-
"minimum-stability": "dev",
17+
"minimum-stability": "stable",
1818
"require": {
19-
"php": "^5.6"
19+
"php": ">=7.2"
2020
},
2121
"require-dev": {
22-
"phpunit/phpunit": "^5"
22+
"phpunit/phpunit": "^8"
2323
}
2424
}

src/CLILib/Argument.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function __construct($name, $value)
1717
*
1818
* @return string
1919
*/
20-
public function name()
20+
public function name() : string
2121
{
2222
return $this->name;
2323
}

src/CLILib/Argument/Iterator.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function __construct(array $args = null, $ignoreFirst = true)
6565
* @param string|array $name
6666
* @return array
6767
*/
68-
public function find($names)
68+
public function find($names) : ?CLILib\Argument
6969
{
7070
if (!is_array($names)) {
7171
$names = [$names];
@@ -77,35 +77,35 @@ public function find($names)
7777
};
7878
}
7979

80-
return false;
80+
return null;
8181
}
8282

83-
public function rewind()
83+
public function rewind() : void
8484
{
8585
$this->position = 0;
8686
}
8787

88-
public function current()
88+
public function current() : CLILib\Argument
8989
{
9090
return $this->args[$this->position];
9191
}
9292

93-
public function key()
93+
public function key() : int
9494
{
9595
return $this->position;
9696
}
9797

98-
public function next()
98+
public function next() : void
9999
{
100100
++$this->position;
101101
}
102102

103-
public function valid()
103+
public function valid() : bool
104104
{
105105
return isset($this->args[$this->position]);
106106
}
107107

108-
public function count()
108+
public function count() : int
109109
{
110110
return count($this->keys);
111111
}

src/CLILib/Message.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ public function __construct($message = null)
6464
$this->dateFormat("H:i:s > ");
6565
}
6666

67-
public function message($message)
67+
public function message($message) : self
6868
{
6969
$this->message = $message;
7070
return $this;
7171
}
7272

73-
public function foreground($colour)
73+
public function foreground($colour) : self
7474
{
7575
if (!is_null($colour) && !array_key_exists($colour, self::$foregroundColours)) {
7676
throw new \Exception('No such foreground colour `'.$colour.'`');
@@ -79,7 +79,7 @@ public function foreground($colour)
7979
return $this;
8080
}
8181

82-
public function background($colour)
82+
public function background($colour) : self
8383
{
8484
if (!is_null($colour) && !array_key_exists($colour, self::$backgroundColours)) {
8585
throw new \Exception('No such background colour `'.$colour.'`');
@@ -88,25 +88,25 @@ public function background($colour)
8888
return $this;
8989
}
9090

91-
public function prependDate($prependDate)
91+
public function prependDate($prependDate) : self
9292
{
9393
$this->prependDate = $prependDate;
9494
return $this;
9595
}
9696

97-
public function dateFormat($format)
97+
public function dateFormat($format) : self
9898
{
9999
$this->dateFormat = $format;
100100
return $this;
101101
}
102102

103-
public function appendNewLine($appendNewLine)
103+
public function appendNewLine($appendNewLine) : self
104104
{
105105
$this->appendNewLine = $appendNewLine;
106106
return $this;
107107
}
108108

109-
public function display($target=STDOUT)
109+
public function display($target=STDOUT) : bool
110110
{
111111
return fputs($target, (string)$this);
112112
}

src/CLILib/Prompt.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Prompt
1010
*
1111
* @return boolean true if the flag is set
1212
*/
13-
protected static function isFlagSet($flags, $flag)
13+
protected static function isFlagSet($flags, $flag) : bool
1414
{
1515
// Flags support bitwise operators so it's easy to see
1616
// if one has been set.
@@ -34,7 +34,7 @@ protected static function isFlagSet($flags, $flag)
3434
* for passwords. Only works if bash is avilable.
3535
* @return string
3636
*/
37-
public static function display($prompt, $flags = null, $default = null, \Closure $validator = null, $character = ":", $target=STDIN)
37+
public static function display($prompt, $flags = null, $default = null, \Closure $validator = null, $character = ":", $target=STDIN) : string
3838
{
3939
$silent = self::isFlagSet($flags, self::FLAG_SILENT);
4040

@@ -90,7 +90,7 @@ public static function display($prompt, $flags = null, $default = null, \Closure
9090
*
9191
* @return bool
9292
*/
93-
protected static function canInvokeBash()
93+
protected static function canInvokeBash() : bool
9494
{
9595
return (strcmp(trim(shell_exec("/usr/bin/env bash -c 'echo OK'")), 'OK') === 0);
9696
}

tests/Argument/Iterator/Test.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function testValidPassArgsToConstructor()
4949
public function testEmptyArgumentArray()
5050
{
5151
$it = new Iterator([], false);
52-
$this->assertFalse($it->find('hithere'));
52+
$this->assertNull($it->find('hithere'));
5353
$this->assertEquals(0, $it->count());
5454
}
5555

@@ -63,7 +63,7 @@ public function testValidIgnoreFirstArg()
6363
'--hithere',
6464
]);
6565
$this->assertEquals(1, iterator_count($it));
66-
$this->assertFalse($it->find('../blah/blah'));
66+
$this->assertNull($it->find('../blah/blah'));
6767
}
6868

6969
/**
@@ -117,6 +117,6 @@ public function testValidFindArgumentArray()
117117
*/
118118
public function testInvalidFindArgumentArray($it)
119119
{
120-
$this->assertFalse($it->find(['f', 'file']));
120+
$this->assertNull($it->find(['f', 'file']));
121121
}
122122
}

0 commit comments

Comments
 (0)