diff --git a/composer.json b/composer.json index b89b82e..4537ad8 100644 --- a/composer.json +++ b/composer.json @@ -19,15 +19,16 @@ ], "require": { "php": "^7.4", + "ext-json": "*", "illuminate/support": "^6.0", + "league/commonmark": "^1.1", + "league/commonmark-extras": "^1.1", "monolog/monolog": "~1.11", "nesbot/carbon": "^2.0", + "reliqarts/laravel-common": "^5.0", "symfony/browser-kit": "^4.3", "symfony/process": "~4.0", - "symfony/yaml": "^4.3", - "ext-json": "*", - "league/commonmark": "^1.1", - "league/commonmark-extras": "^1.1" + "symfony/yaml": "^4.3" }, "require-dev": { "phpunit/phpunit": "^8.5", diff --git a/src/Result.php b/src/Result.php index fdc7bc3..ffad756 100644 --- a/src/Result.php +++ b/src/Result.php @@ -4,142 +4,8 @@ namespace ReliqArts\Docweaver; -use Illuminate\Contracts\Support\Arrayable; -use Illuminate\Contracts\Support\Jsonable; -use stdClass; +use ReliqArts\Result as BaseResult; -class Result implements Arrayable, Jsonable +class Result extends BaseResult { - /** - * @var bool - */ - private bool $success; - - /** - * @var string - */ - private string $error; - - /** - * @var string[] - */ - private array $messages; - - /** - * @var null|stdClass - */ - private $extra; - - /** - * Result constructor. - * - * @param string[] $messages - * @param mixed $extra - */ - public function __construct( - bool $success = true, - string $error = '', - array $messages = [], - $extra = null - ) { - $this->success = $success; - $this->error = $error; - $this->messages = $messages; - $this->extra = $extra; - } - - public function isSuccess(): bool - { - return $this->success; - } - - public function setSuccess(bool $success): self - { - $clone = clone $this; - $clone->success = $success; - - return $clone; - } - - public function getError(): string - { - return $this->error; - } - - public function setError(string $error): self - { - $clone = clone $this; - $clone->error = $error; - $clone->success = false; - - return $clone; - } - - public function getExtra(): ?stdClass - { - return $this->extra; - } - - public function setExtra(stdClass $extra): self - { - $clone = clone $this; - $clone->extra = $extra; - - return $clone; - } - - public function getMessage(): string - { - return empty($this->messages) ? '' : current($this->messages); - } - - public function setMessage(string $message): self - { - return $this->addMessage($message); - } - - /** - * @return string[] - */ - public function getMessages(): array - { - return $this->messages; - } - - /** - * @param string ...$messages - */ - public function setMessages(string ...$messages): self - { - $clone = clone $this; - $clone->messages = $messages; - - return $clone; - } - - public function addMessage(string $message): self - { - $clone = clone $this; - $clone->messages[] = $message; - - return $clone; - } - - /** - * {@inheritdoc} - */ - public function toArray(): array - { - return (array)$this; - } - - /** - * {@inheritdoc} - * - * @param int $options - */ - public function toJson($options = 0): string - { - return json_encode($this->toArray(), JSON_THROW_ON_ERROR); - } }