Skip to content

Commit

Permalink
Remove PHP 5 specific exception handling from lang.Throwable::wrap()
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Mar 16, 2024
1 parent 1fc79d6 commit 9b9d2b5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
4 changes: 3 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ XP Framework Core ChangeLog

### Features

* Suppress *implicitly nullable parameter types* deprecation warning as
* Removed PHP 5 specific exception handling from `lang.Throwable::wrap()`
(@thekid)
* Suppressed *implicitly nullable parameter types* deprecation warning as
there is no way of fixing these syntactically as long as we support
PHP 7.0. See issue #336 and xp-framework/rfc#343
(@thekid)
Expand Down
6 changes: 1 addition & 5 deletions src/main/php/lang/Throwable.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,13 @@ public function __construct($message, $cause= null, $fill= true) {
/**
* Wraps an exception inside a throwable
*
* @param lang.Throwable|php.Throwable|php.Exception $e
* @param lang.Throwable|php.Throwable $e
* @return self
* @throws lang.IllegalArgumentException
*/
public static function wrap($e): self {
if ($e instanceof self) {
return $e;
} else if ($e instanceof \BadMethodCallException) {
$wrapped= new Error($e->getMessage(), $e->getPrevious(), false);
} else if ($e instanceof \Exception) {
$wrapped= new XPException($e->getMessage(), $e->getPrevious(), false);
} else if ($e instanceof \Throwable) {
$wrapped= new Error($e->getMessage(), $e->getPrevious(), false);
} else {
Expand Down
9 changes: 1 addition & 8 deletions src/test/php/lang/unittest/ExceptionsTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use io\streams\{MemoryOutputStream, Streams};
use lang\{Error, IllegalArgumentException, Throwable, XPClass, XPException};
use test\verify\Runtime;
use test\{Action, Assert, Expect, Test};

class ExceptionsTest {
Expand Down Expand Up @@ -132,13 +131,7 @@ public function wrap_xp_exceptions() {
}

#[Test]
public function wrap_php5_exceptions() {
$e= new \Exception('Test');
Assert::instance(XPException::class, Throwable::wrap($e));
}

#[Test, Runtime(php: '>=7.0.0')]
public function wrap_php7_exceptions() {
public function wrap_php_exceptions() {
$e= new \TypeError('Test');
Assert::instance(Error::class, Throwable::wrap($e));
}
Expand Down

0 comments on commit 9b9d2b5

Please sign in to comment.