Replacing public properties by getters and setters

This commit is contained in:
Cédric Belin
2018-11-08 18:00:19 +01:00
parent ded2f54c96
commit c0653faeb7
9 changed files with 423 additions and 97 deletions

View File

@ -5,12 +5,20 @@ namespace Gitea\Models;
/**
* Warps the version of the Gitea server.
*/
class ServerVersion {
class ServerVersion implements \JsonSerializable {
/**
* @var string The version number.
*/
public $version = '';
private $version;
/**
* Creates a new server version.
* @param string $version The version number.
*/
function __construct(string $version) {
$this->version = $version;
}
/**
* Creates a new server version from the specified JSON map.
@ -18,8 +26,22 @@ class ServerVersion {
* @return static The instance corresponding to the specified JSON map.
*/
static function fromJson(object $map): self {
return new static([
'version' => isset($map->version) && is_string($map->version) ? $map->version : ''
]);
return new static(isset($map->version) && is_string($map->version) ? $map->version : '');
}
/**
* Gets the version number.
* @return string The version number.
*/
function getVersion(): string {
return $this->version;
}
/**
* Converts this object to a map in JSON format.
* @return \stdClass The map in JSON format corresponding to this object.
*/
function jsonSerialize(): \stdClass {
return (object) ['version' => $this->getVersion()];
}
}