Skip to content

Commit dde8783

Browse files
committed
Remove Enum support in CLI mode
1 parent f92e67e commit dde8783

File tree

6 files changed

+29
-26
lines changed

6 files changed

+29
-26
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ All Notable changes to `bakame/stackwatch` will be documented in this file.
2323
### Remove
2424

2525
- `MetricsAssertions` trait replaced by the `PerformanceAssertions` trait
26+
- **BC BREAK:** Enums can no longer be profiled using the CLI instance as it was making no sense.
2627

2728
## [0.15.0 - Ouagadougou](https://github.com/bakame-php/stackwatch/compare/0.14.0...0.15.0) - 2025-09-09
2829

composer.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@
2626
"require": {
2727
"php": "^8.1",
2828
"psr/log": "^3.0.2",
29-
"symfony/console": "^6.4 || ^7.3.2",
30-
"symfony/process": "^6.4 || ^7.3"
29+
"symfony/console": "^6.4 || ^7.4.4 || ^v8.0",
30+
"symfony/process": "^6.4 || ^7.4.5 || ^v8.0"
3131
},
3232
"require-dev": {
33-
"friendsofphp/php-cs-fixer": "^3.85.1",
34-
"monolog/monolog": "^3.9",
33+
"friendsofphp/php-cs-fixer": "^3.93.1",
34+
"monolog/monolog": "^3.10",
3535
"nyholm/psr7": "^1.8.2",
36-
"open-telemetry/exporter-otlp": "^1.3.2",
37-
"phpstan/phpstan": "^2.1.21",
36+
"open-telemetry/exporter-otlp": "^1.3.4",
37+
"phpstan/phpstan": "^2.1.38",
3838
"phpstan/phpstan-deprecation-rules": "^2.0.3",
39-
"phpstan/phpstan-phpunit": "^2.0.7",
40-
"phpstan/phpstan-strict-rules": "^2.0.6",
41-
"phpunit/phpunit": "^10.5.15 || ^11.5.25 || ^12.2.9",
42-
"symfony/http-client": "^v6.4.19 || ^7.3.2",
43-
"symfony/var-dumper": "^6.4.21 || ^7.3.2"
39+
"phpstan/phpstan-phpunit": "^2.0.12",
40+
"phpstan/phpstan-strict-rules": "^2.0.8",
41+
"phpunit/phpunit": "^10.5.15 || ^11.5.25 || ^12.5.9",
42+
"symfony/http-client": "^v6.4.19 || ^7.4.5 || ^v8.0",
43+
"symfony/var-dumper": "^6.4.21 || ^7.4.4 || ^v8.0"
4444
},
4545
"autoload": {
4646
"psr-4": {

docs/index.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,17 @@ require 'vendor/autoload.php';
5353

5454
trait TimerTrait {
5555
#[Profile]
56-
private function test() : int {
56+
private function test() : int
57+
{
5758
usleep(100);
5859

5960
return random_int(1, 100);
6061
}
6162
}
6263

63-
enum MyEnum
64+
class MyClass
6465
{
6566
use TimerTrait;
66-
67-
case Case1;
68-
case Case2;
6967
}
7068
```
7169

@@ -83,7 +81,7 @@ Runtime: PHP 8.3.25 OS: Linux Memory Limit: 64M
8381

8482
............................
8583

86-
Target: Foobar\Baz\MyEnum::test; Path: /path/to/profiling/code.php; Iterations: 3; Warmup: 0; Type: Full;
84+
Target: Foobar\Baz\MyClass::test; Path: /path/to/profiling/code.php; Iterations: 3; Warmup: 0; Type: Full;
8785

8886
+-------------------------------+------------+------------+------------+------------+------------+------------+--------------+---------------+-----------+-----------+
8987
| Metrics | iterations | Min Value | Max Value | Range | Sum | Average | Median Value | Variance | Std Dev | Coef Var |

src/Console/PathProfilerTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function testMethod(): void
120120
$output = $this->stdout->fetch();
121121
$errorOutput = $this->stderr->fetch();
122122

123-
self::assertStringContainsString('Full', $output);
123+
self::assertEmpty($output);
124124
self::assertEmpty($errorOutput, 'No errors expected');
125125
}
126126

@@ -134,10 +134,8 @@ public function it_will_skip_methods_with_arguments(): void
134134
use Bakame\Stackwatch\AggregationType;
135135
use Bakame\Stackwatch\Profile;
136136
137-
enum TestMethodWithArguments
137+
class TestMethodWithArguments
138138
{
139-
case Foo;
140-
141139
#[Profile(iterations: 3, warmup: 1, type: AggregationType::Average)]
142140
public function testMethod(string $foo): string
143141
{

src/Console/UnitOfWork.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,14 @@ function_exists($this->function) || throw new UnableToProfile('The function '.$t
229229
0 === $refMethod->getNumberOfRequiredParameters() || throw new UnableToProfile('The method '.$this->class.'::'.$this->method.' cannot be profiled because it has required parameters.');
230230

231231
if ($refMethod->isStatic()) {
232-
$this->callback = fn () => $refMethod->invoke(null);
232+
$this->callback = fn () => $refMethod->invoke(null);
233233

234234
return $this->callback;
235235
}
236236

237-
$instance = $refClass instanceof ReflectionEnum ? $refClass->getCases()[0]->getValue() : $refClass->newInstance();
237+
!$refClass instanceof ReflectionEnum || throw new UnableToProfile('The method '.$this->class.'::'.$this->method.' belongs to an enum and can only be profiled when executed by a case.');
238238

239-
$this->callback = fn () => $refMethod->invoke($instance);
239+
$this->callback = fn () => $refMethod->invoke($refClass->newInstance());
240240

241241
return $this->callback;
242242
}

src/Console/UnitOfWorkGenerator.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
use function array_reduce;
2121
use function class_exists;
2222
use function count;
23+
use function enum_exists;
2324
use function function_exists;
25+
use function in_array;
2426

2527
final class UnitOfWorkGenerator
2628
{
@@ -90,8 +92,12 @@ private function prepareMethodsProcess(string $className, Input $input): array
9092
return [];
9193
}
9294

93-
$refClass = enum_exists($className) ? new ReflectionEnum($className) : new ReflectionClass($className);
94-
$targetRequiresConstructorArgs = !$refClass instanceof ReflectionEnum && (($refClass->getConstructor()?->getNumberOfRequiredParameters() ?? 0) !== 0);
95+
if (enum_exists($className)) {
96+
return [];
97+
}
98+
99+
$refClass = new ReflectionClass($className);
100+
$targetRequiresConstructorArgs = 0 !== ($refClass->getConstructor()?->getNumberOfRequiredParameters() ?? 0);
95101
$parentProfile = $this->findProfile($refClass);
96102

97103
$results = [];

0 commit comments

Comments
 (0)