Skip to content

Commit fef62b1

Browse files
committed
Keep the benchmarks out of lint and analysis on PHP < 8.1
PHP 7.4 reads #[ as a comment until the end of the line, so the attribute of AnalysisBench is on one line. Tally's sources use enums and readonly properties, which PHPStan does not parse for PHP < 8.1, so the benchmarks are not analysed there. Amp-Thread-ID: https://ampcode.com/threads/T-01a1d525-9c4c-73cf-8edc-000aa8e78378
1 parent a66a8a9 commit fef62b1

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

‎build/ignore-by-php-version.neon.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
$includes[] = __DIR__ . '/enums.neon';
1111
$includes[] = __DIR__ . '/readonly-property.neon';
1212
$includes[] = __DIR__ . '/turbo-declaration-generator-pre-8.1.neon';
13+
$includes[] = __DIR__ . '/tally-pre-8.1.neon';
1314
}
1415

1516
// PHP 8.1's serialize() does not trim its buffer, so the rule's cache keys cost 4 KB each

‎build/tally-pre-8.1.neon‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
excludePaths:
3+
# Tally's sources use enums and readonly properties, which PHPStan does not parse for PHP < 8.1
4+
- ../tally.php
5+
- ../tests/bench/AnalysedFileExpectations.php
6+
- ../tests/bench/AnalysedFileHeader.php
7+
- ../tests/bench/AnalysisBench.php

‎tests/bench/AnalysisBench.php‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,10 @@
4343
* is converted to milliseconds by how many of it the analysis runs per millisecond (the median
4444
* over the benchmarks, natively on PHP 8.5 and an Intel Xeon @ 2.60 GHz), and the quicker the
4545
* benchmark, the larger the share of it that may change.
46+
*
47+
* The attribute is on one line because PHP 7.4 reads #[ as a comment until the end of the line.
4648
*/
47-
#[DurationTolerance(
48-
tolerances: [0 => 0.5, 100 => 0.25, 500 => 0.2, 2000 => 0.1],
49-
instructionsPerMillisecond: 5_800_000,
50-
cyclesPerMillisecond: 7_400_000,
51-
memory: 0.1,
52-
)]
49+
#[DurationTolerance(tolerances: [0 => 0.5, 100 => 0.25, 500 => 0.2, 2000 => 0.1], instructionsPerMillisecond: 5_800_000, cyclesPerMillisecond: 7_400_000, memory: 0.1)]
5350
final class AnalysisBench
5451
{
5552

0 commit comments

Comments
 (0)