Skip to content

Commit 02ad26d

Browse files
committed
Fix timeit when -n1, ensure that it always executes at least once even with weird input.
1 parent 27f8bdd commit 02ad26d

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

src/Command/TimeitCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,17 @@ protected function configure()
8585
protected function execute(InputInterface $input, OutputInterface $output)
8686
{
8787
$code = $input->getArgument('code');
88-
$num = $input->getOption('num') ?: 1;
88+
$num = \intval($input->getOption('num') ?: 1);
8989
$shell = $this->getApplication();
9090

9191
$instrumentedCode = $this->instrumentCode($code);
9292

9393
self::$times = [];
9494

95-
for ($i = 0; $i < $num; $i++) {
95+
do {
9696
$_ = $shell->execute($instrumentedCode);
9797
$this->ensureEndMarked();
98-
}
98+
} while (\count(self::$times) < $num);
9999

100100
$shell->writeReturnValue($_);
101101

vendor-bin/phpstan/baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: "#^Variable \\$_ might not be defined\\.$#"
5-
count: 1
6-
path: ../../src/Command/TimeitCommand.php
7-
83
-
94
message: "#^Variable \\$_except in empty\\(\\) always exists and is always falsy\\.$#"
105
count: 1

0 commit comments

Comments
 (0)