Skip to content

Commit 618d9c2

Browse files
authored
PhpStan (#140)
* Update to PHPStan 2.0 * Update to PHPUnit 12 * Remove prefer-lowest from test config * Drop 8.0 testing due to PHPUnit issues
1 parent b3b9351 commit 618d9c2

File tree

7 files changed

+18
-22
lines changed

7 files changed

+18
-22
lines changed

.github/workflows/tests.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ jobs:
88
strategy:
99
fail-fast: false
1010
matrix:
11-
php: [8.4, 8.3, 8.2, 8.1, 8.0]
12-
dependency-version: [prefer-lowest, prefer-stable]
11+
php: [8.4, 8.3, 8.2, 8.1]
12+
dependency-version: [prefer-stable]
1313
os: [ubuntu-latest, windows-latest]
1414

1515
name: ${{ matrix.os }} - PHP${{ matrix.php }} - ${{ matrix.dependency-version }}
@@ -29,7 +29,7 @@ jobs:
2929
- name: Install dependencies
3030
run: |
3131
composer install --no-interaction
32-
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
32+
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
3333
3434
- name: Execute tests
3535
run: vendor/bin/phpunit

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"require-dev": {
3434
"phpunit/phpunit": ">=9.0",
3535
"friendsofphp/php-cs-fixer": "^3.8",
36-
"phpstan/phpstan": "^1.9"
36+
"phpstan/phpstan": "^2.0"
3737
},
3838
"autoload": {
3939
"psr-4": {

src/NXP/Classes/Calculator.php

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* This file is part of the MathExecutor package
45
*

src/NXP/Classes/Operator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class Operator
99
{
1010
/**
11-
* @var callable(\SplStack)
11+
* @var callable
1212
*/
1313
public $function;
1414

src/NXP/Classes/Tokenizer.php

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* This file is part of the MathExecutor package
45
*

src/NXP/MathExecutor.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* This file is part of the MathExecutor package
45
*
@@ -493,7 +494,7 @@ protected function defaultFunctions() : array
493494

494495
$count = \count($finalArgs);
495496
\sort($finalArgs);
496-
$index = \floor($count / 2);
497+
$index = (int)\floor($count / 2);
497498

498499
return ($count & 1) ? $finalArgs[$index] : ($finalArgs[$index - 1] + $finalArgs[$index]) / 2;
499500
},

tests/MathTest.php

+9-16
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@
2020
use NXP\Exception\UnknownVariableException;
2121
use NXP\MathExecutor;
2222
use PHPUnit\Framework\TestCase;
23+
use PHPUnit\Framework\Attributes\DataProvider;
2324

2425
class MathTest extends TestCase
2526
{
26-
/**
27-
* @dataProvider providerExpressions
28-
*/
27+
#[DataProvider('providerExpressions')]
2928
public function testCalculating(string $expression) : void
3029
{
3130
$calculator = new MathExecutor();
@@ -269,9 +268,7 @@ public static function providerExpressions()
269268
];
270269
}
271270

272-
/**
273-
* @dataProvider bcMathExpressions
274-
*/
271+
#[DataProvider('bcMathExpressions')]
275272
public function testBCMathCalculating(string $expression, string $expected = '') : void
276273
{
277274
$calculator = new MathExecutor();
@@ -515,9 +512,7 @@ public static function bcMathExpressions()
515512
];
516513
}
517514

518-
/**
519-
* @dataProvider incorrectExpressions
520-
*/
515+
#[DataProvider('incorrectExpressions')]
521516
public function testIncorrectExpressionException(string $expression) : void
522517
{
523518
$calculator = new MathExecutor();
@@ -976,7 +971,7 @@ public function testNullReturnType() : void
976971
public function testGetFunctionsReturnsArray() : void
977972
{
978973
$calculator = new MathExecutor();
979-
$this->assertIsArray($calculator->getFunctions());
974+
$this->assertIsArray($calculator->getFunctions()); // @phpstan-ignore-line
980975
}
981976

982977
public function testGetFunctionsReturnsFunctions() : void
@@ -988,7 +983,7 @@ public function testGetFunctionsReturnsFunctions() : void
988983
public function testGetVarsReturnsArray() : void
989984
{
990985
$calculator = new MathExecutor();
991-
$this->assertIsArray($calculator->getVars());
986+
$this->assertIsArray($calculator->getVars()); // @phpstan-ignore-line
992987
}
993988

994989
public function testGetVarsReturnsCount() : void
@@ -1098,9 +1093,7 @@ public function testVarExists() : void
10981093
$this->assertFalse($calculator->varExists('Lucy'));
10991094
}
11001095

1101-
/**
1102-
* @dataProvider providerExpressionValues
1103-
*/
1096+
#[DataProvider('providerExpressionValues')]
11041097
public function testCalculatingValues(string $expression, mixed $value) : void
11051098
{
11061099
$calculator = new MathExecutor();
@@ -1160,7 +1153,7 @@ public function testCache() : void
11601153
$calculator = new MathExecutor();
11611154
$this->assertEquals(256, $calculator->execute('2 ^ 8')); // second arg $cache is true by default
11621155

1163-
$this->assertIsArray($calculator->getCache());
1156+
$this->assertIsArray($calculator->getCache()); // @phpstan-ignore-line
11641157
$this->assertCount(1, $calculator->getCache());
11651158

11661159
$this->assertEquals(512, $calculator->execute('2 ^ 9', true));
@@ -1179,7 +1172,7 @@ public function testCache() : void
11791172

11801173
public function testUnsupportedOperands() : void
11811174
{
1182-
if (\version_compare(PHP_VERSION, '8') >= 0) {
1175+
if (\version_compare(PHP_VERSION, '8.0') >= 0) { // @phpstan-ignore-line
11831176
$calculator = new MathExecutor();
11841177

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

0 commit comments

Comments
 (0)