Skip to content

Commit 341013a

Browse files
committed
Changes for static anlaysis improvements, and various other internal changes.
1 parent 70d0111 commit 341013a

File tree

81 files changed

+412
-307
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+412
-307
lines changed

.github/workflows/test_develop_and_master.yml

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
test-and-static-analysis:
11-
name: Test and Static Analysis
11+
name: Test and Lint
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
@@ -23,12 +23,12 @@ jobs:
2323
tools: composer:v2
2424

2525
- name: Set up Node
26-
uses: actions/setup-node@v1
26+
uses: actions/setup-node@v3
2727
with:
2828
node-version: '14.x'
2929

3030
- name: Checkout code
31-
uses: actions/checkout@v2
31+
uses: actions/checkout@v3
3232
with:
3333
fetch-depth: 0
3434

@@ -58,10 +58,38 @@ jobs:
5858
./vendor/bin/phpcs --version
5959
./vendor/bin/phpcs --ignore=vendor --standard=tests/coding_standard.xml -s .
6060
61+
static-analysis:
62+
name: Static Analysis
63+
runs-on: ubuntu-latest
64+
strategy:
65+
matrix:
66+
php: ['7.2']
67+
68+
steps:
69+
- name: Set up PHP
70+
uses: shivammathur/setup-php@v2
71+
with:
72+
php-version: ${{ matrix.php }}
73+
coverage: xdebug
74+
tools: composer:v2
75+
76+
- name: Set up Node
77+
uses: actions/setup-node@v3
78+
with:
79+
node-version: '14.x'
80+
81+
- name: Checkout code
82+
uses: actions/checkout@v3
83+
with:
84+
fetch-depth: 0
85+
86+
- name: Run Composer
87+
run: composer install --no-interaction
88+
6189
- name: Static analysis
6290
run: |
6391
./vendor/bin/phpstan --version
64-
./vendor/bin/phpstan analyze --level max src/
92+
./vendor/bin/phpstan analyze -c tests/phpstan.neon
6593
6694
code-coverage:
6795
name: Code coverage
@@ -79,12 +107,12 @@ jobs:
79107
tools: composer:v2
80108

81109
- name: Set up Node
82-
uses: actions/setup-node@v1
110+
uses: actions/setup-node@v3
83111
with:
84112
node-version: '14.x'
85113

86114
- name: Checkout code
87-
uses: actions/checkout@v2
115+
uses: actions/checkout@v3
88116
with:
89117
fetch-depth: 0
90118

.github/workflows/test_other_branches.yml

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ on:
77
- master
88

99
jobs:
10-
test-and-static-analysis:
11-
name: Test and Static Analysis
10+
test-and-lint:
11+
name: Test and Lint
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
@@ -22,12 +22,12 @@ jobs:
2222
tools: composer:v2
2323

2424
- name: Set up Node
25-
uses: actions/setup-node@v1
25+
uses: actions/setup-node@v3
2626
with:
2727
node-version: '14.x'
2828

2929
- name: Checkout code
30-
uses: actions/checkout@v2
30+
uses: actions/checkout@v3
3131
with:
3232
fetch-depth: 0
3333

@@ -57,7 +57,35 @@ jobs:
5757
./vendor/bin/phpcs --version
5858
./vendor/bin/phpcs --ignore=vendor --standard=tests/coding_standard.xml -s .
5959
60+
static-analysis:
61+
name: Static Analysis
62+
runs-on: ubuntu-latest
63+
strategy:
64+
matrix:
65+
php: ['7.2']
66+
67+
steps:
68+
- name: Set up PHP
69+
uses: shivammathur/setup-php@v2
70+
with:
71+
php-version: ${{ matrix.php }}
72+
coverage: xdebug
73+
tools: composer:v2
74+
75+
- name: Set up Node
76+
uses: actions/setup-node@v3
77+
with:
78+
node-version: '14.x'
79+
80+
- name: Checkout code
81+
uses: actions/checkout@v3
82+
with:
83+
fetch-depth: 0
84+
85+
- name: Run Composer
86+
run: composer install --no-interaction
87+
6088
- name: Static analysis
6189
run: |
6290
./vendor/bin/phpstan --version
63-
./vendor/bin/phpstan analyze --level max src/
91+
./vendor/bin/phpstan analyze -c tests/phpstan.neon

.github/workflows/test_pull_request.yml

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on: pull_request
44

55
jobs:
66
test-and-static-analysis:
7-
name: Test and Static Analysis
7+
name: Test and Lint
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
@@ -19,12 +19,12 @@ jobs:
1919
tools: composer:v2
2020

2121
- name: Set up Node
22-
uses: actions/setup-node@v1
22+
uses: actions/setup-node@v3
2323
with:
2424
node-version: '14.x'
2525

2626
- name: Checkout code
27-
uses: actions/checkout@v2
27+
uses: actions/checkout@v3
2828
with:
2929
fetch-depth: 0
3030

