Skip to content

Commit

Permalink
test: improve codebase for new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed May 8, 2024
1 parent d056bef commit 8c3c47a
Show file tree
Hide file tree
Showing 24 changed files with 194 additions and 162 deletions.
2 changes: 1 addition & 1 deletion phpmd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

<rule ref="rulesets/naming.xml/ShortVariable">
<properties>
<property name="exceptions" value="a,b,i" />
<property name="exceptions" value="a,b,i,in" />
</properties>
</rule>
<rule ref="rulesets/naming.xml/ShortMethodName">
Expand Down
2 changes: 2 additions & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,13 @@ protected function findCommandByName(string $name):Command {
throw new InvalidCommandException($name);
}

/** @SuppressWarnings(PHPMD.ExitExpression) */
private function exit():void {
if(isset($this->exitHandler)) {
call_user_func($this->exitHandler, $this->exitCode);
}
elseif($this->exitCode !== 0) {
// phpcs:ignore
exit($this->exitCode);
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/Argument/ArgumentList.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ public function getCommandName():string {
return $this->argumentList[0]->getValue() ?? "";
}

/** @param string[] $arguments */
/**
* @param string[] $arguments
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function buildArgumentList(array $arguments):void {
if(isset($arguments[0])
&& $arguments[0][0] !== "-") {
Expand Down
2 changes: 1 addition & 1 deletion src/Argument/ArgumentValueListNotSetException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

use Gt\Cli\CliException;

class ArgumentValueListNotSetException extends CliException {}
class ArgumentValueListNotSetException extends CliException {}
3 changes: 2 additions & 1 deletion src/Argument/CommandArgument.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ public function __construct(string $commandName) {
parent::__construct("", $commandName);
}

// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter
protected function processRawKey(string $rawKey): string {
return "";
}
}
}
2 changes: 1 addition & 1 deletion src/Argument/CommandArgumentList.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ public function __construct(
);
parent::__construct($script, ...$commandArguments);
}
}
}
2 changes: 1 addition & 1 deletion src/Argument/DefaultArgumentValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ public function __construct(?string $default) {
parent::__construct("__DEFAULT__");
$this->push($default);
}
}
}
2 changes: 1 addition & 1 deletion src/Argument/LongOptionArgument.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ class LongOptionArgument extends Argument {
protected function processRawKey(string $rawKey):string {
return substr($rawKey, 2);
}
}
}
1 change: 1 addition & 0 deletions src/Argument/NamedArgument.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public function __construct(string $value) {
parent::__construct("", $value);
}

// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter
protected function processRawKey(string $rawKey): string {
return "";
}
Expand Down
2 changes: 1 addition & 1 deletion src/Argument/NamedArgumentValue.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
namespace Gt\Cli\Argument;

class NamedArgumentValue extends ArgumentValue {}
class NamedArgumentValue extends ArgumentValue {}
2 changes: 1 addition & 1 deletion src/Argument/NotEnoughArgumentsException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ class NotEnoughArgumentsException extends CliException {
public function __construct(string $message) {
parent::__construct("Not enough arguments passed. $message.");
}
}
}
2 changes: 1 addition & 1 deletion src/Argument/ShortOptionArgument.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ protected function processRawKey(string $rawKey):string {

return $key;
}
}
}
3 changes: 2 additions & 1 deletion src/CliException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use RuntimeException;

class CliException extends RuntimeException {
/** @SuppressWarnings(PHPMD.StaticAccess) */
public function __construct(string $message) {
$code = ErrorCode::get(get_class($this));

Expand All @@ -12,4 +13,4 @@ public function __construct(string $message) {
$code
);
}
}
}
Loading

0 comments on commit 8c3c47a

Please sign in to comment.