diff --git a/README.md b/README.md index ff36a64..4576e3d 100644 --- a/README.md +++ b/README.md @@ -40,16 +40,13 @@ Telebugs\configure(function ($config) { $config->setApiKey("YOUR_API_KEY"); }); - try { 1 / 0; } catch (DivisionByZeroError $e) { - Telebugs\report($e); + Telebugs\report($e)->wait(); } -sleep(2); - -echo "An error was sent to Telebugs asynchronously." . +echo "An error was sent to Telebugs." . "It will appear in your dashboard shortly." . "A notification was also sent to your Telegram chat." ?> diff --git a/src/Promise.php b/src/Promise.php deleted file mode 100644 index b89dae1..0000000 --- a/src/Promise.php +++ /dev/null @@ -1,38 +0,0 @@ -promise = $promise; - } - - // @phpstan-ignore missingType.parameter - public function then(...$args): Promise - { - return new Promise($this->promise->then(...$args)); - } - - // @phpstan-ignore missingType.parameter - public function otherwise(...$args): Promise - { - return new Promise($this->promise->otherwise(...$args)); - } - - // @phpstan-ignore missingType.parameter, missingType.return - public function wait(...$args) - { - return $this->promise->wait(...$args); - } - - public function getState(): string - { - return $this->promise->getState(); - } -} diff --git a/src/Reporter.php b/src/Reporter.php index ea2197a..2efa650 100644 --- a/src/Reporter.php +++ b/src/Reporter.php @@ -3,14 +3,14 @@ namespace Telebugs; use GuzzleHttp\Promise\FulfilledPromise; +use GuzzleHttp\Promise\PromiseInterface; -use Telebugs\Promise; use Telebugs\Sender; use Telebugs\Config; class Reporter { - public const VERSION = '0.1.0'; + public const VERSION = '0.2.0'; private static ?Reporter $instance = null; @@ -31,13 +31,13 @@ public function __construct() $this->config = Config::getInstance(); } - public function report(\Throwable $e): Promise + public function report(\Throwable $e): PromiseInterface { $report = new Report($e); $this->config->middleware()($report); if ($report->ignored) { - return new Promise(new FulfilledPromise("Report ignored")); + return new FulfilledPromise("Report ignored"); } return $this->sender->send($report); diff --git a/src/Sender.php b/src/Sender.php index 5cddf4d..73defac 100644 --- a/src/Sender.php +++ b/src/Sender.php @@ -2,10 +2,10 @@ namespace Telebugs; -use Telebugs\Promise; use Telebugs\Config; use Telebugs\Report; +use GuzzleHttp\Promise\PromiseInterface; use Psr\Http\Message\ResponseInterface; class Sender @@ -21,9 +21,9 @@ public function __construct() $this->config = Config::getInstance(); } - public function send(Report $report): Promise + public function send(Report $report): PromiseInterface { - $guzzlePromise = $this->config->getHttpClient()->postAsync($this->config->getApiURL(), [ + $promise = $this->config->getHttpClient()->postAsync($this->config->getApiURL(), [ 'body' => json_encode($report), 'headers' => [ 'Content-Type' => self::CONTENT_TYPE, @@ -32,7 +32,6 @@ public function send(Report $report): Promise ] ]); - $promise = new Promise($guzzlePromise); return $promise->then(function (ResponseInterface $res) { return json_decode($res->getBody()->getContents(), true); }); diff --git a/src/functions.php b/src/functions.php index da9302d..c39031a 100644 --- a/src/functions.php +++ b/src/functions.php @@ -6,14 +6,15 @@ use Telebugs\Config; use Telebugs\Reporter; -use Telebugs\Promise; + +use GuzzleHttp\Promise\PromiseInterface; function configure(\Closure $callback): void { $callback(Config::getInstance()); } -function report(\Throwable $e): Promise +function report(\Throwable $e): PromiseInterface { return Reporter::getInstance()->report($e); } diff --git a/tests/PromiseTest.php b/tests/PromiseTest.php deleted file mode 100644 index 7baa132..0000000 --- a/tests/PromiseTest.php +++ /dev/null @@ -1,49 +0,0 @@ - 1])); - $newPromise = $promise->then(function ($value) { - $value['id']++; - return $value; - }); - - $val = $newPromise->wait(); - $this->assertEquals(2, $val['id']); - } - - public function testOtherwise(): void - { - $promise = new Promise(new \GuzzleHttp\Promise\RejectedPromise(['id' => 1])); - $newPromise = $promise->otherwise(function ($value) { - $value['id']++; - return $value; - }); - - $val = $newPromise->wait(); - $this->assertEquals(2, $val['id']); - } - - public function testWait(): void - { - $promise = new Promise(new \GuzzleHttp\Promise\FulfilledPromise(['id' => 1])); - - $val = $promise->wait(); - $this->assertEquals(1, $val['id']); - } - - public function testGetState(): void - { - $promise = new Promise(new \GuzzleHttp\Promise\FulfilledPromise(1)); - - $this->assertEquals("fulfilled", $promise->getState()); - } -}