From 7b83fbeb43a9bb42857d8625b18d16c044e6272c Mon Sep 17 00:00:00 2001 From: Alberto Peripolli Date: Fri, 28 Nov 2025 09:03:15 +0100 Subject: [PATCH 1/3] type coverage 100% --- phpstan.neon | 2 +- src/Models/Error.php | 2 +- src/Models/Model.php | 2 +- src/Models/Transaction.php | 2 +- tests/AgentTest.php | 5 +++-- tests/NestedSegmentsTest.php | 4 ++-- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 9263e67..24adda2 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,7 +5,7 @@ parameters: type_coverage: return: 100 - param: 90 + param: 100 property: 100 declare: 100 constant: 0 diff --git a/src/Models/Error.php b/src/Models/Error.php index 57103b2..a438c67 100644 --- a/src/Models/Error.php +++ b/src/Models/Error.php @@ -91,7 +91,7 @@ public function stackTraceToArray(Throwable $throwable): array // Exception object `getTrace` does not return file and line number for the first line // http://php.net/manual/en/exception.gettrace.php#107563 - $inApp = function ($file): bool { + $inApp = function (string $file): bool { return !str_contains($file, 'vendor') && !str_contains($file, 'index.php') && !str_contains($file, 'web/core'); // Drupal diff --git a/src/Models/Model.php b/src/Models/Model.php index 772c90f..6c888d3 100644 --- a/src/Models/Model.php +++ b/src/Models/Model.php @@ -34,7 +34,7 @@ public function only(array $keys): array public function jsonSerialize(): array { - return array_filter($this->getProperties(), fn($value): bool|int => + return array_filter($this->getProperties(), fn(mixed $value): bool|int => // remove NULL, FALSE, empty strings and empty arrays, but keep values of 0 (zero) is_array($value) || is_object($value) ? !empty($value) : strlen((string) ($value ?? ''))); } diff --git a/src/Models/Transaction.php b/src/Models/Transaction.php index 0697be5..2837a8e 100644 --- a/src/Models/Transaction.php +++ b/src/Models/Transaction.php @@ -63,7 +63,7 @@ public function setType(string $type): Transaction * * @param integer|string $id */ - public function withUser($id, ?string $name = null, ?string $email = null): Transaction + public function withUser(int|string $id, ?string $name = null, ?string $email = null): Transaction { $this->user = new User($id, $name, $email); return $this; diff --git a/tests/AgentTest.php b/tests/AgentTest.php index 91620c3..95f844a 100644 --- a/tests/AgentTest.php +++ b/tests/AgentTest.php @@ -60,14 +60,15 @@ public function testCallbackReturn(): void public function testAddSegmentWithInput(): void { - $this->inspector->addSegment(function ($segment): void { + $this->inspector->addSegment(function (Segment $segment): void { $this->assertInstanceOf(Segment::class, $segment); }, 'callback', 'test callback', true); } public function testAddSegmentWithInputContext(): void { - $segment = $this->inspector->addSegment(fn($segment) => $segment->setContext(['foo' => 'bar']), 'callback', 'test callback', true); + $segment = $this->inspector + ->addSegment(fn(Segment $segment) => $segment->setContext(['foo' => 'bar']), 'callback', 'test callback', true); $this->assertEquals(['foo' => 'bar'], $segment->getContext()); } diff --git a/tests/NestedSegmentsTest.php b/tests/NestedSegmentsTest.php index 9d679f0..4dfd7e6 100644 --- a/tests/NestedSegmentsTest.php +++ b/tests/NestedSegmentsTest.php @@ -180,7 +180,7 @@ public function testMixedStartAndAddSegment(): void $this->inspector->startSegment('parent', 'parent-operation'); - $result = $this->inspector->addSegment(function ($segment): string { + $result = $this->inspector->addSegment(function (Segment $segment): string { $this->assertEquals($this->inspector->getOpenSegments()[0]['hash'], $segment->parent_hash); // Start another segment inside the callback @@ -268,7 +268,7 @@ public function testAddSegmentWithExceptionHandling(): void $this->inspector->startSegment('parent', 'parent-operation'); // Test with throw = false - $result = $this->inspector->addSegment(function ($segment): void { + $result = $this->inspector->addSegment(function (): void { throw new Exception('Test exception'); }, 'child', 'child-operation', false); From 7e93e18091b8014d2c33695404699791bddab7ca Mon Sep 17 00:00:00 2001 From: Alberto Peripolli Date: Fri, 28 Nov 2025 09:04:27 +0100 Subject: [PATCH 2/3] format --- src/Models/Model.php | 2 +- tests/AgentTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Models/Model.php b/src/Models/Model.php index 6c888d3..87a3c4a 100644 --- a/src/Models/Model.php +++ b/src/Models/Model.php @@ -34,7 +34,7 @@ public function only(array $keys): array public function jsonSerialize(): array { - return array_filter($this->getProperties(), fn(mixed $value): bool|int => + return array_filter($this->getProperties(), fn (mixed $value): bool|int => // remove NULL, FALSE, empty strings and empty arrays, but keep values of 0 (zero) is_array($value) || is_object($value) ? !empty($value) : strlen((string) ($value ?? ''))); } diff --git a/tests/AgentTest.php b/tests/AgentTest.php index e33e5a2..f401d1b 100644 --- a/tests/AgentTest.php +++ b/tests/AgentTest.php @@ -68,7 +68,7 @@ public function testAddSegmentWithInput(): void public function testAddSegmentWithInputContext(): void { $segment = $this->inspector - ->addSegment(fn(Segment $segment) => $segment->setContext(['foo' => 'bar']), 'callback', 'test callback', true); + ->addSegment(fn (Segment $segment) => $segment->setContext(['foo' => 'bar']), 'callback', 'test callback', true); $this->assertEquals(['foo' => 'bar'], $segment->getContext()); } From 9688b95810f2f1161f7da6bf7bbcfdc7389d4934 Mon Sep 17 00:00:00 2001 From: Alberto Peripolli Date: Fri, 28 Nov 2025 10:15:05 +0100 Subject: [PATCH 3/3] fixer parallel mode --- .php-cs-fixer.dist.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 9250928..50f0a34 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -2,6 +2,7 @@ use PhpCsFixer\Config; use PhpCsFixer\Finder; +use PhpCsFixer\Runner\Parallel\ParallelConfigFactory; $finder = Finder::create() ->in(__DIR__) @@ -24,4 +25,5 @@ 'import_functions' => true, ] ]) + ->setParallelConfig(ParallelConfigFactory::detect()) ->setFinder($finder);