Page MenuHomeDevCentral

No OneTemporary

diff --git a/commands/LICENSE b/commands/LICENSE
index f9ea06a..f55a2bc 100644
--- a/commands/LICENSE
+++ b/commands/LICENSE
@@ -1,23 +1,23 @@
-Copyright (c) 2002, 2010, 2018 Sébastien Santoro aka Dereckson
+Copyright (c) 2002, 2010, 2018, 2022 Sébastien Santoro aka Dereckson
Some rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/commands/composer.json b/commands/composer.json
index 66647dc..7ae3417 100644
--- a/commands/composer.json
+++ b/commands/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/commands/src/Command.php b/commands/src/Command.php
index 76750db..8dbc082 100644
--- a/commands/src/Command.php
+++ b/commands/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/commands/src/Display/ArrayDisplay.php b/commands/src/Display/ArrayDisplay.php
index 5cc1e16..e92bf92 100644
--- a/commands/src/Display/ArrayDisplay.php
+++ b/commands/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
Wed, Oct 22, 12:53 (1 d, 11 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3092180
Default Alt Text
(6 KB)

Event Timeline