Added constants for project types (git, hg, github...).

This commit is contained in:
Dmitry Khomutov 2018-03-12 00:34:48 +07:00
commit 10d41dba81
No known key found for this signature in database
GPG key ID: EC19426474B37AAC
4 changed files with 85 additions and 32 deletions

View file

@ -2,10 +2,21 @@
namespace PHPCensor\Model\Base;
use PHPCensor\Exception\HttpException\ValidationException;
use PHPCensor\Model;
class Project extends Model
{
const TYPE_LOCAL = 'local';
const TYPE_GIT = 'git';
const TYPE_GITHUB = 'github';
const TYPE_BITBUCKET = 'bitbucket';
const TYPE_GITLAB = 'gitlab';
const TYPE_GOGS = 'gogs';
const TYPE_HG = 'hg';
const TYPE_BITBUCKET_HG = 'bitbucket-hg';
const TYPE_SVN = 'svn';
/**
* @var string
*/
@ -32,6 +43,21 @@ class Project extends Model
'user_id' => 0,
];
/**
* @var array
*/
protected $allowedTypes = [
self::TYPE_LOCAL,
self::TYPE_GIT,
self::TYPE_GITHUB,
self::TYPE_BITBUCKET,
self::TYPE_GITLAB,
self::TYPE_GOGS,
self::TYPE_HG,
self::TYPE_BITBUCKET_HG,
self::TYPE_SVN,
];
/**
* @return integer
*/
@ -247,12 +273,20 @@ class Project extends Model
* @param string $value
*
* @return boolean
*
* @throws ValidationException
*/
public function setType($value)
{
$this->validateNotNull('type', $value);
$this->validateString('type', $value);
if (!in_array($value, $this->allowedTypes, true)) {
throw new ValidationException(
'Column "type" must be one of: ' . join(', ', $this->allowedTypes) . '.'
);
}
if ($this->data['type'] === $value) {
return false;
}