Skip to content

Commit

Permalink
Follow pattern used by EventMetadata instead
Browse files Browse the repository at this point in the history
  • Loading branch information
princejohnsantillan committed Oct 23, 2024
1 parent 744602e commit 17879ab
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 30 deletions.
19 changes: 12 additions & 7 deletions src/Slack/BlockKit/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
namespace Illuminate\Notifications\Slack\BlockKit;


use Illuminate\Notifications\Slack\Contracts\BuilderContract;
use Illuminate\Contracts\Support\Arrayable;
use JsonException;

class Builder implements BuilderContract
class Builder implements Arrayable
{
protected string $payload = "[]";

public function payload(string $payload): self{
$this->payload = $payload;
public function __construct(
protected string $payload = "[]"
){
}

return $this;
/**
* Fluently create a new Builder instance.
*/
public static function make(string $payload): self
{
return new self($payload);
}

/**
Expand Down
10 changes: 0 additions & 10 deletions src/Slack/Contracts/BuilderContract.php

This file was deleted.

9 changes: 3 additions & 6 deletions src/Slack/SlackMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Illuminate\Notifications\Slack\BlockKit\Blocks\SectionBlock;
use Illuminate\Notifications\Slack\BlockKit\Builder;
use Illuminate\Notifications\Slack\Contracts\BlockContract;
use Illuminate\Notifications\Slack\Contracts\BuilderContract;
use Illuminate\Support\Arr;
use Illuminate\Support\Traits\Conditionable;
use LogicException;
Expand Down Expand Up @@ -83,7 +82,7 @@ class SlackMessage implements Arrayable
*/
protected ?bool $broadcastReply = null;

protected ?BuilderContract $builder = null;
protected ?Builder $builder = null;

/**
* Set the Slack channel the message should be sent to.
Expand All @@ -99,10 +98,8 @@ public function to(string $channel): self
/**
* Set the Block Kit Builder json payload.
*/
public function builder(BuilderContract|string $builder): self{
$this->builder = $builder instanceof BuilderContract
? $builder
: (new Builder)->payload($builder);
public function builder(string $payload): self{
$this->builder = new Builder($payload);

return $this;
}
Expand Down
9 changes: 2 additions & 7 deletions tests/Slack/Unit/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@

namespace Illuminate\Tests\Notifications\Slack\Unit;

use Illuminate\Notifications\Slack\BlockKit\Blocks\SectionBlock;
use Illuminate\Notifications\Slack\BlockKit\Builder;
use Illuminate\Notifications\Slack\BlockKit\Elements\ImageElement;
use Illuminate\Tests\Notifications\Slack\TestCase;
use JsonException;
use LogicException;

class BuilderTest extends TestCase
{
/** @test */
public function it_is_arrayable_and_removes_the_blocks_key(): void
{
$builder = new Builder();
$builder->payload(<<<JSON
$builder = new Builder(<<<JSON
{
"blocks": [
{
Expand Down Expand Up @@ -59,8 +55,7 @@ public function it_throws_an_exception_if_payload_is_invalid_json(): void
{
$this->expectException(JsonException::class);

$builder = new Builder();
$builder->payload("!!!");
$builder = new Builder("!!!");
$builder->toArray();
}
}

0 comments on commit 17879ab

Please sign in to comment.