1111
1212use Brick \Math \Internal \Calculator ;
1313
14+ use const PHP_EOL ;
15+
1416(new class (30 ) { // max digits
1517 private readonly Calculator \GmpCalculator $ gmp ;
18+
1619 private readonly Calculator \BcMathCalculator $ bcmath ;
20+
1721 private readonly Calculator \NativeCalculator $ native ;
1822
1923 private int $ testCounter = 0 ;
24+
2025 private float $ lastOutputTime = 0.0 ;
26+
2127 private int $ currentSecond = 0 ;
28+
2229 private int $ currentSecondTestCounter = 0 ;
30+
2331 private int $ testsPerSecond = 0 ;
2432
2533 public function __construct (
2634 private readonly int $ maxDigits ,
2735 ) {
28- $ this ->gmp = new Calculator \GmpCalculator ();
36+ $ this ->gmp = new Calculator \GmpCalculator ();
2937 $ this ->bcmath = new Calculator \BcMathCalculator ();
3038 $ this ->native = new Calculator \NativeCalculator ();
3139 }
3240
33- public function __invoke () : void
41+ public function __invoke (): void
3442 {
35- for (;;) {
43+ for (; ;) {
3644 $ a = $ this ->generateRandomNumber ();
3745 $ b = $ this ->generateRandomNumber ();
3846 $ c = $ this ->generateRandomNumber ();
@@ -65,7 +73,7 @@ public function __invoke() : void
6573 * @param string $a The left operand.
6674 * @param string $b The right operand.
6775 */
68- private function runTests (string $ a , string $ b ) : void
76+ private function runTests (string $ a , string $ b ): void
6977 {
7078 $ this ->test ("$ a + $ b " , fn (Calculator $ c ) => $ c ->add ($ a , $ b ));
7179 $ this ->test ("$ a - $ b " , fn (Calculator $ c ) => $ c ->sub ($ a , $ b ));
@@ -92,12 +100,12 @@ private function runTests(string $a, string $b) : void
92100 }
93101
94102 /**
95- * @param string $test A string representing the test being executed.
103+ * @param string $test A string representing the test being executed.
96104 * @param Closure(Calculator): mixed $callback A callback function accepting a Calculator instance and returning a calculation result.
97105 */
98- private function test (string $ test , Closure $ callback ) : void
106+ private function test (string $ test , Closure $ callback ): void
99107 {
100- $ gmpResult = $ callback ($ this ->gmp );
108+ $ gmpResult = $ callback ($ this ->gmp );
101109 $ bcmathResult = $ callback ($ this ->bcmath );
102110 $ nativeResult = $ callback ($ this ->native );
103111
@@ -132,7 +140,7 @@ private function test(string $test, Closure $callback) : void
132140 * @param string $c2 The name of the second calculator.
133141 * @param string $test A string representing the test being executed.
134142 */
135- private function failure (string $ c1 , string $ c2 , string $ test ) : never
143+ private function failure (string $ c1 , string $ c2 , string $ test ): never
136144 {
137145 echo PHP_EOL ;
138146 echo 'FAILURE! ' , PHP_EOL ;
@@ -141,7 +149,7 @@ private function failure(string $c1, string $c2, string $test) : never
141149 die;
142150 }
143151
144- private function generateRandomNumber () : string
152+ private function generateRandomNumber (): string
145153 {
146154 $ length = random_int (1 , $ this ->maxDigits );
147155
0 commit comments