Skip to content

Commit 02f7e43

Browse files
committed
Improve Exception handling
1 parent dde8783 commit 02f7e43

7 files changed

Lines changed: 21 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ All Notable changes to `bakame/stackwatch` will be documented in this file.
88

99
- `PerformanceAssertions` to align with `AggregatedMetrics` usage and generation.
1010
- `Report::iterations()` method is added.
11+
- `StackWatchException`
12+
- `NoMetricSelected` exceptions
1113

1214
### Fixed
1315

1416
- **BC BREAK:** improve `Report` generation validation and adds missing `Report::iterations()` method
1517
- `AggregatedMetrics::dd` and `Statistics::dd` improved implementation
1618
- **BC BREAK:** global functions are namespaced
17-
- Improve github actions
19+
- Improve Github actions
20+
- **BC BREAK:** exceptions are now all inheriting from a base `StackWatchException`
1821

1922
### Deprecated
2023

docs/1.0/command.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,9 @@ trait TimerTrait {
4141
}
4242
}
4343

44-
enum Foobar
44+
class Foobar
4545
{
4646
use TimerTrait;
47-
48-
case Foobar;
4947
}
5048

5149
#[Profile(iterations: 20, warmup: 2)]

src/InvalidArgument.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
namespace Bakame\Stackwatch;
66

7-
use InvalidArgumentException;
8-
9-
final class InvalidArgument extends InvalidArgumentException implements ProfilingException
7+
class InvalidArgument extends StackWatchException
108
{
119
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace Bakame\Stackwatch;
66

7-
use Throwable;
7+
use Exception;
88

9-
interface ProfilingException extends Throwable
9+
class StackWatchException extends Exception
1010
{
1111
}

src/Test/MetricNotSelected.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bakame\Stackwatch\Test;
6+
7+
use Bakame\Stackwatch\StackWatchException;
8+
9+
class MetricNotSelected extends StackWatchException
10+
{
11+
}

src/Test/MetricsAssert.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Bakame\Stackwatch\DurationUnit;
99
use Bakame\Stackwatch\MemoryUnit;
1010
use Bakame\Stackwatch\Metrics;
11-
use LogicException;
1211
use PHPUnit\Framework\Assert;
1312
use ValueError;
1413

@@ -47,7 +46,7 @@ public function __call(string $name, array $args = []): self
4746

4847
private function getValue(): float|int
4948
{
50-
null !== $this->current || throw new LogicException('No metric selected before assertion.');
49+
null !== $this->current || throw new MetricNotSelected('No metric selected before assertion.');
5150

5251
return $this->metrics->{$this->current}; /* @phpstan-ignore-line */
5352
}

src/UnableToProfile.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
namespace Bakame\Stackwatch;
66

7-
use LogicException;
8-
9-
class UnableToProfile extends LogicException implements ProfilingException
7+
class UnableToProfile extends StackWatchException
108
{
119
}

0 commit comments

Comments
 (0)