Skip to content

Commit 4f8ddb5

Browse files
authored
Merge pull request #66 from adhocore/php8
PHP8
2 parents e2e06d0 + b9c8910 commit 4f8ddb5

28 files changed

+212
-590
lines changed

.travis.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
language: php
22

33
php:
4-
- 7.0
5-
- 7.1
6-
- 7.2
7-
- 7.3
8-
- 7.4
4+
- 8.0
5+
- 8.1
96

107
install:
118
- composer install --prefer-dist

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Command line interface library for PHP",
44
"type": "library",
55
"keywords": [
6-
"php7",
6+
"php8",
77
"command",
88
"argv-parser",
99
"cli",
@@ -37,10 +37,10 @@
3737
}
3838
},
3939
"require": {
40-
"php": ">=7.0"
40+
"php": ">=8.0"
4141
},
4242
"require-dev": {
43-
"phpunit/phpunit": "^6.0"
43+
"phpunit/phpunit": "^9.0"
4444
},
4545
"scripts": {
4646
"test": "phpunit",

src/Application.php

Lines changed: 14 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -27,49 +27,34 @@
2727
class Application
2828
{
2929
/** @var Command[] */
30-
protected $commands = [];
30+
protected array $commands = [];
3131

3232
/** @var array Raw argv sent to parse() */
33-
protected $argv = [];
33+
protected array $argv = [];
3434

3535
/** @var array Command aliases [alias => cmd] */
36-
protected $aliases = [];
37-
38-
/** @var string */
39-
protected $name;
40-
41-
/** @var string App version */
42-
protected $version = '';
36+
protected array $aliases = [];
4337

4438
/** @var string Ascii art logo */
45-
protected $logo = '';
39+
protected string $logo = '';
4640

47-
protected $default = '__default__';
41+
protected string $default = '__default__';
4842

4943
/** @var Interactor */
50-
protected $io;
44+
protected Interactor $io;
5145

5246
/** @var callable The callable to perform exit */
5347
protected $onExit;
5448

55-
public function __construct(string $name, string $version = '0.0.1', callable $onExit = null)
49+
public function __construct(protected string $name, protected string $version = '0.0.1', callable $onExit = null)
5650
{
57-
$this->name = $name;
58-
$this->version = $version;
59-
60-
// @codeCoverageIgnoreStart
61-
$this->onExit = $onExit ?? function ($exitCode = 0) {
62-
exit($exitCode);
63-
};
64-
// @codeCoverageIgnoreEnd
51+
$this->onExit = $onExit ?? fn (int $exitCode = 0) => exit($exitCode);
6552

6653
$this->command('__default__', 'Default command', '', true)->on([$this, 'showHelp'], 'help');
6754
}
6855

6956
/**
7057
* Get the name.
71-
*
72-
* @return string
7358
*/
7459
public function name(): string
7560
{
@@ -78,8 +63,6 @@ public function name(): string
7863

7964
/**
8065
* Get the version.
81-
*
82-
* @return string
8366
*/
8467
public function version(): string
8568
{
@@ -102,8 +85,6 @@ public function commands(): array
10285

10386
/**
10487
* Get the raw argv.
105-
*
106-
* @return array
10788
*/
10889
public function argv(): array
10990
{
@@ -130,14 +111,6 @@ public function logo(string $logo = null)
130111

131112
/**
132113
* Add a command by its name desc alias etc.
133-
*
134-
* @param string $name
135-
* @param string $desc
136-
* @param string $alias
137-
* @param bool $allowUnknown
138-
* @param bool $default
139-
*
140-
* @return Command
141114
*/
142115
public function command(
143116
string $name,
@@ -155,12 +128,6 @@ public function command(
155128

156129
/**
157130
* Add a prepred command.
158-
*
159-
* @param Command $command
160-
* @param string $alias
161-
* @param bool $default
162-
*
163-
* @return self
164131
*/
165132
public function add(Command $command, string $alias = '', bool $default = false): self
166133
{
@@ -192,17 +159,13 @@ public function add(Command $command, string $alias = '', bool $default = false)
192159

193160
/**
194161
* Gets matching command for given argv.
195-
*
196-
* @param array $argv
197-
*
198-
* @return Command
199162
*/
200163
public function commandFor(array $argv): Command
201164
{
202165
$argv += [null, null, null];
203166

204167
return
205-
// cmd
168+
// cmd
206169
$this->commands[$argv[1]]
207170
// cmd alias
208171
?? $this->commands[$this->aliases[$argv[1]] ?? null]
@@ -262,12 +225,8 @@ public function parse(array $argv): Command
262225

263226
/**
264227
* Handle the request, invoke action and call exit handler.
265-
*
266-
* @param array $argv
267-
*
268-
* @return mixed
269228
*/
270-
public function handle(array $argv)
229+
public function handle(array $argv): mixed
271230
{
272231
if (\count($argv) < 2) {
273232
return $this->showHelp();
@@ -288,10 +247,6 @@ public function handle(array $argv)
288247

289248
/**
290249
* Get aliases for given command.
291-
*
292-
* @param Command $command
293-
*
294-
* @return array
295250
*/
296251
protected function aliasesFor(Command $command): array
297252
{
@@ -309,10 +264,8 @@ protected function aliasesFor(Command $command): array
309264

310265
/**
311266
* Show help of all commands.
312-
*
313-
* @return mixed
314267
*/
315-
public function showHelp()
268+
public function showHelp(): mixed
316269
{
317270
$writer = $this->io()->writer();
318271
$header = "{$this->name}, version {$this->version}";
@@ -336,12 +289,8 @@ protected function outputHelper(): OutputHelper
336289

337290
/**
338291
* Invoke command action.
339-
*
340-
* @param Command $command
341-
*
342-
* @return mixed
343292
*/
344-
protected function doAction(Command $command)
293+
protected function doAction(Command $command): mixed
345294
{
346295
if ($command->name() === '__default__') {
347296
return $this->notFound();
@@ -351,7 +300,7 @@ protected function doAction(Command $command)
351300
$command->interact($this->io());
352301

353302
if (!$command->action() && !\method_exists($command, 'execute')) {
354-
return;
303+
return null;
355304
}
356305

357306
$params = [];
@@ -368,10 +317,8 @@ protected function doAction(Command $command)
368317

369318
/**
370319
* Command not found handler.
371-
*
372-
* @return mixed
373320
*/
374-
protected function notFound()
321+
protected function notFound(): mixed
375322
{
376323
$available = \array_keys($this->commands() + $this->aliases);
377324
$this->outputHelper()->showCommandNotFound($this->argv[1], $available);

src/Helper/InflectsString.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ trait InflectsString
2323
{
2424
/**
2525
* Convert a string to camel case.
26-
*
27-
* @param string $string
28-
*
29-
* @return string
3026
*/
3127
public function toCamelCase(string $string): string
3228
{
@@ -39,10 +35,6 @@ public function toCamelCase(string $string): string
3935

4036
/**
4137
* Convert a string to capitalized words.
42-
*
43-
* @param string $string
44-
*
45-
* @return string
4638
*/
4739
public function toWords(string $string): string
4840
{

src/Helper/Normalizer.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ class Normalizer
2626
{
2727
/**
2828
* Normalize argv args. Like splitting `-abc` and `--xyz=...`.
29-
*
30-
* @param array $args
31-
*
32-
* @return array
3329
*/
3430
public function normalizeArgs(array $args): array
3531
{
@@ -53,13 +49,8 @@ public function normalizeArgs(array $args): array
5349

5450
/**
5551
* Normalizes value as per context and runs thorugh filter if possible.
56-
*
57-
* @param Parameter $parameter
58-
* @param string|null $value
59-
*
60-
* @return mixed
6152
*/
62-
public function normalizeValue(Parameter $parameter, string $value = null)
53+
public function normalizeValue(Parameter $parameter, string $value = null): mixed
6354
{
6455
if ($parameter instanceof Option && $parameter->bool()) {
6556
return !$parameter->default();

0 commit comments

Comments
 (0)