Skip to content

Commit 9686e13

Browse files
author
ityaozm@gmail.com
committed
perf(commands): Improve null handling and code clarity
- Update variable type hint for originalOutput to allow null. - Adjust condition for checking null key in ConfigCommand for better readability. - Document exception throwing in argToValue method. - Remove commented-out code in valueToArg for cleaner implementation.
1 parent bfc9b63 commit 9686e13

File tree

5 files changed

+25
-28
lines changed

5 files changed

+25
-28
lines changed

app/Commands/BuildCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ final class BuildCommand extends Command
5959
/**
6060
* Holds the command original output.
6161
*
62-
* @var \Symfony\Component\Console\Output\OutputInterface
62+
* @var null|\Symfony\Component\Console\Output\OutputInterface
6363
*/
6464
private $originalOutput;
6565

app/Commands/CommitCommand.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,18 @@ private function getCommitCommand(Collection $message): array
349349
return array_merge(['git', 'commit', '--message', $this->hydrateMessage($message)], $options);
350350
}
351351

352+
private function hydrateMessage(Collection $message): string
353+
{
354+
return $message
355+
->map(static function (string $val): string {
356+
return trim($val, " \t\n\r\x0B");
357+
})
358+
->filter(static function ($val) {
359+
return $val;
360+
})
361+
->implode(str_repeat(PHP_EOL, 2));
362+
}
363+
352364
private function shouldntEdit(): bool
353365
{
354366
return ! Process::isTtySupported() || $this->option('no-edit') || $this->configManager->get('no_edit');
@@ -371,16 +383,4 @@ private function shouldVerify(): bool
371383
{
372384
return ! $this->shouldntVerify();
373385
}
374-
375-
private function hydrateMessage(Collection $message): string
376-
{
377-
return $message
378-
->map(static function (string $val): string {
379-
return trim($val, " \t\n\r\x0B");
380-
})
381-
->filter(static function ($val) {
382-
return $val;
383-
})
384-
->implode(str_repeat(PHP_EOL, 2));
385-
}
386386
}

app/Commands/ConfigCommand.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function handle(ExecutableFinder $executableFinder): int
8888
$action = $this->argument('action');
8989
$key = $this->argument('key');
9090

91-
if (\in_array($action, ['set', 'unset'], true) && null === $key) {
91+
if (null === $key && \in_array($action, ['set', 'unset'], true)) {
9292
$this->output->error('Please specify the parameter key.');
9393

9494
return self::FAILURE;
@@ -206,8 +206,11 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
206206
}
207207

208208
/**
209-
* @throws \JsonException
210209
* @noinspection PhpInconsistentReturnPointsInspection
210+
*
211+
* @throws \JsonException
212+
*
213+
* @return mixed
211214
*/
212215
private function argToValue(string $arg)
213216
{
@@ -241,13 +244,13 @@ private function argToValue(string $arg)
241244
*/
242245
private function valueToArg($value): string
243246
{
244-
if (null === $value) {
245-
return 'null';
246-
}
247-
248-
if (\is_scalar($value)) {
249-
return var_export($value, true);
250-
}
247+
// if (null === $value) {
248+
// return 'null';
249+
// }
250+
//
251+
// if (\is_scalar($value)) {
252+
// return var_export($value, true);
253+
// }
251254

252255
return (string) json_encode($value, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
253256
}

app/Commands/ThanksCommand.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,11 @@
1818
final class ThanksCommand extends Command
1919
{
2020
/**
21-
* The signature of the command.
22-
*
2321
* @var string
2422
*/
2523
protected $signature = 'thanks';
2624

2725
/**
28-
* The description of the command.
29-
*
3026
* @var string
3127
*/
3228
protected $description = 'Thanks for using this tool.';

rector.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
*/
1212

1313
use Rector\Caching\ValueObject\Storage\FileCacheStorage;
14-
use Rector\CodeQuality\Rector\Array_\CallableThisArrayToAnonymousFunctionRector;
1514
use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector;
1615
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
1716
use Rector\CodeQuality\Rector\ClassMethod\ExplicitReturnNullRector;
@@ -75,7 +74,6 @@
7574

7675
$rectorConfig->skip([
7776
// rules
78-
// CallableThisArrayToAnonymousFunctionRector::class,
7977
// RemoveEmptyClassMethodRector::class,
8078
// RemoveUnusedVariableAssignRector::class,
8179
// SimplifyBoolIdenticalTrueRector::class,

0 commit comments

Comments
 (0)