From f3ffe16fd0267fc6720c40967e667a00250cab12 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Mon, 27 Nov 2023 23:13:28 -0500 Subject: [PATCH] Fix psalm errors. Use more verbose code style to get typing to be more sound. --- src/Command/BenchmarkCommand.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Command/BenchmarkCommand.php b/src/Command/BenchmarkCommand.php index 813c0bb9a..fedd73acd 100644 --- a/src/Command/BenchmarkCommand.php +++ b/src/Command/BenchmarkCommand.php @@ -50,15 +50,21 @@ public function execute(Arguments $args, ConsoleIo $io): ?int $this->io = $io; /** @var string $url */ $url = $args->getArgumentAt(0); - $defaults = ['t' => 100, 'n' => 10]; - $options = array_merge($defaults, $args->getOptions()); $times = []; $io->out(Text::insert('-> Testing :url', compact('url'))); $io->out(''); - for ($i = 0; $i < $options['n']; $i++) { - /** @psalm-suppress PossiblyInvalidOperand */ - if (floor($options['t'] - array_sum($times)) <= 0 || $options['n'] <= 1) { + $count = 10; + if ($args->hasOption('n')) { + $count = (float)$args->getOption('n'); + } + $timeout = 100; + if ($args->hasOption('t')) { + $timeout = (float)$args->getOption('t'); + } + + for ($i = 0; $i < $count; $i++) { + if (floor($timeout - array_sum($times)) <= 0 || $count <= 1) { break; }