Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
17 / 17 |
|
100.00% |
10 / 10 |
CRAP | |
100.00% |
1 / 1 |
| Command | |
100.00% |
17 / 17 |
|
100.00% |
10 / 10 |
13 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| setName | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| setParams | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| setHelp | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getParams | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasParams | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getHelp | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasHelp | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __toString | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Pop PHP Framework (https://www.popphp.org/) |
| 4 | * |
| 5 | * @link https://github.com/popphp/popphp-framework |
| 6 | * @author Nick Sagona, III <dev@noladev.com> |
| 7 | * @copyright Copyright (c) 2009-2026 NOLA Interactive, LLC. |
| 8 | * @license https://www.popphp.org/license New BSD License |
| 9 | */ |
| 10 | |
| 11 | /** |
| 12 | * @namespace |
| 13 | */ |
| 14 | namespace Pop\Console; |
| 15 | |
| 16 | /** |
| 17 | * Console command class |
| 18 | * |
| 19 | * @category Pop |
| 20 | * @package Pop\Console |
| 21 | * @author Nick Sagona, III <dev@noladev.com> |
| 22 | * @copyright Copyright (c) 2009-2026 NOLA Interactive, LLC. |
| 23 | * @license https://www.popphp.org/license New BSD License |
| 24 | * @version 4.2.6 |
| 25 | */ |
| 26 | class Command |
| 27 | { |
| 28 | |
| 29 | /** |
| 30 | * Command name |
| 31 | * @var ?string |
| 32 | */ |
| 33 | protected ?string $name = null; |
| 34 | |
| 35 | /** |
| 36 | * Command params |
| 37 | * @var ?string |
| 38 | */ |
| 39 | protected ?string $params = null; |
| 40 | |
| 41 | /** |
| 42 | * Command help |
| 43 | * @var ?string |
| 44 | */ |
| 45 | protected ?string $help = null; |
| 46 | |
| 47 | /** |
| 48 | * Instantiate the command object |
| 49 | * |
| 50 | * @param string $name |
| 51 | * @param ?string $params |
| 52 | * @param ?string $help |
| 53 | */ |
| 54 | public function __construct(string $name, ?string $params = null, ?string $help = null) |
| 55 | { |
| 56 | $this->setName($name); |
| 57 | if ($params !== null) { |
| 58 | $this->setParams($params); |
| 59 | } |
| 60 | if ($help !== null) { |
| 61 | $this->setHelp($help); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Set the command name |
| 67 | * |
| 68 | * @param string $name |
| 69 | * @return Command |
| 70 | */ |
| 71 | public function setName(string $name): Command |
| 72 | { |
| 73 | $this->name = $name; |
| 74 | return $this; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Set the command params |
| 79 | * |
| 80 | * @param string $params |
| 81 | * @return Command |
| 82 | */ |
| 83 | public function setParams(string $params): Command |
| 84 | { |
| 85 | $this->params = $params; |
| 86 | return $this; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Set the command help |
| 91 | * |
| 92 | * @param string $help |
| 93 | * @return Command |
| 94 | */ |
| 95 | public function setHelp(string $help): Command |
| 96 | { |
| 97 | $this->help = $help; |
| 98 | return $this; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Get the command name |
| 103 | * |
| 104 | * @return ?string |
| 105 | */ |
| 106 | public function getName(): ?string |
| 107 | { |
| 108 | return $this->name; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Get the command params |
| 113 | * |
| 114 | * @return ?string |
| 115 | */ |
| 116 | public function getParams(): ?string |
| 117 | { |
| 118 | return $this->params; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Determine if the command has params |
| 123 | * |
| 124 | * @return bool |
| 125 | */ |
| 126 | public function hasParams(): bool |
| 127 | { |
| 128 | return (null !== $this->params); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Get the command help |
| 133 | * |
| 134 | * @return ?string |
| 135 | */ |
| 136 | public function getHelp(): ?string |
| 137 | { |
| 138 | return $this->help; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Determine if the command has help |
| 143 | * |
| 144 | * @return bool |
| 145 | */ |
| 146 | public function hasHelp(): bool |
| 147 | { |
| 148 | return (null !== $this->help); |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * Return the command name as string |
| 153 | * |
| 154 | * @return string |
| 155 | */ |
| 156 | public function __toString(): string |
| 157 | { |
| 158 | return $this->name . ((null !== $this->params) ? ' ' . $this->params : null); |
| 159 | } |
| 160 | |
| 161 | } |