Skip to content

Commit 377daea

Browse files
authored
PHPStan and docs updates (#142)
* Update to PHPStan 2.0 * Update to PHPUnit 12 * Remove prefer-lowest from test config * Drop 8.0 testing due to PHPUnit issues * Update addOperator docs * trying to fix PHPUnit failures that work locally
1 parent 618d9c2 commit 377daea

3 files changed

Lines changed: 11 additions & 17 deletions

File tree

README.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ $executor->execute('average(1, 3, 4, 8)'); // 4
123123
## Operators:
124124
Default operators: `+ - * / % ^`
125125

126-
Add custom operator to executor:
126+
Add custom float modulo operator to executor:
127127

128128
```php
129129
use NXP\Classes\Operator;
@@ -132,13 +132,9 @@ $executor->addOperator(new Operator(
132132
'%', // Operator sign
133133
false, // Is right associated operator
134134
180, // Operator priority
135-
function (&$stack)
135+
function ($op1, $op2)
136136
{
137-
$op2 = array_pop($stack);
138-
$op1 = array_pop($stack);
139-
$result = $op1->getValue() % $op2->getValue();
140-
141-
return $result;
137+
return fmod($op1, $op2);
142138
}
143139
));
144140
```
@@ -198,8 +194,7 @@ $executor->setVarValidationHandler(function (string $name, $variable) {
198194
You can dynamically define variables at run time. If a variable has a high computation cost, but might not be used, then you can define an undefined variable handler. It will only get called when the variable is used, rather than having to always set it initially.
199195

200196
```php
201-
$calculator = new MathExecutor();
202-
$calculator->setVarNotFoundHandler(
197+
$executor->setVarNotFoundHandler(
203198
function ($varName) {
204199
if ($varName == 'trans') {
205200
return transmogrify();
@@ -228,7 +223,7 @@ echo $executor->setDivisionByZeroIsZero()->execute('1/0');
228223
```
229224
If you want another behavior, you can override division operator:
230225
```php
231-
$executor->addOperator("/", false, 180, function($a, $b) {
226+
$executor->addOperator(new Operator("/"m, false, 180, function($a, $b) {
232227
if ($b == 0) {
233228
return null;
234229
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"php": ">=8.0 <8.5"
3232
},
3333
"require-dev": {
34-
"phpunit/phpunit": ">=9.0",
34+
"phpunit/phpunit": ">=10.0",
3535
"friendsofphp/php-cs-fixer": "^3.8",
3636
"phpstan/phpstan": "^2.0"
3737
},

tests/MathTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@
2020
use NXP\Exception\UnknownVariableException;
2121
use NXP\MathExecutor;
2222
use PHPUnit\Framework\TestCase;
23-
use PHPUnit\Framework\Attributes\DataProvider;
2423

2524
class MathTest extends TestCase
2625
{
27-
#[DataProvider('providerExpressions')]
26+
#[\PHPUnit\Framework\Attributes\DataProvider('providerExpressions')]
2827
public function testCalculating(string $expression) : void
2928
{
3029
$calculator = new MathExecutor();
@@ -268,7 +267,7 @@ public static function providerExpressions()
268267
];
269268
}
270269

271-
#[DataProvider('bcMathExpressions')]
270+
#[\PHPUnit\Framework\Attributes\DataProvider('bcMathExpressions')]
272271
public function testBCMathCalculating(string $expression, string $expected = '') : void
273272
{
274273
$calculator = new MathExecutor();
@@ -512,7 +511,7 @@ public static function bcMathExpressions()
512511
];
513512
}
514513

515-
#[DataProvider('incorrectExpressions')]
514+
#[\PHPUnit\Framework\Attributes\DataProvider('incorrectExpressions')]
516515
public function testIncorrectExpressionException(string $expression) : void
517516
{
518517
$calculator = new MathExecutor();
@@ -1093,7 +1092,7 @@ public function testVarExists() : void
10931092
$this->assertFalse($calculator->varExists('Lucy'));
10941093
}
10951094

1096-
#[DataProvider('providerExpressionValues')]
1095+
#[\PHPUnit\Framework\Attributes\DataProvider('providerExpressionValues')]
10971096
public function testCalculatingValues(string $expression, mixed $value) : void
10981097
{
10991098
$calculator = new MathExecutor();
@@ -1172,7 +1171,7 @@ public function testCache() : void
11721171

11731172
public function testUnsupportedOperands() : void
11741173
{
1175-
if (\version_compare(PHP_VERSION, '8.0') >= 0) { // @phpstan-ignore-line
1174+
if (\version_compare(PHP_VERSION, '8.0') >= 0) { /** @phpstan-ignore-line */
11761175
$calculator = new MathExecutor();
11771176

11781177
$calculator->setVar('stringVar', 'string');

0 commit comments

Comments
 (0)