Skip to content

Commit 9c87823

Browse files
authored
Merge pull request #1 from BinarCode/docs
Docs
2 parents 83cfe3b + 977b08d commit 9c87823

File tree

7 files changed

+61
-7
lines changed

7 files changed

+61
-7
lines changed

.github/workflows/run-tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ jobs:
88
strategy:
99
fail-fast: true
1010
matrix:
11-
os: [ubuntu-latest, windows-latest]
11+
os: [ubuntu-latest]
1212
php: [8.0, 7.4]
1313
laravel: [8.*]
14-
stability: [prefer-lowest, prefer-stable]
14+
stability: [prefer-stable]
1515
include:
1616
- laravel: 8.*
1717
testbench: 6.*
@@ -28,7 +28,7 @@ jobs:
2828
php-version: ${{ matrix.php }}
2929
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
3030
coverage: none
31-
31+
3232
- name: Setup problem matchers
3333
run: |
3434
echo "::add-matcher::${{ runner.tool_cache }}/php.json"

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,31 @@ return [
5656

5757
## Usage
5858

59+
### Send exception to slack
60+
5961
The simplies way to use the package is to send an exception to the slack:
6062

6163
```php
64+
use Binarcode\LaravelDeveloper\LaravelDeveloper;
65+
6266
LaravelDeveloper::exceptionToDevSlack(
6367
new \Exception('wew')
6468
);
6569
```
6670

71+
### Send anything to slack
72+
73+
Obviously, you can send any kind of message to the slack channel. The `toDevSlack` method accept an instance of `DevNotificationDto`:
74+
75+
```php
76+
use Binarcode\LaravelDeveloper\LaravelDeveloper;
77+
use Binarcode\LaravelDeveloper\Dtos\DevNotificationDto;
78+
79+
LaravelDeveloper::toDevSlack(
80+
DevNotificationDto::makeWithMessage('hey')
81+
);
82+
```
83+
6784
### Persist exception
6885

6986
If you want to persist the exception into the database, in any place you want to catch and log an exception, you can do something like this:

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"require-dev": {
2424
"orchestra/testbench": "^6.0",
2525
"phpunit/phpunit": "^9.3",
26-
"vimeo/psalm": "^3.11"
26+
"vimeo/psalm": "^4.3"
2727
},
2828
"autoload": {
2929
"psr-4": {

src/Dtos/DevNotificationDto.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,21 @@ public function getAttachmentContent(): ?string
4949
return $this->attachment_content ?? $this->attachment_title;
5050
}
5151

52-
public static function makeFromException(Throwable $t)
52+
public static function makeWithMessage(string $message): self
53+
{
54+
return new static([
55+
'message' => $message,
56+
]);
57+
}
58+
59+
public static function makeFromException(Throwable $t): self
5360
{
5461
return new static([
5562
'message' => $t->getMessage(),
5663
]);
5764
}
5865

59-
public static function makeFromExceptionLog(ExceptionLog $log)
66+
public static function makeFromExceptionLog(ExceptionLog $log): self
6067
{
6168
return new static([
6269
'message' => $log->name,

src/LaravelDeveloper.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,23 @@ public static function notifyDev(Notification $notification)
2727
);
2828
}
2929

30+
public static function toDevSlack(DevNotificationDto $dto)
31+
{
32+
/**
33+
* @var string $class
34+
*/
35+
$class = config('developer.notification', DevNotification::class);
36+
37+
static::notifyDev(new $class(
38+
$dto
39+
));
40+
}
41+
3042
public static function exceptionToDevSlack(Throwable $t)
3143
{
44+
/**
45+
* @var string $class
46+
*/
3247
$class = config('developer.notification', DevNotification::class);
3348

3449
static::notifyDev(new $class(
@@ -38,6 +53,9 @@ public static function exceptionToDevSlack(Throwable $t)
3853

3954
public static function exceptionLogToDevSlack(ExceptionLog $log)
4055
{
56+
/**
57+
* @var string $class
58+
*/
4159
$class = config('developer.notification', DevNotification::class);
4260

4361
static::notifyDev(new $class(

src/Models/ExceptionLog.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* @property-read string $identifier
1919
* @property string $name
2020
* @property array $exception
21-
* @property array $payload
21+
* @property array|mixed $payload
2222
* @package App\Models
2323
*/
2424
class ExceptionLog extends Model

tests/Models/LaravelDeveloperTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Binarcode\LaravelDeveloper\Tests\Models;
44

5+
use Binarcode\LaravelDeveloper\Dtos\DevNotificationDto;
56
use Binarcode\LaravelDeveloper\LaravelDeveloper;
67
use Binarcode\LaravelDeveloper\Models\ExceptionLog;
78
use Binarcode\LaravelDeveloper\Notifications\DevNotification;
@@ -40,4 +41,15 @@ public function test_can_notify_any_exception()
4041

4142
Notification::assertSentTo(new AnonymousNotifiable, DevNotification::class);
4243
}
44+
45+
public function test_can_notify_any_dto()
46+
{
47+
Notification::fake();
48+
49+
LaravelDeveloper::toDevSlack(
50+
DevNotificationDto::makeWithMessage('hey')
51+
);
52+
53+
Notification::assertSentTo(new AnonymousNotifiable, DevNotification::class);
54+
}
4355
}

0 commit comments

Comments
 (0)