Skip to content

Commit 9cc675a

Browse files
committed
up: AbstractHandler add new prop:desc instead the prop:description
1 parent a254803 commit 9cc675a

File tree

5 files changed

+25
-17
lines changed

5 files changed

+25
-17
lines changed

src/Concern/ApplicationHelpTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public function showCommandList(): void
218218
$options = $info['options'];
219219
$controller = $info['handler'];
220220
/** @var AbstractHandler $controller */
221-
$desc = $controller::getDescription() ?: $placeholder;
221+
$desc = $controller::getDesc() ?: $placeholder;
222222
$aliases = $options['aliases'];
223223
$extra = $aliases ? ColorTag::wrap(' (alias: ' . implode(',', $aliases) . ')', 'info') : '';
224224

@@ -237,7 +237,7 @@ public function showCommandList(): void
237237

238238
/** @var AbstractHandler $command */
239239
if (is_subclass_of($command, CommandInterface::class)) {
240-
$desc = $command::getDescription() ?: $placeholder;
240+
$desc = $command::getDesc() ?: $placeholder;
241241
} elseif ($msg = $options['desc'] ?? '') {
242242
$desc = $msg;
243243
} elseif (is_string($command)) {

src/Concern/ControllerHelpTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function showCommandList(): void
9999
$ref = new ReflectionClass($this);
100100
$sName = lcfirst(self::getName() ?: $ref->getShortName());
101101

102-
if (!($classDes = self::getDescription())) {
102+
if (!($classDes = self::getDesc())) {
103103
$classDes = PhpDoc::description($ref->getDocComment()) ?: 'No description for the command group';
104104
}
105105

src/Controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ protected function getAllCommandMethods(ReflectionClass $ref = null, bool $onlyN
556556
* @param string $name
557557
*
558558
* @return string
559-
* @description please use resolveAlias()
559+
* @deprecated please use resolveAlias()
560560
*/
561561
public function getRealCommandName(string $name): string
562562
{

src/Handler/AbstractHandler.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ abstract class AbstractHandler implements CommandHandlerInterface
6666
*
6767
* @var string
6868
*/
69+
protected static $desc = '';
70+
71+
/**
72+
* command/controller description message
73+
*
74+
* @var string
75+
* @deprecated please use {@see $desc}
76+
*/
6977
protected static $description = '';
7078

7179
/**
@@ -614,33 +622,33 @@ final public static function getName(): string
614622
*/
615623
public static function getDesc(): string
616624
{
617-
return static::$description;
625+
return static::$desc ?: static::$description;
618626
}
619627

620628
/**
621-
* @return string
629+
* @param string $desc
622630
*/
623-
public static function getDescription(): string
631+
public static function setDesc(string $desc): void
624632
{
625-
return static::$description;
633+
if ($desc) {
634+
static::$desc = $desc;
635+
}
626636
}
627637

628638
/**
629-
* @param string $desc
639+
* @return string
630640
*/
631-
public static function setDesc(string $desc): void
641+
public static function getDescription(): string
632642
{
633-
self::setDescription($desc);
643+
return self::getDesc();
634644
}
635645

636646
/**
637-
* @param string $description
647+
* @param string $desc
638648
*/
639-
public static function setDescription(string $description): void
649+
public static function setDescription(string $desc): void
640650
{
641-
if ($description) {
642-
static::$description = $description;
643-
}
651+
self::setDesc($desc);
644652
}
645653

646654
/**

test/CommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ public function testBasic(): void
2424
$c = new TestCommand(new Input(), new Output());
2525

2626
$this->assertSame('test1', $c::getName());
27-
$this->assertStringContainsString('desc', $c::getDescription());
27+
$this->assertStringContainsString('desc', $c::getDesc());
2828
}
2929
}

0 commit comments

Comments
 (0)