Page MenuHomeDevCentral

No OneTemporary

diff --git a/composer.json b/composer.json
index 66647dc..7ae3417 100644
--- a/composer.json
+++ b/composer.json
@@ -1,25 +1,25 @@
{
"name": "keruald/commands",
"description": "Classes to build CLI commands",
"type": "library",
"license": "BSD-2-Clause",
"authors": [
{
"name": "Sébastien Santoro",
"email": "dereckson@espace-win.org"
}
],
"autoload": {
"psr-4": {
"Keruald\\Commands\\": "src/",
"Keruald\\Commands\\Tests\\": "tests/"
}
},
"require": {
},
"require-dev": {
- "phan/phan": "^0.12.3",
+ "phan/phan": "^5.3",
"phpunit/phpunit": "^9.5.13",
"squizlabs/php_codesniffer": "^3"
}
}
diff --git a/src/Command.php b/src/Command.php
index 76750db..8dbc082 100644
--- a/src/Command.php
+++ b/src/Command.php
@@ -1,98 +1,94 @@
<?php
namespace Keruald\Commands;
use Keruald\Commands\Display\Display;
use Keruald\Commands\Display\OutputDisplay;
abstract class Command {
- /**
- * @var int
- */
- private $argc;
-
- /**
- * @var array
- */
- private $argv;
-
- /**
- * @var \Keruald\Commands\Display\Display
- */
- protected $display;
+ protected Display $display;
public function __construct (
- int $argc,
- array $argv,
+ public int $argc,
+ public array $argv,
Display $display = null
) {
- $this->argc = $argc;
- $this->argv = $argv;
-
if ($display === null) {
$display = self::getDefaultDisplay();
}
$this->display = $display;
}
public static function run (int $argc, array $argv) : int {
$command = new static($argc, $argv);
return $command->main();
}
///
/// Getters and setters
///
+ /**
+ * @deprecated Use directly Command::$argc
+ */
public function getArgc () : int {
return $this->argc;
}
+ /**
+ * @deprecated Use directly Command::$argc
+ */
public function setArgc (int $argc) : Command {
$this->argc = $argc;
return $this;
}
+ /**
+ * @deprecated Use directly Command::$argv
+ */
public function getArgv () : array {
return $this->argv;
}
+ /**
+ * @deprecated Use directly Command::$argv
+ */
public function setArgv (array $argv) : Command {
$this->argv = $argv;
return $this;
}
public function getCommandName () : string {
return $this->argv[0] ?? "";
}
public function getDisplay () : Display {
return $this->display;
}
public function setDisplay (Display $display) : Command {
$this->display = $display;
return $this;
}
///
/// Helper methods
///
private static function getDefaultDisplay () : Display {
return new OutputDisplay();
}
///
/// Methods to implement
///
public abstract function main () : int;
}
diff --git a/src/Display/ArrayDisplay.php b/src/Display/ArrayDisplay.php
index 5cc1e16..e92bf92 100644
--- a/src/Display/ArrayDisplay.php
+++ b/src/Display/ArrayDisplay.php
@@ -1,72 +1,72 @@
<?php
namespace Keruald\Commands\Display;
/**
* Class ArrayDisplay
*
* Intended to ease unit tests with a display capturing output in arrays.
*
* @package Keruald\Commands\Display
*/
class ArrayDisplay extends Display {
/**
- * @var array
+ * @var string[]
*/
- private $out = [];
+ private array $out = [];
/**
- * @var array
+ * @var string[]
*/
- private $error = [];
+ private array $error = [];
///
/// Implement Display
///
public function out (string $message) : void {
$this->out[] = $message;
}
public function error (string $message) : void {
$this->error[] = $message;
}
///
/// Getters
///
public function getOut () : array {
return $this->out;
}
public function getError () : array {
return $this->error;
}
///
/// Helper methods
///
public function clearOut () : ArrayDisplay {
$this->out = [];
return $this;
}
public function clearError () : ArrayDisplay {
$this->error = [];
return $this;
}
public function countOut () : int {
return count($this->out);
}
public function countError () : int {
return count($this->error);
}
}

File Metadata

Mime Type
text/x-diff
Expires
Thu, Sep 18, 10:03 (18 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2987047
Default Alt Text
(4 KB)

Event Timeline