Skip to content

Commit

Permalink
use ReliqArts\Result as BaseResult
Browse files Browse the repository at this point in the history
  • Loading branch information
reliq committed Dec 24, 2019
1 parent 189f192 commit 848e6c3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 140 deletions.
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
138 changes: 2 additions & 136 deletions src/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 848e6c3

Please sign in to comment.