Skip to content

Commit

Permalink
Ongoing refactoring to use JsonApi Objects throughout codebase.
Browse files Browse the repository at this point in the history
  • Loading branch information
elb98rm committed Mar 26, 2021
1 parent 0a0dc66 commit 5b53512
Show file tree
Hide file tree
Showing 10 changed files with 1,062 additions and 88 deletions.
268 changes: 268 additions & 0 deletions src/Models/Error.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,268 @@
<?php
/**
* Error.php
*
* Error class
*
* php 7.4+
*
* @category None
* @package Floor9design\JsonApiFormatter\Models
* @author Rick Morice <rick@floor9design.com>
* @copyright Floor9design Ltd
* @license MIT
* @version 1.0
* @link https://www.floor9design.com
* @since File available since Release 1.0
*
*/

namespace Floor9design\JsonApiFormatter\Models;

/**
* Class Error
*
* Class to offer methods/properties to prepare data for an Error
* These are set to the v1.0 specification, defined at https://jsonapi.org/format/
*
* @category None
* @package Floor9design\JsonApiFormatter\Models
* @author Rick Morice <rick@floor9design.com>
* @copyright Floor9design Ltd
* @license MIT
* @version 1.0
* @link https://www.floor9design.com
* @link https://jsonapi.org/
* @link https://jsonapi-validator.herokuapp.com/
* @since File available since Release 1.0
* @see https://jsonapi.org/format/
*/
class Error
{
// Properties

/**
* @var string|null
*/
var ?string $id = null;

/**
* @var Links|null
*/
var ?Links $links = null;

/**
* @var string|null
*/
var ?string $status = null;

/**
* @var string|null
*/
var ?string $code = null;

/**
* @var string|null
*/
var ?string $title = null;

/**
* @var string|null
*/
var ?string $detail = null;

/**
* @var object|null
*/
var ?object $source = null;

// accessors

/**
* @return string|null
* @see $id
*/
public function getId(): ?string
{
return $this->id;
}

/**
* @param string|null $id
* @return Error
* @see $id
*/
public function setId(?string $id): Error
{
$this->id = $id;
return $this;
}

/**
* @return Links|null
* @see $links
*/
public function getLinks(): ?Links
{
return $this->links;
}

/**
* @param Links|null $links
* @return Error
* @see $links
*/
public function setLinks(?Links $links): Error
{
$this->links = $links;
return $this;
}

/**
* @return string|null
* @see $status
*/
public function getStatus(): ?string
{
return $this->status;
}

/**
* @param string|null $status
* @return Error
* @see $status
*/
public function setStatus(?string $status): Error
{
$this->status = $status;
return $this;
}

/**
* @return string|null
* @see $code
*/
public function getCode(): ?string
{
return $this->code;
}

/**
* @param string|null $code
* @return Error
* @see $code
*/
public function setCode(?string $code): Error
{
$this->code = $code;
return $this;
}

/**
* @return string|null
* @see $title
*/
public function getTitle(): ?string
{
return $this->title;
}

/**
* @param string|null $title
* @return Error
* @see $title
*/
public function setTitle(?string $title): Error
{
$this->title = $title;
return $this;
}

/**
* @return string|null
* @see $detail
*/
public function getDetail(): ?string
{
return $this->detail;
}

/**
* @param string|null $detail
* @return Error
* @see $detail
*/
public function setDetail(?string $detail): Error
{
$this->detail = $detail;
return $this;
}

/**
* @return object|null
* @see $source
*/
public function getSource(): ?object
{
return $this->source;
}

/**
* @param object|null $source
* @return Error
* @see $source
*/
public function setSource(?object $source): Error
{
$this->source = $source;
return $this;
}

// constructor

/**
* Error constructor.
* @param string|null $id
* @param Links|null $links
* @param string|null $status
* @param string|null $code
* @param string|null $title
* @param string|null $detail
* @param string|null $source
*/
public function __construct(
?string $id = null,
?Links $links = null,
?string $status = null,
?string $code = null,
?string $title = null,
?string $detail = null,
?object $source = null
) {
$this
->setId($id)
->setLinks($links)
->setStatus($status)
->setCode($code)
->setTitle($title)
->setDetail($detail)
->setSource($source);
}

/**
* @return array
*/
public function toArray(): array
{
return [
'id' => $this->getId(),
'links' => $this->getLinks(),
'status' => $this->getStatus(),
'code' => $this->getCode(),
'title' => $this->getTitle(),
'detail' => $this->getDetail(),
'source' => $this->getSource(),
];
}

}
Loading

0 comments on commit 5b53512

Please sign in to comment.