Skip to content

Commit 2583f57

Browse files
authored
Merge pull request #3561 from paulbalandan/basecommand-getpad
Deprecate BaseCommand::getPad and add more tests
2 parents 0978c57 + d4e2c4a commit 2583f57

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

system/CLI/BaseCommand.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ protected function showError(Throwable $e)
171171
public function showHelp()
172172
{
173173
CLI::write(lang('CLI.helpUsage'), 'yellow');
174+
174175
if (! empty($this->usage))
175176
{
176177
$usage = $this->usage;
@@ -184,6 +185,7 @@ public function showHelp()
184185
$usage .= ' [arguments]';
185186
}
186187
}
188+
187189
CLI::write($this->setPad($usage, 0, 0, 2));
188190

189191
if (! empty($this->description))
@@ -198,6 +200,7 @@ public function showHelp()
198200
CLI::newLine();
199201
CLI::write(lang('CLI.helpArguments'), 'yellow');
200202
$length = max(array_map('strlen', array_keys($this->arguments)));
203+
201204
foreach ($this->arguments as $argument => $description)
202205
{
203206
CLI::write(CLI::color($this->setPad($argument, $length, 2, 2), 'green') . $description);
@@ -209,6 +212,7 @@ public function showHelp()
209212
CLI::newLine();
210213
CLI::write(lang('CLI.helpOptions'), 'yellow');
211214
$length = max(array_map('strlen', array_keys($this->options)));
215+
212216
foreach ($this->options as $option => $description)
213217
{
214218
CLI::write(CLI::color($this->setPad($option, $length, 2, 2), 'green') . $description);
@@ -223,12 +227,12 @@ public function showHelp()
223227
*
224228
* @param string $item
225229
* @param integer $max
226-
* @param integer $extra // How many extra spaces to add at the end
230+
* @param integer $extra How many extra spaces to add at the end
227231
* @param integer $indent
228232
*
229233
* @return string
230234
*/
231-
protected function setPad(string $item, int $max, int $extra = 2, int $indent = 0): string
235+
public function setPad(string $item, int $max, int $extra = 2, int $indent = 0): string
232236
{
233237
$max += $extra + $indent;
234238

@@ -244,6 +248,10 @@ protected function setPad(string $item, int $max, int $extra = 2, int $indent =
244248
* @param integer $pad
245249
*
246250
* @return integer
251+
*
252+
* @deprecated Use setPad() instead.
253+
*
254+
* @codeCoverageIgnore
247255
*/
248256
public function getPad(array $array, int $pad): int
249257
{

tests/_support/Commands/AppInfo.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class AppInfo extends BaseCommand
1010

1111
protected $group = 'demo';
1212
protected $name = 'app:info';
13+
protected $arguments = ['draft' => 'unused'];
1314
protected $description = 'Displays basic application information.';
1415

1516
public function run(array $params)

tests/system/Commands/HelpCommandTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ public function testHelpCommand()
3737
$this->assertStringContainsString('command_name', $this->getBuffer());
3838
}
3939

40+
public function testHelpCommandWithMissingUsage()
41+
{
42+
command('help app:info');
43+
$this->assertStringContainsString('app:info [arguments]', $this->getBuffer());
44+
}
45+
4046
public function testHelpCommandOnSpecificCommand()
4147
{
4248
command('help cache:clear');

user_guide_src/source/changelogs/v4.0.5.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ Bugs Fixed:
1717

1818
- Fixed a bug in ``Entity`` class where declaring class parameters was preventing data propagation to the ``attributes`` array.
1919
- Handling for the environment variable ``encryption.key`` has changed. Previously, explicit function calls, like ``getenv('encryption.key')`` or ``env('encryption.key')`` where the value has the special prefix ``hex2bin:`` returns an automatically converted binary string. This is now changed to just return the character string with the prefix. This change was due to incompatibility with handling binary strings in environment variables on Windows platforms. However, accessing ``$key`` using ``Encryption`` class config remains unchanged and still returns a binary string.
20+
21+
Deprecations:
22+
23+
- Deprecated ``BaseCommand::getPad`` in favor of ``BaseCommand::setPad``.

0 commit comments

Comments
 (0)