diff --git a/composer.json b/composer.json index cce4687e096..f95adb69640 100644 --- a/composer.json +++ b/composer.json @@ -71,7 +71,7 @@ "phpstan/phpstan-nette": "^2.0", "phpstan/phpstan-phpunit": "^2.1", "phpstan/phpstan-strict-rules": "^2.1", - "phpstan/tally": "dev-release/1.x", + "phpstan/tally": "^1.0.1", "phpunit/phpunit": "^11.5.23", "shipmonk/composer-dependency-analyser": "^1.5", "shipmonk/dead-code-detector": "^1.4.2", diff --git a/composer.lock b/composer.lock index 4487df6fbf1..31ccd7593f9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c8e816333f58f55b9348aa729f3d31a4", + "content-hash": "1267a1b194e9dd3c379a9fe16dabe494", "packages": [ { "name": "clue/ndjson-react", @@ -4205,22 +4205,23 @@ }, { "name": "phpstan/tally", - "version": "dev-release/1.x", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/phpstan/tally.git", - "reference": "e67008ced513658b84e40992268763385218b228" + "reference": "f62fb265cbe7fd916af1e8d61ee49bb2c1af4b21" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/tally/zipball/e67008ced513658b84e40992268763385218b228", - "reference": "e67008ced513658b84e40992268763385218b228", + "url": "https://api.github.com/repos/phpstan/tally/zipball/f62fb265cbe7fd916af1e8d61ee49bb2c1af4b21", + "reference": "f62fb265cbe7fd916af1e8d61ee49bb2c1af4b21", "shasum": "" }, "require": { "php": "^8.2" }, "require-dev": { + "ext-posix": "*", "infection/infection": "^0.35.10", "php-parallel-lint/php-parallel-lint": "^1.4", "phpstan/phpstan": "^2.1", @@ -4234,6 +4235,11 @@ "bin/tally" ], "type": "library", + "extra": { + "skills": { + "source": "skills" + } + }, "autoload": { "psr-4": { "Tally\\": "src/" @@ -4251,10 +4257,10 @@ ], "support": { "issues": "https://github.com/phpstan/tally/issues", - "source": "https://github.com/phpstan/tally/tree/release/1.x" + "source": "https://github.com/phpstan/tally/tree/1.0.1" }, - "time": "2026-11-14T11:09:44+00:00", - "published-time": "2026-11-14T11:09:50+00:00" + "time": "2026-11-14T22:36:03+00:00", + "published-time": "2026-11-14T22:42:17+00:00" }, { "name": "phpunit/php-code-coverage", @@ -5935,8 +5941,7 @@ "aliases": [], "minimum-stability": "dev", "stability-flags": { - "jetbrains/phpstorm-stubs": 20, - "phpstan/tally": 20 + "jetbrains/phpstorm-stubs": 20 }, "prefer-stable": true, "prefer-lowest": false, diff --git a/tests/bench/AnalysedFileExpectations.php b/tests/bench/AnalysedFileExpectations.php index a6d2c1de5c9..2d66d37b345 100644 --- a/tests/bench/AnalysedFileExpectations.php +++ b/tests/bench/AnalysedFileExpectations.php @@ -28,9 +28,9 @@ public function file(): string } #[Override] - public function rewrite(string $code, Metrics $measured): string + public function edits(string $code, Metrics $measured): array { - return $this->header->write($code, $measured); + return [$this->header->write($code, $measured)]; } #[Override] diff --git a/tests/bench/AnalysedFileHeader.php b/tests/bench/AnalysedFileHeader.php index d15bea1e012..164d135ff93 100644 --- a/tests/bench/AnalysedFileHeader.php +++ b/tests/bench/AnalysedFileHeader.php @@ -2,16 +2,14 @@ namespace PHPStan\Benchmark; +use Tally\Expectation\CodeEdit; use Tally\Expectation\ExpectationException; use Tally\Metric; use Tally\Metrics; use Tally\Quantity\InvalidQuantityException; -use function addcslashes; use function preg_match; -use function preg_replace; use function sprintf; use function strlen; -use function substr; /** * Reads and writes the expected numbers in the comment after the first line of a benchmark in data/: @@ -24,7 +22,7 @@ * * memory: 4.520MiB * *\/ * - * Takes code and returns code, AnalysedFileExpectations reads the file. + * Takes code and returns the edit of it, AnalysedFileExpectations reads the file. */ final class AnalysedFileHeader { @@ -47,9 +45,11 @@ public function read(string $code): ?Metrics } /** + * Replaces the comment, or adds it after the format($metrics, Metric::Cycles), $this->format($metrics, Metric::Memory), ); - if (preg_match(self::PATTERN, $code) === 1) { - // the replacement reads $ and \ - return (string) preg_replace(self::PATTERN, '$1' . "\n" . addcslashes($header, '$\\'), $code); + if (preg_match(self::PATTERN, $code, $matches) === 1) { + return new CodeEdit(strlen($matches[1]), strlen($matches[0]) - strlen($matches[1]), "\n" . $header); } if (preg_match('~\A<\?php[^\n]*\n~', $code, $matches) !== 1) { throw new ExpectationException('The benchmark does not start with a