Skip to content

Commit

Permalink
added PHP 7.1 scalar and return type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Feb 5, 2019
1 parent d6c99cc commit bc2b262
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/CommandLine/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public function __construct()
}


public function useColors($state = true)
public function useColors(bool $state = true): void
{
$this->useColors = (bool) $state;
$this->useColors = $state;
}


public function color($color = null, $s = null)
public function color(?string $color, string $s = null): string
{
static $colors = [
'black' => '0;30', 'gray' => '1;30', 'silver' => '0;37', 'white' => '1;37',
Expand All @@ -40,13 +40,13 @@ public function color($color = null, $s = null)
null => '0',
];
if ($this->useColors) {
$c = explode('/', $color);
$c = explode('/', $color ?: '/');
return "\033["
. ($c[0] ? $colors[$c[0]] : '')
. (empty($c[1]) ? '' : ';4' . substr($colors[$c[1]], -1))
. 'm' . $s
. ($s === null ? '' : "\033[0m");
}
return $s;
return (string) $s;
}
}
10 changes: 5 additions & 5 deletions src/CommandLine/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Parser
private $help;


public function __construct($help, array $defaults = [])
public function __construct(string $help, array $defaults = [])
{
$this->help = $help;
$this->options = $defaults;
Expand Down Expand Up @@ -68,7 +68,7 @@ public function __construct($help, array $defaults = [])
}


public function parse(array $args = null)
public function parse(array $args = null): array
{
if ($args === null) {
$args = isset($_SERVER['argv']) ? array_slice($_SERVER['argv'], 1) : [];
Expand Down Expand Up @@ -145,13 +145,13 @@ public function parse(array $args = null)
}


public function help()
public function help(): void
{
echo $this->help;
}


public function checkArg(array $opt, &$arg)
public function checkArg(array $opt, &$arg): void
{
if (!empty($opt[self::REALPATH])) {
$path = realpath($arg);
Expand All @@ -163,7 +163,7 @@ public function checkArg(array $opt, &$arg)
}


public function isEmpty()
public function isEmpty(): bool
{
return !isset($_SERVER['argv']) || count($_SERVER['argv']) < 2;
}
Expand Down

0 comments on commit bc2b262

Please sign in to comment.