@@ -54,10 +54,38 @@ jobs:
5454
./vendor/bin/phpcs --version
5555
./vendor/bin/phpcs --ignore=vendor --standard=tests/coding_standard.xml -s .
5656
57+
static-analysis:
58+
name: Static Analysis
59+
runs-on: ubuntu-latest
60+
strategy:
61+
matrix:
62+
php: ['7.2']
63+
64+
steps:
65+
- name: Set up PHP
66+
uses: shivammathur/setup-php@v2
67+
with:
68+
php-version: ${{ matrix.php }}
69+
coverage: xdebug
70+
tools: composer:v2
71+
72+
- name: Set up Node
73+
uses: actions/setup-node@v3
74+
with:
75+
node-version: '14.x'
76+
77+
- name: Checkout code
78+
uses: actions/checkout@v3
79+
with:
80+
fetch-depth: 0
81+
82+
- name: Run Composer
83+
run: composer install --no-interaction
84+
5785
- name: Static analysis
5886
run: |
5987
./vendor/bin/phpstan --version
60-
./vendor/bin/phpstan analyze --level max src/
88+
./vendor/bin/phpstan analyze -c tests/phpstan.neon
6189
6290
code-coverage:
6391
name: Code coverage
@@ -75,12 +103,12 @@ jobs:
75103
tools: composer:v2
76104

77105
- name: Set up Node
78-
uses: actions/setup-node@v1
106+
uses: actions/setup-node@v3
79107
with:
80108
node-version: '14.x'
81109

82110
- name: Checkout code
83-
uses: actions/checkout@v2
111+
uses: actions/checkout@v3
84112
with:
85113
fetch-depth: 0
86114

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ style :
1212
vendor/bin/phpcs --standard=tests/coding_standard.xml --ignore=vendor -s .
1313

1414
phpstan :
15-
vendor/bin/phpstan analyze --level max src/
15+
vendor/bin/phpstan analyze -c tests/phpstan.neon
1616

1717
phpmd :
1818
vendor/bin/phpmd src/ ansi cleancode,codesize,design,unusedcode,naming

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ $f’⟮x⟯ = function ($x) {
977977
};
978978
[$start, $end, $n] = [0, 3, 4];
979979

980-
$p = Interpolation\ClampedCubicSpline::interpolate($points); // input as a set of points
980+
$p = Interpolation\ClampedCubicSpline::interpolate($points); // input as a set of points
981981
$p = Interpolation\ClampedCubicSpline::interpolate($f⟮x⟯, $f’⟮x⟯, $start, $end, $n); // input as a callback function
982982

983983
$p(0); // 1

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"phpunit/phpunit": "^8.5",
1616
"php-coveralls/php-coveralls": "^2.0",
1717
"squizlabs/php_codesniffer": "3.*",
18-
"phpstan/phpstan": "*",
18+
"phpstan/phpstan": "^1.10",
1919
"phpmd/phpmd": "^2.6",
2020
"phploc/phploc": "*",
2121
"php-parallel-lint/php-parallel-lint": "^1.2"

