Skip to content

Commit d82cfbb

Browse files
committed
Apply coding standard
1 parent 8be7f41 commit d82cfbb

23 files changed

+1429
-1271
lines changed

phpunit.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,26 @@
55
use Brick\Math\Internal\Calculator;
66
use Brick\Math\Internal\CalculatorRegistry;
77

8+
use const PHP_EOL;
9+
810
require __DIR__ . '/vendor/autoload.php';
911

1012
function getCalculatorImplementation(): Calculator
1113
{
12-
switch ($calculator = \getenv('CALCULATOR')) {
14+
switch ($calculator = getenv('CALCULATOR')) {
1315
case 'GMP':
1416
$calculator = new Calculator\GmpCalculator();
17+
1518
break;
1619

1720
case 'BCMath':
1821
$calculator = new Calculator\BcMathCalculator();
22+
1923
break;
2024

2125
case 'Native':
2226
$calculator = new Calculator\NativeCalculator();
27+
2328
break;
2429

2530
default:
@@ -34,16 +39,16 @@ function getCalculatorImplementation(): Calculator
3439
exit(1);
3540
}
3641

37-
echo 'Using ', \get_class($calculator), PHP_EOL;
42+
echo 'Using ', get_class($calculator), PHP_EOL;
3843

3944
return $calculator;
4045
}
4146

4247
CalculatorRegistry::set(getCalculatorImplementation());
4348

44-
$scale = \getenv('BCMATH_DEFAULT_SCALE');
49+
$scale = getenv('BCMATH_DEFAULT_SCALE');
4550

4651
if ($scale !== false) {
4752
echo "Using bcscale($scale)", PHP_EOL;
48-
\bcscale((int) $scale);
53+
bcscale((int) $scale);
4954
}

random-tests.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,36 @@
1111

1212
use 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

Comments
 (0)