src/Algebra.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public static function extendedGcd(int $a, int $b): array
9595
* @param int $b
9696
*
9797
* @return int
98+
* @psalm-suppress InvalidReturnType (Change to intdiv for PHP 8.0)
9899
*/
99100
public static function lcm(int $a, int $b): int
100101
{
@@ -236,7 +237,7 @@ public static function linear(float $a, float $b): ?float
236237
* @param float $c constant coefficient
237238
* @param bool $return_complex Whether to return complex numbers or NANs if imaginary roots
238239
*
239-
* @return array{0: float|Complex, 1?: float|Complex}
240+
* @return float[]|Complex[]
240241
* [x₁, x₂] roots of the equation, or
241242
* [NAN, NAN] if discriminant is negative, or
242243
* [Complex, Complex] if discriminant is negative and complex option is on or
@@ -367,7 +368,7 @@ public static function discriminant(float $a, float $b, float $c): float
367368
* @param float $a₀ constant coefficient
368369
* @param bool $return_complex whether to return complex numbers
369370
*
370-
* @return array{0: float|Complex, 1?: float|Complex, 2?: float|Complex}
371+
* @return float[]|Complex[]
371372
* array of roots (three real roots, or one real root and two NANs because complex numbers not yet supported)
372373
* (If $a₃ = 0, then only two roots of quadratic equation)
373374
*
@@ -531,7 +532,10 @@ public static function quartic(float $a₄, float $a₃, float $a₂, float $a
531532

532533
// The roots for this polynomial are the roots of the depressed polynomial minus a₃/4.
533534
if (!$return_complex) {
534-
// @phpstan-ignore-next-line (Single::subtract() works with real numbers only, must be real roots)
535+
/**
536+
* @phpstan-ignore-next-line (Single::subtract() works with real numbers only, must be real roots)
537+
* @psalm-suppress InvalidArgument
538+
*/
535539
return Single::subtract($depressed_quartic_roots, $a₃ / 4);
536540
}
537541

src/Expression/Piecewise.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ public function __construct(array $intervals, array $functions)
7171
$lastB = $b ?? -\INF;
7272
$lastBOpen = $bOpen ?? false;
7373

74-
// @phpstan-ignore-next-line (Strict comparison using !== between 2 and 2 will always evaluate to false.)
7574
if (\count(\array_filter($interval, '\is_numeric')) !== 2) {
7675
throw new Exception\BadDataException('Each interval must contain two numbers.');
7776
}

src/Expression/Polynomial.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Polynomial implements ObjectArithmetic
5656
/** @var int */
5757
private $degree;
5858

59-
/** @var array<number> */
59+
/** @var array<int|float> */
6060
private $coefficients;
6161

6262
/** @var string */
@@ -71,7 +71,7 @@ class Polynomial implements ObjectArithmetic
7171
* When a polynomial is instantiated, set the coefficients and degree of
7272
* that polynomial as its object parameters.
7373
*
74-
* @param array<number> $coefficients An array of coefficients in decreasing powers
74+
* @param array<int|float> $coefficients An array of coefficients in decreasing powers
7575
* Example: new Polynomial([1, 2, 3]) will create
7676
* a polynomial that looks like x² + 2x + 3.
7777
* @param string $variable
@@ -215,7 +215,7 @@ private function checkNumericOrPolynomial($input): Polynomial
215215
if ($input instanceof Polynomial) {
216216
return $input;
217217
} elseif (\is_numeric($input)) {
218-
/** @var number $input */
218+
/** @var int|float $input */
219219
return new Polynomial([$input]);
220220
} else {
221221
throw new Exception\IncorrectTypeException('Input must be a Polynomial or a number');
@@ -235,7 +235,7 @@ public function getDegree(): int
235235
/**
236236
* Getter method for the coefficients of a polynomial
237237
*
238-
* @return array<number> The coefficients array of a polynomial object
238+
* @return array<int|float> The coefficients array of a polynomial object
239239
*/
240240
public function getCoefficients(): array
241241
{

src/Functions/Map/Multi.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ class Multi
1414
*
1515
* [x₁ + y₁, x₂ + y₂, ... ]
1616
*
17-
* @param array<number> ...$arrays Two or more arrays of numbers
17+
* @param array<int|float> ...$arrays Two or more arrays of numbers
1818
*
19-
* @return array<number>
19+
* @return array<int|float>
2020
*
2121
* @throws Exception\BadDataException
2222
*/
@@ -42,9 +42,9 @@ public static function add(array ...$arrays): array
4242
*
4343
* [x₁ - y₁, x₂ - y₂, ... ]
4444
*
45-
* @param array<number> ...$arrays Two or more arrays of numbers
45+
* @param array<int|float> ...$arrays Two or more arrays of numbers
4646
*
47-
* @return array<number>
47+
* @return array<int|float>
4848
*
4949
* @throws Exception\BadDataException
5050
*/
@@ -75,9 +75,9 @@ function ($x) {
7575
*
7676
* [x₁ * y₁, x₂ * y₂, ... ]
7777
*
78-
* @param array<number> ...$arrays Two or more arrays of numbers
78+
* @param array<int|float> ...$arrays Two or more arrays of numbers
7979
*
80-
* @return array<number>
80+
* @return array<int|float>
8181
*
8282
* @throws Exception\BadDataException
8383
*/
@@ -103,7 +103,7 @@ public static function multiply(array ...$arrays): array
103103
*
104104
* [x₁ / y₁, x₂ / y₂, ... ]
105105
*
106-
* @param array<number> ...$arrays Two or more arrays of numbers
106+
* @param array<int|float> ...$arrays Two or more arrays of numbers
107107
*
108108
* @return array<float>
109109
*
@@ -136,9 +136,9 @@ function ($x) {
136136
*
137137
* [max(x₁, y₁), max(x₂, y₂), ... ]
138138
*
139-
* @param array<number> ...$arrays Two or more arrays of numbers
139+
* @param array<int|float> ...$arrays Two or more arrays of numbers
140140
*
141-
* @return array<number>
141+
* @return array<int|float>
142142
*
143143
* @throws Exception\BadDataException
144144
*/
@@ -169,9 +169,9 @@ function ($x) {
169169
*
170170
* [max(x₁, y₁), max(x₂, y₂), ... ]
171171
*
172-
* @param array<number> ...$arrays Two or more arrays of numbers
172+
* @param array<int|float> ...$arrays Two or more arrays of numbers
173173
*
174-
* @return array<number>
174+
* @return array<int|float>
175175
*
176176
* @throws Exception\BadDataException
177177
*/

0 commit comments

Comments
 (0)