From fb11ba4652d29806db071b1276ab2e1daaa822ec Mon Sep 17 00:00:00 2001
From: Dmitry Khomutov
Date: Sat, 10 Mar 2018 01:00:53 +0700
Subject: [PATCH] Refactored models.
---
runtime/builds/.gitkeep | 0
src/Command/CreateAdminCommand.php | 2 +-
src/Command/InstallCommand.php | 2 +-
src/Controller/ProjectController.php | 6 +-
src/Controller/UserController.php | 2 +-
...23052715_added_request_branch_to_build.php | 2 +-
src/Model.php | 23 +-
src/Model/Base/Build.php | 455 ++++++++++++++
src/Model/Base/BuildError.php | 307 +++++++++
src/Model/Base/BuildMeta.php | 123 ++++
src/Model/Base/Environment.php | 128 ++++
src/Model/Base/Project.php | 461 ++++++++++++++
src/Model/Base/ProjectGroup.php | 126 ++++
src/Model/Base/User.php | 284 +++++++++
src/Model/Build.php | 590 +-----------------
src/Model/BuildError.php | 374 +----------
src/Model/BuildMeta.php | 162 +----
src/Model/Environment.php | 146 +----
src/Model/Project.php | 563 +----------------
src/Model/ProjectGroup.php | 160 +----
src/Model/User.php | 321 +---------
.../Authentication/UserProvider/Ldap.php | 2 +-
src/Service/BuildService.php | 14 +-
src/Service/ProjectService.php | 10 +-
src/Service/UserService.php | 8 +-
src/View/Build/view.phtml | 2 +-
src/View/BuildStatus/view.phtml | 5 +-
src/View/Email/long.phtml | 2 +-
src/View/Email/short.phtml | 2 +-
src/View/WidgetLastBuilds/update.phtml | 5 +-
tests/src/Model/BuildTest.php | 20 +-
tests/src/Service/BuildServiceTest.php | 2 +-
tests/src/Service/ProjectServiceTest.php | 8 +-
tests/src/Service/UserServiceTest.php | 24 +-
34 files changed, 2006 insertions(+), 2335 deletions(-)
delete mode 100644 runtime/builds/.gitkeep
create mode 100644 src/Model/Base/Build.php
create mode 100644 src/Model/Base/BuildError.php
create mode 100644 src/Model/Base/BuildMeta.php
create mode 100644 src/Model/Base/Environment.php
create mode 100644 src/Model/Base/Project.php
create mode 100644 src/Model/Base/ProjectGroup.php
create mode 100644 src/Model/Base/User.php
diff --git a/runtime/builds/.gitkeep b/runtime/builds/.gitkeep
deleted file mode 100644
index e69de29b..00000000
diff --git a/src/Command/CreateAdminCommand.php b/src/Command/CreateAdminCommand.php
index 113974bf..34335573 100644
--- a/src/Command/CreateAdminCommand.php
+++ b/src/Command/CreateAdminCommand.php
@@ -85,7 +85,7 @@ class CreateAdminCommand extends Command
try {
$userService = new UserService($this->userStore);
- $userService->createUser($adminName, $adminEmail, 'internal', json_encode(['type' => 'internal']), $adminPassword, true);
+ $userService->createUser($adminName, $adminEmail, 'internal', ['type' => 'internal'], $adminPassword, true);
$output->writeln('User account created!');
} catch (\Exception $ex) {
diff --git a/src/Command/InstallCommand.php b/src/Command/InstallCommand.php
index e1210ebe..dba9396b 100644
--- a/src/Command/InstallCommand.php
+++ b/src/Command/InstallCommand.php
@@ -520,7 +520,7 @@ class InstallCommand extends Command
}
$userService = new UserService($userStore);
- $userService->createUser($admin['name'], $admin['email'], 'internal', json_encode(['type' => 'internal']), $admin['password'], true);
+ $userService->createUser($admin['name'], $admin['email'], 'internal', ['type' => 'internal'], $admin['password'], true);
$output->writeln('User account created!');
} catch (\Exception $ex) {
diff --git a/src/Controller/ProjectController.php b/src/Controller/ProjectController.php
index 2cd432ac..700f149b 100644
--- a/src/Controller/ProjectController.php
+++ b/src/Controller/ProjectController.php
@@ -396,10 +396,10 @@ class ProjectController extends PHPCensor\Controller
'ssh_private_key' => $this->getParam('key', null),
'ssh_public_key' => $this->getParam('pubkey', null),
'build_config' => $this->getParam('build_config', null),
- 'allow_public_status' => $this->getParam('allow_public_status', 0),
- 'archived' => $this->getParam('archived', 0),
+ 'allow_public_status' => $this->getParam('allow_public_status', false),
+ 'archived' => $this->getParam('archived', false),
'branch' => $this->getParam('branch', null),
- 'default_branch_only' => $this->getParam('default_branch_only', 0),
+ 'default_branch_only' => $this->getParam('default_branch_only', false),
'group' => $this->getParam('group_id', null),
'environments' => $this->getParam('environments', null),
];
diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php
index 5bd8ac26..d50a6bc0 100644
--- a/src/Controller/UserController.php
+++ b/src/Controller/UserController.php
@@ -182,7 +182,7 @@ class UserController extends Controller
$password = $this->getParam('password', null);
$isAdmin = (int)$this->getParam('is_admin', 0);
- $this->userService->createUser($name, $email, 'internal', json_encode(['type' => 'internal']), $password, $isAdmin);
+ $this->userService->createUser($name, $email, 'internal', ['type' => 'internal'], $password, $isAdmin);
$response = new RedirectResponse();
$response->setHeader('Location', APP_URL . 'user');
diff --git a/src/Migrations/20180223052715_added_request_branch_to_build.php b/src/Migrations/20180223052715_added_request_branch_to_build.php
index d2390c54..2c702dd6 100644
--- a/src/Migrations/20180223052715_added_request_branch_to_build.php
+++ b/src/Migrations/20180223052715_added_request_branch_to_build.php
@@ -43,7 +43,7 @@ class AddedRequestBranchToBuild extends AbstractMigration
unset($extra['build_type']);
unset($extra['pull_request_id']);
- $build->setExtra(json_encode($extra));
+ $build->setExtra($extra);
$buildStore->save($build);
}
unset($build);
diff --git a/src/Model.php b/src/Model.php
index ac51dbb2..df436500 100644
--- a/src/Model.php
+++ b/src/Model.php
@@ -6,16 +6,6 @@ use PHPCensor\Exception\HttpException\ValidationException;
class Model
{
- /**
- * @var array
- */
- protected $getters = [];
-
- /**
- * @var array
- */
- protected $setters = [];
-
/**
* @var array
*/
@@ -109,6 +99,19 @@ class Model
}
}
+ /**
+ * @param string $name
+ * @param mixed $value
+ *
+ * @throws ValidationException
+ */
+ protected function validateBoolean($name, $value)
+ {
+ if (!is_bool($value) && !is_null($value)) {
+ throw new ValidationException('Column "' . $name . '" must be a boolean.');
+ }
+ }
+
/**
* @param string $name
* @param mixed $value
diff --git a/src/Model/Base/Build.php b/src/Model/Base/Build.php
new file mode 100644
index 00000000..dab29ece
--- /dev/null
+++ b/src/Model/Base/Build.php
@@ -0,0 +1,455 @@
+ null,
+ 'project_id' => null,
+ 'commit_id' => null,
+ 'status' => null,
+ 'log' => null,
+ 'branch' => null,
+ 'tag' => null,
+ 'create_date' => null,
+ 'start_date' => null,
+ 'finish_date' => null,
+ 'committer_email' => null,
+ 'commit_message' => null,
+ 'extra' => null,
+ 'environment' => null,
+ 'source' => Build::SOURCE_UNKNOWN,
+ 'user_id' => 0,
+ ];
+
+ /**
+ * @return integer
+ */
+ public function getId()
+ {
+ return (integer)$this->data['id'];
+ }
+
+ /**
+ * @param integer $value
+ */
+ public function setId($value)
+ {
+ $this->validateNotNull('id', $value);
+ $this->validateInt('id', $value);
+
+ if ($this->data['id'] === $value) {
+ return;
+ }
+
+ $this->data['id'] = (integer)$value;
+
+ $this->setModified('id');
+ }
+
+ /**
+ * @return integer
+ */
+ public function getProjectId()
+ {
+ return (integer)$this->data['project_id'];
+ }
+
+ /**
+ * @param integer $value
+ */
+ public function setProjectId($value)
+ {
+ $this->validateNotNull('project_id', $value);
+ $this->validateInt('project_id', $value);
+
+ if ($this->data['project_id'] === $value) {
+ return;
+ }
+
+ $this->data['project_id'] = $value;
+
+ $this->setModified('project_id');
+ }
+
+ /**
+ * @return string
+ */
+ public function getCommitId()
+ {
+ return $this->data['commit_id'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setCommitId($value)
+ {
+ $this->validateNotNull('commit_id', $value);
+ $this->validateString('commit_id', $value);
+
+ if ($this->data['commit_id'] === $value) {
+ return;
+ }
+
+ $this->data['commit_id'] = $value;
+
+ $this->setModified('commit_id');
+ }
+
+ /**
+ * @return integer
+ */
+ public function getStatus()
+ {
+ return (integer)$this->data['status'];
+ }
+
+ /**
+ * @param integer $value
+ */
+ public function setStatus($value)
+ {
+ $this->validateNotNull('status', $value);
+ $this->validateInt('status', $value);
+
+ if ($this->data['status'] === $value) {
+ return;
+ }
+
+ $this->data['status'] = $value;
+
+ $this->setModified('status');
+ }
+
+ /**
+ * @return string
+ */
+ public function getLog()
+ {
+ return $this->data['log'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setLog($value)
+ {
+ $this->validateString('log', $value);
+
+ if ($this->data['log'] === $value) {
+ return;
+ }
+
+ $this->data['log'] = $value;
+
+ $this->setModified('log');
+ }
+
+ /**
+ * @return string
+ */
+ public function getBranch()
+ {
+ return $this->data['branch'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setBranch($value)
+ {
+ $this->validateNotNull('branch', $value);
+ $this->validateString('branch', $value);
+
+ if ($this->data['branch'] === $value) {
+ return;
+ }
+
+ $this->data['branch'] = $value;
+
+ $this->setModified('branch');
+ }
+
+ /**
+ * @return string
+ */
+ public function getTag()
+ {
+ return $this->data['tag'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setTag($value)
+ {
+ $this->validateString('tag', $value);
+
+ if ($this->data['tag'] === $value) {
+ return;
+ }
+
+ $this->data['tag'] = $value;
+
+ $this->setModified('tag');
+ }
+
+ /**
+ * @return \DateTime|null
+ */
+ public function getCreateDate()
+ {
+ if ($this->data['create_date']) {
+ return new \DateTime($this->data['create_date']);
+ }
+
+ return null;
+ }
+
+ /**
+ * @param \DateTime $value
+ */
+ public function setCreateDate(\DateTime $value)
+ {
+ $stringValue = $value->format('Y-m-d H:i:s');
+
+ if ($this->data['create_date'] === $stringValue) {
+ return;
+ }
+
+ $this->data['create_date'] = $stringValue;
+
+ $this->setModified('create_date');
+ }
+
+ /**
+ * @return \DateTime|null
+ */
+ public function getStartDate()
+ {
+ if ($this->data['start_date']) {
+ return new \DateTime($this->data['start_date']);
+ }
+
+ return null;
+ }
+
+ /**
+ * @param \DateTime $value
+ */
+ public function setStartDate(\DateTime $value)
+ {
+ $stringValue = $value->format('Y-m-d H:i:s');
+
+ if ($this->data['start_date'] === $stringValue) {
+ return;
+ }
+
+ $this->data['start_date'] = $stringValue;
+
+ $this->setModified('start_date');
+ }
+
+ /**
+ * @return \DateTime|null
+ */
+ public function getFinishDate()
+ {
+ if ($this->data['finish_date']) {
+ return new \DateTime($this->data['finish_date']);
+ }
+
+ return null;
+ }
+
+ /**
+ * @param \DateTime $value
+ */
+ public function setFinishDate(\DateTime $value)
+ {
+ $stringValue = $value->format('Y-m-d H:i:s');
+
+ if ($this->data['finish_date'] === $stringValue) {
+ return;
+ }
+
+ $this->data['finish_date'] = $stringValue;
+
+ $this->setModified('finish_date');
+ }
+
+ /**
+ * @return string
+ */
+ public function getCommitterEmail()
+ {
+ return $this->data['committer_email'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setCommitterEmail($value)
+ {
+ $this->validateString('committer_email', $value);
+
+ if ($this->data['committer_email'] === $value) {
+ return;
+ }
+
+ $this->data['committer_email'] = $value;
+
+ $this->setModified('committer_email');
+ }
+
+ /**
+ * @return string
+ */
+ public function getCommitMessage()
+ {
+ return $this->data['commit_message'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setCommitMessage($value)
+ {
+ $this->validateString('commit_message', $value);
+
+ if ($this->data['commit_message'] === $value) {
+ return;
+ }
+
+ $this->data['commit_message'] = $value;
+
+ $this->setModified('commit_message');
+ }
+
+ /**
+ * @param string|null $key
+ *
+ * @return array|string|null
+ */
+ public function getExtra($key = null)
+ {
+ $data = json_decode($this->data['extra'], true);
+ $extra = null;
+ if (is_null($key)) {
+ $extra = $data;
+ } elseif (isset($data[$key])) {
+ $extra = $data[$key];
+ }
+
+ return $extra;
+ }
+
+ /**
+ * @param array $value
+ */
+ public function setExtra(array $value)
+ {
+ $this->validateNotNull('branches', $value);
+
+ $extra = json_encode($value);
+ if ($this->data['extra'] === $extra) {
+ return;
+ }
+
+ $this->data['extra'] = $extra;
+
+ $this->setModified('extra');
+ }
+
+ /**
+ * @return string
+ */
+ public function getEnvironment()
+ {
+ return $this->data['environment'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setEnvironment($value)
+ {
+ $this->validateString('environment', $value);
+
+ if ($this->data['environment'] === $value) {
+ return;
+ }
+
+ $this->data['environment'] = $value;
+
+ $this->setModified('environment');
+ }
+
+ /**
+ * @return string
+ */
+ public function getSource()
+ {
+ return (integer)$this->data['source'];
+ }
+
+ /**
+ * @param integer $value
+ */
+ public function setSource($value)
+ {
+ $this->validateInt('source', $value);
+
+ if ($this->data['source'] === $value) {
+ return;
+ }
+
+ $this->data['source'] = $value;
+
+ $this->setModified('source');
+ }
+
+ /**
+ * @return string
+ */
+ public function getUserId()
+ {
+ return (integer)$this->data['user_id'];
+ }
+
+ /**
+ * @param integer $value
+ */
+ public function setUserId($value)
+ {
+ $this->validateNotNull('user_id', $value);
+ $this->validateInt('user_id', $value);
+
+ if ($this->data['user_id'] === $value) {
+ return;
+ }
+
+ $this->data['user_id'] = $value;
+
+ $this->setModified('user_id');
+ }
+}
diff --git a/src/Model/Base/BuildError.php b/src/Model/Base/BuildError.php
new file mode 100644
index 00000000..45ffb108
--- /dev/null
+++ b/src/Model/Base/BuildError.php
@@ -0,0 +1,307 @@
+ null,
+ 'build_id' => null,
+ 'plugin' => null,
+ 'file' => null,
+ 'line_start' => null,
+ 'line_end' => null,
+ 'severity' => null,
+ 'message' => null,
+ 'create_date' => null,
+ 'hash' => null,
+ 'is_new' => null,
+ ];
+
+ /**
+ * @return integer
+ */
+ public function getId()
+ {
+ return (integer)$this->data['id'];
+ }
+
+ /**
+ * @param integer $value
+ */
+ public function setId($value)
+ {
+ $this->validateNotNull('id', $value);
+ $this->validateInt('id', $value);
+
+ if ($this->data['id'] === $value) {
+ return;
+ }
+
+ $this->data['id'] = $value;
+
+ $this->setModified('id');
+ }
+
+ /**
+ * @return integer
+ */
+ public function getBuildId()
+ {
+ return (integer)$this->data['build_id'];
+ }
+
+ /**
+ * @param integer $value
+ */
+ public function setBuildId($value)
+ {
+ $this->validateNotNull('build_id', $value);
+ $this->validateInt('build_id', $value);
+
+ if ($this->data['build_id'] === $value) {
+ return;
+ }
+
+ $this->data['build_id'] = $value;
+
+ $this->setModified('build_id');
+ }
+
+ /**
+ * @return string
+ */
+ public function getPlugin()
+ {
+ return $this->data['plugin'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setPlugin($value)
+ {
+ $this->validateNotNull('plugin', $value);
+ $this->validateString('plugin', $value);
+
+ if ($this->data['plugin'] === $value) {
+ return;
+ }
+
+ $this->data['plugin'] = $value;
+
+ $this->setModified('plugin');
+ }
+
+ /**
+ * @return string
+ */
+ public function getFile()
+ {
+ return $this->data['file'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setFile($value)
+ {
+ $this->validateString('file', $value);
+
+ if ($this->data['file'] === $value) {
+ return;
+ }
+
+ $this->data['file'] = $value;
+
+ $this->setModified('file');
+ }
+
+ /**
+ * @return integer
+ */
+ public function getLineStart()
+ {
+ return (integer)$this->data['line_start'];
+ }
+
+ /**
+ * @param integer $value
+ */
+ public function setLineStart($value)
+ {
+ $this->validateInt('line_start', $value);
+
+ if ($this->data['line_start'] === $value) {
+ return;
+ }
+
+ $this->data['line_start'] = $value;
+
+ $this->setModified('line_start');
+ }
+
+ /**
+ * @return integer
+ */
+ public function getLineEnd()
+ {
+ return (integer)$this->data['line_end'];
+ }
+
+ /**
+ * @param integer $value
+ */
+ public function setLineEnd($value)
+ {
+ $this->validateInt('line_end', $value);
+
+ if ($this->data['line_end'] === $value) {
+ return;
+ }
+
+ $this->data['line_end'] = $value;
+
+ $this->setModified('line_end');
+ }
+
+ /**
+ * @return integer
+ */
+ public function getSeverity()
+ {
+ return (integer)$this->data['severity'];
+ }
+
+ /**
+ * @param integer $value
+ */
+ public function setSeverity($value)
+ {
+ $this->validateNotNull('severity', $value);
+ $this->validateInt('severity', $value);
+
+ if ($this->data['severity'] === $value) {
+ return;
+ }
+
+ $this->data['severity'] = $value;
+
+ $this->setModified('severity');
+ }
+
+ /**
+ * @return string
+ */
+ public function getMessage()
+ {
+ return $this->data['message'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setMessage($value)
+ {
+ $this->validateNotNull('message', $value);
+ $this->validateString('message', $value);
+
+ if ($this->data['message'] === $value) {
+ return;
+ }
+
+ $this->data['message'] = $value;
+
+ $this->setModified('message');
+ }
+
+ /**
+ * @return \DateTime|null
+ */
+ public function getCreateDate()
+ {
+ if ($this->data['create_date']) {
+ return new \DateTime($this->data['create_date']);
+ }
+
+ return null;
+ }
+
+ /**
+ * @param \DateTime $value
+ */
+ public function setCreateDate(\DateTime $value)
+ {
+ $this->validateNotNull('create_date', $value);
+
+ $stringValue = $value->format('Y-m-d H:i:s');
+
+ if ($this->data['create_date'] === $stringValue) {
+ return;
+ }
+
+ $this->data['create_date'] = $stringValue;
+
+ $this->setModified('create_date');
+ }
+
+ /**
+ * @return string
+ */
+ public function getHash()
+ {
+ return $this->data['hash'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setHash($value)
+ {
+ $this->validateNotNull('hash', $value);
+ $this->validateString('hash', $value);
+
+ if ($this->data['hash'] === $value) {
+ return;
+ }
+
+ $this->data['hash'] = $value;
+
+ $this->setModified('hash');
+ }
+
+ /**
+ * @return boolean
+ */
+ public function getIsNew()
+ {
+ return (boolean)$this->data['is_new'];
+ }
+
+ /**
+ * @param boolean $value
+ */
+ public function setIsNew($value)
+ {
+ $this->validateNotNull('is_new', $value);
+ $this->validateBoolean('is_new', $value);
+
+ if ($this->data['is_new'] === $value) {
+ return;
+ }
+
+ $this->data['is_new'] = (integer)$value;
+
+ $this->setModified('is_new');
+ }
+}
diff --git a/src/Model/Base/BuildMeta.php b/src/Model/Base/BuildMeta.php
new file mode 100644
index 00000000..a98a960f
--- /dev/null
+++ b/src/Model/Base/BuildMeta.php
@@ -0,0 +1,123 @@
+ null,
+ 'build_id' => null,
+ 'meta_key' => null,
+ 'meta_value' => null,
+ ];
+
+ /**
+ * @return integer
+ */
+ public function getId()
+ {
+ return (integer)$this->data['id'];
+ }
+
+ /**
+ * @param integer $value
+ */
+ public function setId($value)
+ {
+ $this->validateNotNull('id', $value);
+ $this->validateInt('id', $value);
+
+ if ($this->data['id'] === $value) {
+ return;
+ }
+
+ $this->data['id'] = $value;
+
+ $this->setModified('id');
+ }
+
+ /**
+ * @return integer
+ */
+ public function getBuildId()
+ {
+ return (integer)$this->data['build_id'];
+ }
+
+ /**
+ * @param integer $value
+ */
+ public function setBuildId($value)
+ {
+ $this->validateNotNull('build_id', $value);
+ $this->validateInt('build_id', $value);
+
+ if ($this->data['build_id'] === $value) {
+ return;
+ }
+
+ $this->data['build_id'] = $value;
+
+ $this->setModified('build_id');
+ }
+
+ /**
+ * @return string
+ */
+ public function getMetaKey()
+ {
+ return $this->data['meta_key'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setMetaKey($value)
+ {
+ $this->validateNotNull('meta_key', $value);
+ $this->validateString('meta_key', $value);
+
+ if ($this->data['meta_key'] === $value) {
+ return;
+ }
+
+ $this->data['meta_key'] = $value;
+
+ $this->setModified('meta_key');
+ }
+
+ /**
+ * @return string
+ */
+ public function getMetaValue()
+ {
+ return $this->data['meta_value'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setMetaValue($value)
+ {
+ $this->validateNotNull('meta_value', $value);
+ $this->validateString('meta_value', $value);
+
+ if ($this->data['meta_value'] === $value) {
+ return;
+ }
+
+ $this->data['meta_value'] = $value;
+
+ $this->setModified('meta_value');
+ }
+}
diff --git a/src/Model/Base/Environment.php b/src/Model/Base/Environment.php
new file mode 100644
index 00000000..10d17a09
--- /dev/null
+++ b/src/Model/Base/Environment.php
@@ -0,0 +1,128 @@
+ null,
+ 'project_id' => null,
+ 'name' => null,
+ 'branches' => null,
+ ];
+
+ /**
+ * @return integer
+ */
+ public function getId()
+ {
+ return (integer)$this->data['id'];
+ }
+
+ /**
+ * @param integer $value
+ */
+ public function setId($value)
+ {
+ $this->validateNotNull('id', $value);
+ $this->validateInt('id', $value);
+
+ if ($this->data['id'] === $value) {
+ return;
+ }
+
+ $this->data['id'] = $value;
+
+ $this->setModified('id');
+ }
+
+ /**
+ * @return integer
+ */
+ public function getProjectId()
+ {
+ return (integer)$this->data['project_id'];
+ }
+
+ /**
+ * @param integer $value
+ */
+ public function setProjectId($value)
+ {
+ $this->validateNotNull('project_id', $value);
+ $this->validateInt('project_id', $value);
+
+ if ($this->data['project_id'] === $value) {
+ return;
+ }
+
+ $this->data['project_id'] = $value;
+
+ $this->setModified('project_id');
+ }
+
+ /**
+ * @return string
+ */
+ public function getName()
+ {
+ return $this->data['name'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setName($value)
+ {
+ $this->validateNotNull('name', $value);
+ $this->validateString('name', $value);
+
+ if ($this->data['name'] === $value) {
+ return;
+ }
+
+ $this->data['name'] = $value;
+
+ $this->setModified('name');
+ }
+
+ /**
+ * @return array
+ */
+ public function getBranches()
+ {
+ return array_filter(
+ array_map(
+ 'trim',
+ explode("\n", $this->data['branches'])
+ )
+ );
+ }
+
+ /**
+ * @param array $value
+ */
+ public function setBranches(array $value)
+ {
+ $this->validateNotNull('branches', $value);
+
+ $branches = implode("\n", $value);
+ if ($this->data['branches'] === $branches) {
+ return;
+ }
+
+ $this->data['branches'] = $branches;
+
+ $this->setModified('branches');
+ }
+}
diff --git a/src/Model/Base/Project.php b/src/Model/Base/Project.php
new file mode 100644
index 00000000..f47cbb22
--- /dev/null
+++ b/src/Model/Base/Project.php
@@ -0,0 +1,461 @@
+ null,
+ 'title' => null,
+ 'reference' => null,
+ 'branch' => null,
+ 'default_branch_only' => null,
+ 'ssh_private_key' => null,
+ 'ssh_public_key' => null,
+ 'type' => null,
+ 'access_information' => null,
+ 'last_commit' => null,
+ 'build_config' => null,
+ 'allow_public_status' => null,
+ 'archived' => null,
+ 'group_id' => null,
+ 'create_date' => null,
+ 'user_id' => 0,
+ ];
+
+ /**
+ * @return integer
+ */
+ public function getId()
+ {
+ return (integer)$this->data['id'];
+ }
+
+ /**
+ * @param integer $value
+ */
+ public function setId($value)
+ {
+ $this->validateNotNull('id', $value);
+ $this->validateInt('id', $value);
+
+ if ($this->data['id'] === $value) {
+ return;
+ }
+
+ $this->data['id'] = $value;
+
+ $this->setModified('id');
+ }
+
+ /**
+ * @return string
+ */
+ public function getTitle()
+ {
+ return $this->data['title'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setTitle($value)
+ {
+ $this->validateNotNull('title', $value);
+ $this->validateString('title', $value);
+
+ if ($this->data['title'] === $value) {
+ return;
+ }
+
+ $this->data['title'] = $value;
+
+ $this->setModified('title');
+ }
+
+ /**
+ * @return string
+ */
+ public function getReference()
+ {
+ return $this->data['reference'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setReference($value)
+ {
+ $this->validateNotNull('reference', $value);
+ $this->validateString('reference', $value);
+
+ if ($this->data['reference'] === $value) {
+ return;
+ }
+
+ $this->data['reference'] = $value;
+
+ $this->setModified('reference');
+ }
+
+ /**
+ * @return string
+ */
+ public function getBranch()
+ {
+ if (!$this->data['branch']) {
+ $projectType = $this->getType();
+ switch ($projectType) {
+ case 'hg':
+ $branch = 'default';
+ break;
+ case 'svn':
+ $branch = 'trunk';
+ break;
+ default:
+ $branch = 'master';
+ }
+
+ return $branch;
+ } else {
+ return $this->data['branch'];
+ }
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setBranch($value)
+ {
+ $this->validateNotNull('branch', $value);
+ $this->validateString('branch', $value);
+
+ if ($this->data['branch'] === $value) {
+ return;
+ }
+
+ $this->data['branch'] = $value;
+
+ $this->setModified('branch');
+ }
+
+ /**
+ * @return boolean
+ */
+ public function getDefaultBranchOnly()
+ {
+ return (boolean)$this->data['default_branch_only'];
+ }
+
+ /**
+ * @param boolean $value
+ */
+ public function setDefaultBranchOnly($value)
+ {
+ $this->validateNotNull('default_branch_only', $value);
+ $this->validateBoolean('default_branch_only', $value);
+
+ if ($this->data['default_branch_only'] === $value) {
+ return;
+ }
+
+ $this->data['default_branch_only'] = (integer)$value;
+
+ $this->setModified('default_branch_only');
+ }
+
+ /**
+ * @return string
+ */
+ public function getSshPrivateKey()
+ {
+ return $this->data['ssh_private_key'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setSshPrivateKey($value)
+ {
+ $this->validateString('ssh_private_key', $value);
+
+ if ($this->data['ssh_private_key'] === $value) {
+ return;
+ }
+
+ $this->data['ssh_private_key'] = $value;
+
+ $this->setModified('ssh_private_key');
+ }
+
+ /**
+ * @return string
+ */
+ public function getSshPublicKey()
+ {
+ return $this->data['ssh_public_key'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setSshPublicKey($value)
+ {
+ $this->validateString('ssh_public_key', $value);
+
+ if ($this->data['ssh_public_key'] === $value) {
+ return;
+ }
+
+ $this->data['ssh_public_key'] = $value;
+
+ $this->setModified('ssh_public_key');
+ }
+
+ /**
+ * @return string
+ */
+ public function getType()
+ {
+ return $this->data['type'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setType($value)
+ {
+ $this->validateNotNull('type', $value);
+ $this->validateString('type', $value);
+
+ if ($this->data['type'] === $value) {
+ return;
+ }
+
+ $this->data['type'] = $value;
+
+ $this->setModified('type');
+ }
+
+ /**
+ * @param string|null $key
+ *
+ * @return array|string|null
+ */
+ public function getAccessInformation($key = null)
+ {
+ $data = json_decode($this->data['access_information'], true);
+ $accessInformation = null;
+ if (is_null($key)) {
+ $accessInformation = $data;
+ } elseif (isset($data[$key])) {
+ $accessInformation = $data[$key];
+ }
+
+ return $accessInformation;
+ }
+
+ /**
+ * @param array $value
+ */
+ public function setAccessInformation(array $value)
+ {
+ $this->validateNotNull('branches', $value);
+
+ $accessInformation = json_encode($value);
+ if ($this->data['access_information'] === $accessInformation) {
+ return;
+ }
+
+ $this->data['access_information'] = $accessInformation;
+
+ $this->setModified('access_information');
+ }
+
+
+ /**
+ * @return string
+ */
+ public function getLastCommit()
+ {
+ return $this->data['last_commit'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setLastCommit($value)
+ {
+ $this->validateString('last_commit', $value);
+
+ if ($this->data['last_commit'] === $value) {
+ return;
+ }
+
+ $this->data['last_commit'] = $value;
+
+ $this->setModified('last_commit');
+ }
+
+ /**
+ * @return string
+ */
+ public function getBuildConfig()
+ {
+ return $this->data['build_config'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setBuildConfig($value)
+ {
+ $this->validateString('build_config', $value);
+
+ if ($this->data['build_config'] === $value) {
+ return;
+ }
+
+ $this->data['build_config'] = $value;
+
+ $this->setModified('build_config');
+ }
+
+ /**
+ * @return boolean
+ */
+ public function getAllowPublicStatus()
+ {
+ return (boolean)$this->data['allow_public_status'];
+ }
+
+ /**
+ * @param boolean $value
+ */
+ public function setAllowPublicStatus($value)
+ {
+ $this->validateNotNull('allow_public_status', $value);
+ $this->validateBoolean('allow_public_status', $value);
+
+ if ($this->data['allow_public_status'] === $value) {
+ return;
+ }
+
+ $this->data['allow_public_status'] = (integer)$value;
+
+ $this->setModified('allow_public_status');
+ }
+
+ /**
+ * @return boolean
+ */
+ public function getArchived()
+ {
+ return (boolean)$this->data['archived'];
+ }
+
+ /**
+ * @param boolean $value
+ */
+ public function setArchived($value)
+ {
+ $this->validateNotNull('archived', $value);
+ $this->validateBoolean('archived', $value);
+
+ if ($this->data['archived'] === $value) {
+ return;
+ }
+
+ $this->data['archived'] = (integer)$value;
+
+ $this->setModified('archived');
+ }
+
+ /**
+ * @return integer
+ */
+ public function getGroupId()
+ {
+ return (integer)$this->data['group_id'];
+ }
+
+ /**
+ * @param integer $value
+ */
+ public function setGroupId($value)
+ {
+ $this->validateNotNull('group_id', $value);
+ $this->validateInt('group_id', $value);
+
+ if ($this->data['group_id'] === $value) {
+ return;
+ }
+
+ $this->data['group_id'] = $value;
+
+ $this->setModified('group_id');
+ }
+
+ /**
+ * @return \DateTime|null
+ */
+ public function getCreateDate()
+ {
+ if ($this->data['create_date']) {
+ return new \DateTime($this->data['create_date']);
+ }
+
+ return null;
+ }
+
+ /**
+ * @param \DateTime $value
+ */
+ public function setCreateDate(\DateTime $value)
+ {
+ $stringValue = $value->format('Y-m-d H:i:s');
+
+ if ($this->data['create_date'] === $stringValue) {
+ return;
+ }
+
+ $this->data['create_date'] = $stringValue;
+
+ $this->setModified('create_date');
+ }
+
+ /**
+ * @return integer
+ */
+ public function getUserId()
+ {
+ return (integer)$this->data['user_id'];
+ }
+
+ /**
+ * @param integer $value
+ */
+ public function setUserId($value)
+ {
+ $this->validateNotNull('user_id', $value);
+ $this->validateInt('user_id', $value);
+
+ if ($this->data['user_id'] === $value) {
+ return;
+ }
+
+ $this->data['user_id'] = $value;
+
+ $this->setModified('user_id');
+ }
+}
diff --git a/src/Model/Base/ProjectGroup.php b/src/Model/Base/ProjectGroup.php
new file mode 100644
index 00000000..0d61884f
--- /dev/null
+++ b/src/Model/Base/ProjectGroup.php
@@ -0,0 +1,126 @@
+ null,
+ 'title' => null,
+ 'create_date' => null,
+ 'user_id' => 0,
+ ];
+
+ /**
+ * @return integer
+ */
+ public function getId()
+ {
+ return (integer)$this->data['id'];
+ }
+
+ /**
+ * @param integer $value
+ */
+ public function setId($value)
+ {
+ $this->validateNotNull('id', $value);
+ $this->validateInt('id', $value);
+
+ if ($this->data['id'] === $value) {
+ return;
+ }
+
+ $this->data['id'] = $value;
+
+ $this->setModified('id');
+ }
+
+ /**
+ * @return string
+ */
+ public function getTitle()
+ {
+ return $this->data['title'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setTitle($value)
+ {
+ $this->validateNotNull('title', $value);
+ $this->validateString('title', $value);
+
+ if ($this->data['title'] === $value) {
+ return;
+ }
+
+ $this->data['title'] = $value;
+
+ $this->setModified('title');
+ }
+
+ /**
+ * @return \DateTime|null
+ */
+ public function getCreateDate()
+ {
+ if ($this->data['create_date']) {
+ return new \DateTime($this->data['create_date']);
+ }
+
+ return null;
+ }
+
+ /**
+ * @param \DateTime $value
+ */
+ public function setCreateDate(\DateTime $value)
+ {
+ $stringValue = $value->format('Y-m-d H:i:s');
+
+ if ($this->data['create_date'] === $stringValue) {
+ return;
+ }
+
+ $this->data['create_date'] = $stringValue;
+
+ $this->setModified('create_date');
+ }
+
+ /**
+ * @return string
+ */
+ public function getUserId()
+ {
+ return (integer)$this->data['user_id'];
+ }
+
+ /**
+ * @param integer $value
+ */
+ public function setUserId($value)
+ {
+ $this->validateNotNull('user_id', $value);
+ $this->validateInt('user_id', $value);
+
+ if ($this->data['user_id'] === $value) {
+ return;
+ }
+
+ $this->data['user_id'] = $value;
+
+ $this->setModified('user_id');
+ }
+}
diff --git a/src/Model/Base/User.php b/src/Model/Base/User.php
new file mode 100644
index 00000000..01c82c1e
--- /dev/null
+++ b/src/Model/Base/User.php
@@ -0,0 +1,284 @@
+ null,
+ 'email' => null,
+ 'hash' => null,
+ 'is_admin' => null,
+ 'name' => null,
+ 'language' => null,
+ 'per_page' => null,
+ 'provider_key' => null,
+ 'provider_data' => null,
+ 'remember_key' => null,
+ ];
+
+ /**
+ * @return integer
+ */
+ public function getId()
+ {
+ return (integer)$this->data['id'];
+ }
+
+ /**
+ * @param integer $value
+ */
+ public function setId($value)
+ {
+ $this->validateNotNull('id', $value);
+ $this->validateInt('id', $value);
+
+ if ($this->data['id'] === $value) {
+ return;
+ }
+
+ $this->data['id'] = $value;
+
+ $this->setModified('id');
+ }
+
+ /**
+ * @return string
+ */
+ public function getEmail()
+ {
+ return $this->data['email'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setEmail($value)
+ {
+ $this->validateNotNull('email', $value);
+ $this->validateString('email', $value);
+
+ if ($this->data['email'] === $value) {
+ return;
+ }
+
+ $this->data['email'] = $value;
+
+ $this->setModified('email');
+ }
+
+ /**
+ * @return string
+ */
+ public function getHash()
+ {
+ return $this->data['hash'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setHash($value)
+ {
+ $this->validateNotNull('hash', $value);
+ $this->validateString('hash', $value);
+
+ if ($this->data['hash'] === $value) {
+ return;
+ }
+
+ $this->data['hash'] = $value;
+
+ $this->setModified('hash');
+ }
+
+ /**
+ * @return boolean
+ */
+ public function getIsAdmin()
+ {
+ return (boolean)$this->data['is_admin'];
+ }
+
+ /**
+ * @param boolean $value
+ */
+ public function setIsAdmin($value)
+ {
+ $this->validateNotNull('is_admin', $value);
+ $this->validateBoolean('is_admin', $value);
+
+ if ($this->data['is_admin'] === $value) {
+ return;
+ }
+
+ $this->data['is_admin'] = (integer)$value;
+
+ $this->setModified('is_admin');
+ }
+
+ /**
+ * @return string
+ */
+ public function getName()
+ {
+ return $this->data['name'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setName($value)
+ {
+ $this->validateNotNull('name', $value);
+ $this->validateString('name', $value);
+
+ if ($this->data['name'] === $value) {
+ return;
+ }
+
+ $this->data['name'] = $value;
+
+ $this->setModified('name');
+ }
+
+ /**
+ * @return string
+ */
+ public function getLanguage()
+ {
+ return $this->data['language'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setLanguage($value)
+ {
+ if ($this->data['language'] === $value) {
+ return;
+ }
+
+ $this->data['language'] = $value;
+
+ $this->setModified('language');
+ }
+
+ /**
+ * @return integer
+ */
+ public function getPerPage()
+ {
+ return (integer)$this->data['per_page'];
+ }
+
+ /**
+ * @param integer $value
+ */
+ public function setPerPage($value)
+ {
+ $this->validateInt('per_page', $value);
+
+ if ($this->data['per_page'] === $value) {
+ return;
+ }
+
+ $this->data['per_page'] = $value;
+
+ $this->setModified('per_page');
+ }
+
+ /**
+ * @return string
+ */
+ public function getProviderKey()
+ {
+ return $this->data['provider_key'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setProviderKey($value)
+ {
+ $this->validateNotNull('provider_key', $value);
+ $this->validateString('provider_key', $value);
+
+ if ($this->data['provider_key'] === $value) {
+ return;
+ }
+
+ $this->data['provider_key'] = $value;
+
+ $this->setModified('provider_key');
+ }
+
+ /**
+ * @param string|null $key
+ *
+ * @return array|string|null
+ */
+ public function getProviderData($key = null)
+ {
+ $data = json_decode($this->data['provider_data'], true);
+ $providerData = null;
+ if (is_null($key)) {
+ $providerData = $data;
+ } elseif (isset($data[$key])) {
+ $providerData = $data[$key];
+ }
+
+ return $providerData;
+ }
+
+ /**
+ * @param array $value
+ */
+ public function setProviderData(array $value)
+ {
+ $this->validateNotNull('provider_data', $value);
+
+ $providerData = json_encode($value);
+ if ($this->data['provider_data'] === $providerData) {
+ return;
+ }
+
+ $this->data['provider_data'] = $providerData;
+
+ $this->setModified('provider_data');
+ }
+
+ /**
+ * @return string
+ */
+ public function getRememberKey()
+ {
+ return $this->data['remember_key'];
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setRememberKey($value)
+ {
+ $this->validateString('remember_key', $value);
+
+ if ($this->data['remember_key'] === $value) {
+ return;
+ }
+
+ $this->data['remember_key'] = $value;
+
+ $this->setModified('remember_key');
+ }
+}
diff --git a/src/Model/Build.php b/src/Model/Build.php
index fb2b1b66..207c4611 100644
--- a/src/Model/Build.php
+++ b/src/Model/Build.php
@@ -3,16 +3,17 @@
namespace PHPCensor\Model;
use PHPCensor\Builder;
+use PHPCensor\Store\Factory;
+use PHPCensor\Store\ProjectStore;
use PHPCensor\Store\BuildErrorStore;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Yaml\Parser as YamlParser;
-use PHPCensor\Model;
-use PHPCensor\Store\Factory;
+use PHPCensor\Model\Base\Build as BaseBuild;
/**
* @author Dan Cryer
*/
-class Build extends Model
+class Build extends BaseBuild
{
const STAGE_SETUP = 'setup';
const STAGE_TEST = 'test';
@@ -23,23 +24,6 @@ class Build extends Model
const STAGE_FIXED = 'fixed';
const STAGE_BROKEN = 'broken';
- const STATUS_PENDING = 0;
- const STATUS_RUNNING = 1;
- const STATUS_SUCCESS = 2;
- const STATUS_FAILED = 3;
-
- const SOURCE_UNKNOWN = 0;
- const SOURCE_MANUAL_WEB = 1;
- const SOURCE_MANUAL_CONSOLE = 2;
- const SOURCE_PERIODICAL = 3;
- const SOURCE_WEBHOOK = 4;
- const SOURCE_WEBHOOK_PULL_REQUEST = 5;
-
- /**
- * @var string
- */
- protected $tableName = 'build';
-
/**
* @var integer
*/
@@ -56,482 +40,33 @@ class Build extends Model
protected $buildBranchDirectory;
/**
- * @var array
+ * @return Project|null
*/
- protected $data = [
- 'id' => null,
- 'project_id' => null,
- 'commit_id' => null,
- 'status' => null,
- 'log' => null,
- 'branch' => null,
- 'tag' => null,
- 'create_date' => null,
- 'start_date' => null,
- 'finish_date' => null,
- 'committer_email' => null,
- 'commit_message' => null,
- 'extra' => null,
- 'environment' => null,
- 'source' => Build::SOURCE_UNKNOWN,
- 'user_id' => 0,
- ];
-
- /**
- * @var array
- */
- protected $getters = [
- // Direct property getters:
- 'id' => 'getId',
- 'project_id' => 'getProjectId',
- 'commit_id' => 'getCommitId',
- 'status' => 'getStatus',
- 'log' => 'getLog',
- 'branch' => 'getBranch',
- 'tag' => 'getTag',
- 'create_date' => 'getCreateDate',
- 'start_date' => 'getStartDate',
- 'finish_date' => 'getFinishDate',
- 'committer_email' => 'getCommitterEmail',
- 'commit_message' => 'getCommitMessage',
- 'extra' => 'getExtra',
- 'environment' => 'getEnvironment',
- 'source' => 'getSource',
- 'user_id' => 'getUserId',
-
- // Foreign key getters:
- 'Project' => 'getProject',
- ];
-
- /**
- * @var array
- */
- protected $setters = [
- // Direct property setters:
- 'id' => 'setId',
- 'project_id' => 'setProjectId',
- 'commit_id' => 'setCommitId',
- 'status' => 'setStatus',
- 'log' => 'setLog',
- 'branch' => 'setBranch',
- 'setTag' => 'setTag',
- 'create_date' => 'setCreateDate',
- 'start_date' => 'setStartDate',
- 'finish_date' => 'setFinishDate',
- 'committer_email' => 'setCommitterEmail',
- 'commit_message' => 'setCommitMessage',
- 'extra' => 'setExtra',
- 'environment' => 'setEnvironment',
- 'source' => 'setSource',
- 'user_id' => 'setUserId',
- ];
-
- /**
- * @return integer
- */
- public function getId()
+ public function getProject()
{
- $rtn = $this->data['id'];
-
- return (integer)$rtn;
- }
-
- /**
- * @param integer $value
- */
- public function setId($value)
- {
- $this->validateNotNull('id', $value);
- $this->validateInt('id', $value);
-
- if ($this->data['id'] === $value) {
- return;
+ $projectId = $this->getProjectId();
+ if (!$projectId) {
+ return null;
}
- $this->data['id'] = $value;
+ /** @var ProjectStore $projectStore */
+ $projectStore = Factory::getStore('Project');
- $this->setModified('id');
+ return $projectStore->getById($projectId);
}
/**
- * @return integer
+ * @param string $name
+ * @param mixed $value
*/
- public function getProjectId()
+ public function addExtraValue($name, $value)
{
- $rtn = $this->data['project_id'];
-
- return (integer)$rtn;
- }
-
- /**
- * @param integer $value
- */
- public function setProjectId($value)
- {
- $this->validateNotNull('project_id', $value);
- $this->validateInt('project_id', $value);
-
- if ($this->data['project_id'] === $value) {
- return;
+ $extra = json_decode($this->data['extra'], true);
+ if ($extra === false) {
+ $extra = [];
}
-
- $this->data['project_id'] = $value;
-
- $this->setModified('project_id');
- }
-
- /**
- * @return string
- */
- public function getCommitId()
- {
- $rtn = $this->data['commit_id'];
-
- return $rtn;
- }
-
- /**
- * @param string $value
- */
- public function setCommitId($value)
- {
- $this->validateNotNull('commit_id', $value);
- $this->validateString('commit_id', $value);
-
- if ($this->data['commit_id'] === $value) {
- return;
- }
-
- $this->data['commit_id'] = $value;
-
- $this->setModified('commit_id');
- }
-
- /**
- * @return integer
- */
- public function getStatus()
- {
- $rtn = $this->data['status'];
-
- return (integer)$rtn;
- }
-
- /**
- * @param integer $value
- */
- public function setStatus($value)
- {
- $this->validateNotNull('status', $value);
- $this->validateInt('status', $value);
-
- if ($this->data['status'] === $value) {
- return;
- }
-
- $this->data['status'] = $value;
-
- $this->setModified('status');
- }
-
- /**
- * @return string
- */
- public function getLog()
- {
- $rtn = $this->data['log'];
-
- return $rtn;
- }
-
- /**
- * @param string $value
- */
- public function setLog($value)
- {
- $this->validateString('log', $value);
-
- if ($this->data['log'] === $value) {
- return;
- }
-
- $this->data['log'] = $value;
-
- $this->setModified('log');
- }
-
- /**
- * @return string
- */
- public function getBranch()
- {
- $rtn = $this->data['branch'];
-
- return $rtn;
- }
-
- /**
- * @param string $value
- */
- public function setBranch($value)
- {
- $this->validateNotNull('branch', $value);
- $this->validateString('branch', $value);
-
- if ($this->data['branch'] === $value) {
- return;
- }
-
- $this->data['branch'] = $value;
-
- $this->setModified('branch');
- }
-
- /**
- * @return \DateTime
- */
- public function getCreateDate()
- {
- $rtn = $this->data['create_date'];
-
- if (!empty($rtn)) {
- $rtn = new \DateTime($rtn);
- }
-
- return $rtn;
- }
-
- /**
- * @param \DateTime $value
- */
- public function setCreateDate(\DateTime $value)
- {
- $stringValue = $value->format('Y-m-d H:i:s');
-
- if ($this->data['create_date'] === $stringValue) {
- return;
- }
-
- $this->data['create_date'] = $stringValue;
-
- $this->setModified('create_date');
- }
-
- /**
- * @return \DateTime
- */
- public function getStartDate()
- {
- $rtn = $this->data['start_date'];
-
- if (!empty($rtn)) {
- $rtn = new \DateTime($rtn);
- }
-
- return $rtn;
- }
-
- /**
- * @param \DateTime $value
- */
- public function setStartDate(\DateTime $value)
- {
- $stringValue = $value->format('Y-m-d H:i:s');
-
- if ($this->data['start_date'] === $stringValue) {
- return;
- }
-
- $this->data['start_date'] = $stringValue;
-
- $this->setModified('start_date');
- }
-
- /**
- * @return \DateTime
- */
- public function getFinishDate()
- {
- $rtn = $this->data['finish_date'];
-
- if (!empty($rtn)) {
- $rtn = new \DateTime($rtn);
- }
-
- return $rtn;
- }
-
- /**
- * @param \DateTime $value
- */
- public function setFinishDate(\DateTime $value)
- {
- $stringValue = $value->format('Y-m-d H:i:s');
-
- if ($this->data['finish_date'] === $stringValue) {
- return;
- }
-
- $this->data['finish_date'] = $stringValue;
-
- $this->setModified('finish_date');
- }
-
- /**
- * @return string
- */
- public function getCommitterEmail()
- {
- $rtn = $this->data['committer_email'];
-
- return $rtn;
- }
-
- /**
- * @param string $value
- */
- public function setCommitterEmail($value)
- {
- $this->validateString('committer_email', $value);
-
- if ($this->data['committer_email'] === $value) {
- return;
- }
-
- $this->data['committer_email'] = $value;
-
- $this->setModified('committer_email');
- }
-
- /**
- * @return string
- */
- public function getCommitMessage()
- {
- $rtn = htmlspecialchars($this->data['commit_message']);
-
- return $rtn;
- }
-
- /**
- * @param string $value
- */
- public function setCommitMessage($value)
- {
- $this->validateString('commit_message', $value);
-
- if ($this->data['commit_message'] === $value) {
- return;
- }
-
- $this->data['commit_message'] = $value;
-
- $this->setModified('commit_message');
- }
-
- /**
- * @return string
- */
- public function getTag()
- {
- $rtn = $this->data['tag'];
-
- return $rtn;
- }
-
- /**
- * @param string $value
- */
- public function setTag($value)
- {
- $this->validateString('tag', $value);
-
- if ($this->data['tag'] === $value) {
- return;
- }
-
- $this->data['tag'] = $value;
-
- $this->setModified('tag');
- }
-
- /**
- * @return string
- */
- public function getSource()
- {
- $rtn = $this->data['source'];
-
- return (integer)$rtn;
- }
-
- /**
- * @param integer $value
- */
- public function setSource($value)
- {
- $this->validateInt('source', $value);
-
- if ($this->data['source'] === $value) {
- return;
- }
-
- $this->data['source'] = $value;
-
- $this->setModified('source');
- }
-
- /**
- * @return string
- */
- public function getUserId()
- {
- $rtn = $this->data['user_id'];
-
- return (integer)$rtn;
- }
-
- /**
- * @param integer $value
- */
- public function setUserId($value)
- {
- $this->validateNotNull('user_id', $value);
- $this->validateInt('user_id', $value);
-
- if ($this->data['user_id'] === $value) {
- return;
- }
-
- $this->data['user_id'] = $value;
-
- $this->setModified('user_id');
- }
-
- /**
- * @return string
- */
- public function getEnvironment()
- {
- $rtn = $this->data['environment'];
-
- return $rtn;
- }
-
- /**
- * @param string $value
- */
- public function setEnvironment($value)
- {
- $this->validateString('environment', $value);
-
- if ($this->data['environment'] === $value) {
- return;
- }
-
- $this->data['environment'] = $value;
-
- $this->setModified('environment');
+ $extra[$name] = $value;
+ $this->setExtra($extra);
}
/**
@@ -556,91 +91,6 @@ class Build extends Model
return false;
}
- /**
- * Return a value from the build's "extra" JSON array.
- *
- * @param string|null $key
- *
- * @return array|string|null
- */
- public function getExtra($key = null)
- {
- $data = json_decode($this->data['extra'], true);
-
- if (is_null($key)) {
- $rtn = $data;
- } elseif (isset($data[$key])) {
- $rtn = $data[$key];
- } else {
- $rtn = null;
- }
-
- return $rtn;
- }
-
- /**
- * @param string $value
- */
- public function setExtra($value)
- {
- $this->validateString('extra', $value);
-
- if ($this->data['extra'] === $value) {
- return;
- }
-
- $this->data['extra'] = $value;
-
- $this->setModified('extra');
- }
-
- /**
- * Set the value of extra.
- *
- * @param string $name
- * @param mixed $value
- */
- public function setExtraValue($name, $value)
- {
- $extra = json_decode($this->data['extra'], true);
- if ($extra === false) {
- $extra = [];
- }
- $extra[$name] = $value;
- $this->setExtra(json_encode($extra));
- }
-
- /**
- * Set the values of extra.
- *
- * @param mixed $values
- */
- public function setExtraValues($values)
- {
- $extra = json_decode($this->data['extra'], true);
- if ($extra === false) {
- $extra = [];
- }
- $extra = array_replace($extra, $values);
- $this->setExtra(json_encode($extra));
- }
-
- /**
- * Get the Project model for this Build by Id.
- *
- * @return \PHPCensor\Model\Project
- */
- public function getProject()
- {
- $key = $this->getProjectId();
-
- if (empty($key)) {
- return null;
- }
-
- return Factory::getStore('Project')->getById($key);
- }
-
/**
* Get BuildError models by BuildId for this Build.
*
diff --git a/src/Model/BuildError.php b/src/Model/BuildError.php
index a4492b79..f7a6f29f 100644
--- a/src/Model/BuildError.php
+++ b/src/Model/BuildError.php
@@ -2,10 +2,11 @@
namespace PHPCensor\Model;
-use PHPCensor\Model;
+use PHPCensor\Model\Base\BuildError as BaseBuildError;
+use PHPCensor\Store\BuildStore;
use PHPCensor\Store\Factory;
-class BuildError extends Model
+class BuildError extends BaseBuildError
{
const SEVERITY_CRITICAL = 0;
const SEVERITY_HIGH = 1;
@@ -13,369 +14,7 @@ class BuildError extends Model
const SEVERITY_LOW = 3;
/**
- * @var string
- */
- protected $tableName = 'build_error';
-
- /**
- * @var array
- */
- protected $data = [
- 'id' => null,
- 'build_id' => null,
- 'plugin' => null,
- 'file' => null,
- 'line_start' => null,
- 'line_end' => null,
- 'severity' => null,
- 'message' => null,
- 'create_date' => null,
- 'hash' => null,
- 'is_new' => null,
- ];
-
- /**
- * @var array
- */
- protected $getters = [
- // Direct property getters:
- 'id' => 'getId',
- 'build_id' => 'getBuildId',
- 'plugin' => 'getPlugin',
- 'file' => 'getFile',
- 'line_start' => 'getLineStart',
- 'line_end' => 'getLineEnd',
- 'severity' => 'getSeverity',
- 'message' => 'getMessage',
- 'create_date' => 'getCreateDate',
- 'hash' => 'getHash',
- 'is_new' => 'getIsNew',
-
- // Foreign key getters:
- 'Build' => 'getBuild',
- ];
-
- /**
- * @var array
- */
- protected $setters = [
- // Direct property setters:
- 'id' => 'setId',
- 'build_id' => 'setBuildId',
- 'plugin' => 'setPlugin',
- 'file' => 'setFile',
- 'line_start' => 'setLineStart',
- 'line_end' => 'setLineEnd',
- 'severity' => 'setSeverity',
- 'message' => 'setMessage',
- 'create_date' => 'setCreateDate',
- 'hash' => 'setHash',
- 'is_new' => 'setIsNew',
- ];
-
- /**
- * @return integer
- */
- public function getId()
- {
- $rtn = $this->data['id'];
-
- return $rtn;
- }
-
- /**
- * @return integer
- */
- public function getBuildId()
- {
- $rtn = $this->data['build_id'];
-
- return $rtn;
- }
-
- /**
- * @return string
- */
- public function getPlugin()
- {
- $rtn = $this->data['plugin'];
-
- return $rtn;
- }
-
- /**
- * @return string
- */
- public function getFile()
- {
- $rtn = $this->data['file'];
-
- return $rtn;
- }
-
- /**
- * @return integer
- */
- public function getLineStart()
- {
- $rtn = $this->data['line_start'];
-
- return $rtn;
- }
-
- /**
- * @return integer
- */
- public function getLineEnd()
- {
- $rtn = $this->data['line_end'];
-
- return $rtn;
- }
-
- /**
- * @return integer
- */
- public function getSeverity()
- {
- $rtn = $this->data['severity'];
-
- return $rtn;
- }
-
- /**
- * @return string
- */
- public function getMessage()
- {
- $rtn = $this->data['message'];
-
- return $rtn;
- }
-
- /**
- * @return \DateTime
- */
- public function getCreateDate()
- {
- $rtn = $this->data['create_date'];
-
- if (!empty($rtn)) {
- $rtn = new \DateTime($rtn);
- }
-
- return $rtn;
- }
-
- /**
- * @return string
- */
- public function getHash()
- {
- $rtn = (string)$this->data['hash'];
-
- return $rtn;
- }
-
- /**
- * @return string
- */
- public function getIsNew()
- {
- $rtn = $this->data['is_new'];
-
- return $rtn;
- }
-
- /**
- * @param integer $value
- */
- public function setId($value)
- {
- $this->validateNotNull('id', $value);
- $this->validateInt('id', $value);
-
- if ($this->data['id'] === $value) {
- return;
- }
-
- $this->data['id'] = $value;
-
- $this->setModified('id');
- }
-
- /**
- * @param integer $value
- */
- public function setBuildId($value)
- {
- $this->validateNotNull('build_id', $value);
- $this->validateInt('build_id', $value);
-
- if ($this->data['build_id'] === $value) {
- return;
- }
-
- $this->data['build_id'] = $value;
-
- $this->setModified('build_id');
- }
-
- /**
- * @param string $value
- */
- public function setPlugin($value)
- {
- $this->validateNotNull('plugin', $value);
- $this->validateString('plugin', $value);
-
- if ($this->data['plugin'] === $value) {
- return;
- }
-
- $this->data['plugin'] = $value;
-
- $this->setModified('plugin');
- }
-
- /**
- * @param string $value
- */
- public function setFile($value)
- {
- $this->validateString('file', $value);
-
- if ($this->data['file'] === $value) {
- return;
- }
-
- $this->data['file'] = $value;
-
- $this->setModified('file');
- }
-
- /**
- * @param integer $value
- */
- public function setLineStart($value)
- {
- $this->validateInt('line_start', $value);
-
- if ($this->data['line_start'] === $value) {
- return;
- }
-
- $this->data['line_start'] = $value;
-
- $this->setModified('line_start');
- }
-
- /**
- * @param integer $value
- */
- public function setLineEnd($value)
- {
- $this->validateInt('line_end', $value);
-
- if ($this->data['line_end'] === $value) {
- return;
- }
-
- $this->data['line_end'] = $value;
-
- $this->setModified('line_end');
- }
-
- /**
- * @param integer $value
- */
- public function setSeverity($value)
- {
- $this->validateNotNull('severity', $value);
- $this->validateInt('severity', $value);
-
- if ($this->data['severity'] === $value) {
- return;
- }
-
- $this->data['severity'] = $value;
-
- $this->setModified('severity');
- }
-
- /**
- * @param string $value
- */
- public function setMessage($value)
- {
- $this->validateNotNull('message', $value);
- $this->validateString('message', $value);
-
- if ($this->data['message'] === $value) {
- return;
- }
-
- $this->data['message'] = $value;
-
- $this->setModified('message');
- }
-
- /**
- * @param \DateTime $value
- */
- public function setCreateDate(\DateTime $value)
- {
- $this->validateNotNull('create_date', $value);
-
- $stringValue = $value->format('Y-m-d H:i:s');
-
- if ($this->data['create_date'] === $stringValue) {
- return;
- }
-
- $this->data['create_date'] = $stringValue;
-
- $this->setModified('create_date');
- }
-
- /**
- * @param string $value
- */
- public function setHash($value)
- {
- $this->validateNotNull('hash', $value);
- $this->validateString('hash', $value);
-
- if ($this->data['hash'] === $value) {
- return;
- }
-
- $this->data['hash'] = $value;
-
- $this->setModified('hash');
- }
-
- /**
- * @param integer $value
- */
- public function setIsNew($value)
- {
- $this->validateNotNull('is_new', $value);
- $this->validateInt('is_new', $value);
-
- if ($this->data['is_new'] === $value) {
- return;
- }
-
- $this->data['is_new'] = $value;
-
- $this->setModified('is_new');
- }
-
- /**
- * Get the Build model for this BuildError by Id.
- *
- * @return \PHPCensor\Model\Build|null
+ * @return Build|null
*/
public function getBuild()
{
@@ -384,7 +23,10 @@ class BuildError extends Model
return null;
}
- return Factory::getStore('Build')->getById($buildId);
+ /** @var BuildStore $buildStore */
+ $buildStore = Factory::getStore('Build');
+
+ return $buildStore->getById($buildId);
}
/**
diff --git a/src/Model/BuildMeta.php b/src/Model/BuildMeta.php
index 68c2fb79..b6e09dd7 100644
--- a/src/Model/BuildMeta.php
+++ b/src/Model/BuildMeta.php
@@ -2,163 +2,14 @@
namespace PHPCensor\Model;
-use PHPCensor\Model;
+use PHPCensor\Model\Base\BuildMeta as BaseBuildMeta;
+use PHPCensor\Store\BuildStore;
use PHPCensor\Store\Factory;
-class BuildMeta extends Model
+class BuildMeta extends BaseBuildMeta
{
/**
- * @var string
- */
- protected $tableName = 'build_meta';
-
- /**
- * @var array
- */
- protected $data = [
- 'id' => null,
- 'build_id' => null,
- 'meta_key' => null,
- 'meta_value' => null,
- ];
-
- /**
- * @var array
- */
- protected $getters = [
- // Direct property getters:
- 'id' => 'getId',
- 'build_id' => 'getBuildId',
- 'meta_key' => 'getMetaKey',
- 'meta_value' => 'getMetaValue',
-
- // Foreign key getters:
- 'Build' => 'getBuild',
- ];
-
- /**
- * @var array
- */
- protected $setters = [
- // Direct property setters:
- 'id' => 'setId',
- 'build_id' => 'setBuildId',
- 'meta_key' => 'setMetaKey',
- 'meta_value' => 'setMetaValue',
- ];
-
- /**
- * @return integer
- */
- public function getId()
- {
- $rtn = $this->data['id'];
-
- return $rtn;
- }
-
- /**
- * @return integer
- */
- public function getBuildId()
- {
- $rtn = $this->data['build_id'];
-
- return $rtn;
- }
-
- /**
- * @return string
- */
- public function getMetaKey()
- {
- $rtn = $this->data['meta_key'];
-
- return $rtn;
- }
-
- /**
- * @return string
- */
- public function getMetaValue()
- {
- $rtn = $this->data['meta_value'];
-
- return $rtn;
- }
-
- /**
- * @param integer $value
- */
- public function setId($value)
- {
- $this->validateNotNull('id', $value);
- $this->validateInt('id', $value);
-
- if ($this->data['id'] === $value) {
- return;
- }
-
- $this->data['id'] = $value;
-
- $this->setModified('id');
- }
-
- /**
- * @param integer $value
- */
- public function setBuildId($value)
- {
- $this->validateNotNull('build_id', $value);
- $this->validateInt('build_id', $value);
-
- if ($this->data['build_id'] === $value) {
- return;
- }
-
- $this->data['build_id'] = $value;
-
- $this->setModified('build_id');
- }
-
- /**
- * @param string $value
- */
- public function setMetaKey($value)
- {
- $this->validateNotNull('meta_key', $value);
- $this->validateString('meta_key', $value);
-
- if ($this->data['meta_key'] === $value) {
- return;
- }
-
- $this->data['meta_key'] = $value;
-
- $this->setModified('meta_key');
- }
-
- /**
- * @param string $value
- */
- public function setMetaValue($value)
- {
- $this->validateNotNull('meta_value', $value);
- $this->validateString('meta_value', $value);
-
- if ($this->data['meta_value'] === $value) {
- return;
- }
-
- $this->data['meta_value'] = $value;
-
- $this->setModified('meta_value');
- }
-
- /**
- * Get the Build model for this BuildMeta by Id.
- *
- * @return \PHPCensor\Model\Build
+ * @return Build|null
*/
public function getBuild()
{
@@ -167,6 +18,9 @@ class BuildMeta extends Model
return null;
}
- return Factory::getStore('Build')->getById($buildId);
+ /** @var BuildStore $buildStore */
+ $buildStore = Factory::getStore('Build');
+
+ return $buildStore->getById($buildId);
}
}
diff --git a/src/Model/Environment.php b/src/Model/Environment.php
index ade80d6e..acac8908 100644
--- a/src/Model/Environment.php
+++ b/src/Model/Environment.php
@@ -2,150 +2,8 @@
namespace PHPCensor\Model;
-use PHPCensor\Model;
+use PHPCensor\Model\Base\Environment as BaseEnvironment;
-class Environment extends Model
+class Environment extends BaseEnvironment
{
- /**
- * @var string
- */
- protected $tableName = 'environment';
-
- /**
- * @var array
- */
- protected $data = [
- 'id' => null,
- 'project_id' => null,
- 'name' => null,
- 'branches' => null,
- ];
-
- /**
- * @var array
- */
- protected $getters = [
- 'id' => 'getId',
- 'project_id' => 'getProjectId',
- 'name' => 'getName',
- 'branches' => 'getBranches',
- ];
-
- /**
- * @var array
- */
- protected $setters = [
- 'id' => 'setId',
- 'project_id' => 'setProjectId',
- 'name' => 'setName',
- 'branches' => 'setBranches',
- ];
-
- /**
- * @return integer
- */
- public function getId()
- {
- $rtn = $this->data['id'];
-
- return $rtn;
- }
-
- /**
- * @return integer
- */
- public function getProjectId()
- {
- $rtn = $this->data['project_id'];
-
- return $rtn;
- }
-
- /**
- * @return string
- */
- public function getName()
- {
- $rtn = $this->data['name'];
-
- return $rtn;
- }
-
- /**
- * @return array
- */
- public function getBranches()
- {
- $rtn = array_filter(array_map('trim', explode("\n", $this->data['branches'])));
-
- return $rtn;
- }
-
- /**
- * @param integer $value
- */
- public function setId($value)
- {
- $this->validateNotNull('id', $value);
- $this->validateInt('id', $value);
-
- if ($this->data['id'] === $value) {
- return;
- }
-
- $this->data['id'] = $value;
-
- $this->setModified('id');
- }
-
- /**
- * @param integer $value
- */
- public function setProjectId($value)
- {
- $this->validateNotNull('project_id', $value);
- $this->validateInt('project_id', $value);
-
- if ($this->data['project_id'] === $value) {
- return;
- }
-
- $this->data['project_id'] = $value;
-
- $this->setModified('project_id');
- }
-
- /**
- * @param string $value
- */
- public function setName($value)
- {
- $this->validateNotNull('name', $value);
- $this->validateString('name', $value);
-
- if ($this->data['name'] === $value) {
- return;
- }
-
- $this->data['name'] = $value;
-
- $this->setModified('name');
- }
-
- /**
- * @param array $value
- */
- public function setBranches($value)
- {
- $this->validateNotNull('branches', $value);
- $value = implode("\n", $value);
-
- if ($this->data['branches'] === $value) {
- return;
- }
-
- $this->data['branches'] = $value;
-
- $this->setModified('branches');
- }
}
diff --git a/src/Model/Project.php b/src/Model/Project.php
index e6ccfacb..e81d29fa 100644
--- a/src/Model/Project.php
+++ b/src/Model/Project.php
@@ -2,447 +2,32 @@
namespace PHPCensor\Model;
-use PHPCensor\Model;
use PHPCensor\Store\Factory;
use PHPCensor\Store\EnvironmentStore;
+use PHPCensor\Store\ProjectGroupStore;
use Symfony\Component\Yaml\Parser as YamlParser;
use Symfony\Component\Yaml\Dumper as YamlDumper;
+use PHPCensor\Model\Base\Project as BaseProject;
/**
* @author Dan Cryer
*/
-class Project extends Model
+class Project extends BaseProject
{
/**
- * @var string
- */
- protected $tableName = 'project';
-
- /**
- * @var array
- */
- protected $data = [
- 'id' => null,
- 'title' => null,
- 'reference' => null,
- 'branch' => null,
- 'default_branch_only' => null,
- 'ssh_private_key' => null,
- 'type' => null,
- 'access_information' => null,
- 'last_commit' => null,
- 'build_config' => null,
- 'ssh_public_key' => null,
- 'allow_public_status' => null,
- 'archived' => null,
- 'group_id' => null,
- 'create_date' => null,
- 'user_id' => 0,
- ];
-
- /**
- * @var array
- */
- protected $getters = [
- // Direct property getters:
- 'id' => 'getId',
- 'title' => 'getTitle',
- 'reference' => 'getReference',
- 'branch' => 'getBranch',
- 'default_branch_only' => 'getDefaultBranchOnly',
- 'ssh_private_key' => 'getSshPrivateKey',
- 'type' => 'getType',
- 'access_information' => 'getAccessInformation',
- 'last_commit' => 'getLastCommit',
- 'build_config' => 'getBuildConfig',
- 'ssh_public_key' => 'getSshPublicKey',
- 'allow_public_status' => 'getAllowPublicStatus',
- 'archived' => 'getArchived',
- 'group_id' => 'getGroupId',
- 'create_date' => 'getCreateDate',
- 'user_id' => 'getUserId',
-
- // Foreign key getters:
- 'Group' => 'getGroup',
- ];
-
- /**
- * @var array
- */
- protected $setters = [
- // Direct property setters:
- 'id' => 'setId',
- 'title' => 'setTitle',
- 'reference' => 'setReference',
- 'branch' => 'setBranch',
- 'default_branch_only' => 'setDefaultBranchOnly',
- 'ssh_private_key' => 'setSshPrivateKey',
- 'type' => 'setType',
- 'access_information' => 'setAccessInformation',
- 'last_commit' => 'setLastCommit',
- 'build_config' => 'setBuildConfig',
- 'ssh_public_key' => 'setSshPublicKey',
- 'allow_public_status' => 'setAllowPublicStatus',
- 'archived' => 'setArchived',
- 'group_id' => 'setGroupId',
- 'create_date' => 'setCreateDate',
- 'user_id' => 'setUserId',
-
- // Foreign key setters:
- 'Group' => 'setGroup',
- ];
-
- /**
- * @return integer
- */
- public function getId()
- {
- $rtn = $this->data['id'];
-
- return $rtn;
- }
-
- /**
- * @return string
- */
- public function getTitle()
- {
- $rtn = $this->data['title'];
-
- return $rtn;
- }
-
- /**
- * @return string
- */
- public function getReference()
- {
- $rtn = $this->data['reference'];
-
- return $rtn;
- }
-
- /**
- * @return string
- */
- public function getSshPrivateKey()
- {
- $rtn = $this->data['ssh_private_key'];
-
- return $rtn;
- }
-
- /**
- * @return string
- */
- public function getType()
- {
- $rtn = $this->data['type'];
-
- return $rtn;
- }
-
- /**
- * @return string
- */
- public function getLastCommit()
- {
- $rtn = $this->data['last_commit'];
-
- return $rtn;
- }
-
- /**
- * @return string
- */
- public function getBuildConfig()
- {
- $rtn = $this->data['build_config'];
-
- return $rtn;
- }
-
- /**
- * @return string
- */
- public function getSshPublicKey()
- {
- $rtn = $this->data['ssh_public_key'];
-
- return $rtn;
- }
-
- /**
- * @return integer
- */
- public function getAllowPublicStatus()
- {
- $rtn = $this->data['allow_public_status'];
-
- return $rtn;
- }
-
- /**
- * @return integer
- */
- public function getArchived()
- {
- $rtn = $this->data['archived'];
-
- return $rtn;
- }
-
- /**
- * @return integer
- */
- public function getGroupId()
- {
- $rtn = $this->data['group_id'];
-
- return $rtn;
- }
-
- /**
- * @return integer
- */
- public function getDefaultBranchOnly()
- {
- $rtn = $this->data['default_branch_only'];
-
- return $rtn;
- }
-
- /**
- * @param integer $value
- */
- public function setId($value)
- {
- $this->validateNotNull('id', $value);
- $this->validateInt('id', $value);
-
- if ($this->data['id'] === $value) {
- return;
- }
-
- $this->data['id'] = $value;
-
- $this->setModified('id');
- }
-
- /**
- * @param string $value
- */
- public function setTitle($value)
- {
- $this->validateNotNull('title', $value);
- $this->validateString('title', $value);
-
- if ($this->data['title'] === $value) {
- return;
- }
-
- $this->data['title'] = $value;
-
- $this->setModified('title');
- }
-
- /**
- * @param string $value
- */
- public function setReference($value)
- {
- $this->validateNotNull('reference', $value);
- $this->validateString('reference', $value);
-
- if ($this->data['reference'] === $value) {
- return;
- }
-
- $this->data['reference'] = $value;
-
- $this->setModified('reference');
- }
-
- /**
- * @param string $value
- */
- public function setBranch($value)
- {
- $this->validateNotNull('branch', $value);
- $this->validateString('branch', $value);
-
- if ($this->data['branch'] === $value) {
- return;
- }
-
- $this->data['branch'] = $value;
-
- $this->setModified('branch');
- }
-
- /**
- * @param integer $value
- */
- public function setDefaultBranchOnly($value)
- {
- $this->validateNotNull('default_branch_only', $value);
- $this->validateInt('default_branch_only', $value);
-
- if ($this->data['default_branch_only'] === $value) {
- return;
- }
-
- $this->data['default_branch_only'] = $value;
-
- $this->setModified('default_branch_only');
- }
-
- /**
- * @param string $value
- */
- public function setSshPrivateKey($value)
- {
- $this->validateString('ssh_private_key', $value);
-
- if ($this->data['ssh_private_key'] === $value) {
- return;
- }
-
- $this->data['ssh_private_key'] = $value;
-
- $this->setModified('ssh_private_key');
- }
-
- /**
- * @param string $value
- */
- public function setType($value)
- {
- $this->validateNotNull('type', $value);
- $this->validateString('type', $value);
-
- if ($this->data['type'] === $value) {
- return;
- }
-
- $this->data['type'] = $value;
-
- $this->setModified('type');
- }
-
- /**
- * @param string $value
- */
- public function setLastCommit($value)
- {
- $this->validateString('last_commit', $value);
-
- if ($this->data['last_commit'] === $value) {
- return;
- }
-
- $this->data['last_commit'] = $value;
-
- $this->setModified('last_commit');
- }
-
- /**
- * @param string $value
- */
- public function setBuildConfig($value)
- {
- $this->validateString('build_config', $value);
-
- if ($this->data['build_config'] === $value) {
- return;
- }
-
- $this->data['build_config'] = $value;
-
- $this->setModified('build_config');
- }
-
- /**
- * @param string $value
- */
- public function setSshPublicKey($value)
- {
- $this->validateString('ssh_public_key', $value);
-
- if ($this->data['ssh_public_key'] === $value) {
- return;
- }
-
- $this->data['ssh_public_key'] = $value;
-
- $this->setModified('ssh_public_key');
- }
-
- /**
- * @param integer $value
- */
- public function setAllowPublicStatus($value)
- {
- $this->validateNotNull('allow_public_status', $value);
- $this->validateInt('allow_public_status', $value);
-
- if ($this->data['allow_public_status'] === $value) {
- return;
- }
-
- $this->data['allow_public_status'] = $value;
-
- $this->setModified('allow_public_status');
- }
-
- /**
- * @param integer $value
- */
- public function setArchived($value)
- {
- $this->validateNotNull('archived', $value);
- $this->validateInt('archived', $value);
-
- if ($this->data['archived'] === $value) {
- return;
- }
-
- $this->data['archived'] = $value;
-
- $this->setModified('archived');
- }
-
- /**
- * @param integer $value
- */
- public function setGroupId($value)
- {
- $this->validateNotNull('group_id', $value);
- $this->validateInt('group_id', $value);
-
- if ($this->data['group_id'] === $value) {
- return;
- }
-
- $this->data['group_id'] = $value;
-
- $this->setModified('group_id');
- }
-
- /**
- * Get the ProjectGroup model for this Project by Id.
- *
- * @return \PHPCensor\Model\ProjectGroup
+ * @return ProjectGroup|null
*/
public function getGroup()
{
$groupId = $this->getGroupId();
-
if (empty($groupId)) {
return null;
}
- return Factory::getStore('ProjectGroup')->getById($groupId);
+ /** @var ProjectGroupStore $groupStore */
+ $groupStore = Factory::getStore('ProjectGroup');
+
+ return $groupStore->getById($groupId);
}
/**
@@ -509,138 +94,6 @@ class Project extends Model
return null;
}
- /**
- * @param string|array $value
- */
- public function setAccessInformation($value)
- {
- if (is_array($value)) {
- $value = json_encode($value);
- }
-
- $this->validateString('access_information', $value);
-
- if ($this->data['access_information'] === $value) {
- return;
- }
-
- $this->data['access_information'] = $value;
-
- $this->setModified('access_information');
- }
-
- /**
- * Get this project's access_information data. Pass a specific key or null for all data.
- *
- * @param string|null $key
- *
- * @return mixed|null|string
- */
- public function getAccessInformation($key = null)
- {
- $info = $this->data['access_information'];
-
- // Handle old-format (serialized) access information first:
- if (!empty($info) && !in_array(substr($info, 0, 1), ['{', '['])) {
- $data = unserialize($info);
- } else {
- $data = json_decode($info, true);
- }
-
- if (is_null($key)) {
- $rtn = $data;
- } elseif (isset($data[$key])) {
- $rtn = $data[$key];
- } else {
- $rtn = null;
- }
-
- return $rtn;
- }
-
- /**
- * @return \DateTime
- */
- public function getCreateDate()
- {
- $rtn = $this->data['create_date'];
-
- if (!empty($rtn)) {
- $rtn = new \DateTime($rtn);
- }
-
- return $rtn;
- }
-
- /**
- * @param \DateTime $value
- */
- public function setCreateDate(\DateTime $value)
- {
- $stringValue = $value->format('Y-m-d H:i:s');
-
- if ($this->data['create_date'] === $stringValue) {
- return;
- }
-
- $this->data['create_date'] = $stringValue;
-
- $this->setModified('create_date');
- }
-
- /**
- * @return string
- */
- public function getUserId()
- {
- $rtn = $this->data['user_id'];
-
- return (integer)$rtn;
- }
-
- /**
- * @param integer $value
- */
- public function setUserId($value)
- {
- $this->validateNotNull('user_id', $value);
- $this->validateInt('user_id', $value);
-
- if ($this->data['user_id'] === $value) {
- return;
- }
-
- $this->data['user_id'] = $value;
-
- $this->setModified('user_id');
- }
-
- /**
- * Get the value of branch.
- *
- * @return string
- */
- public function getBranch()
- {
- if (empty($this->data['branch'])) {
- $projectType = $this->getType();
- switch ($projectType) {
- case 'hg':
- $branch = 'default';
- break;
- case 'svn':
- $branch = 'trunk';
- break;
- default:
- $branch = 'master';
- }
-
- return $branch;
- } else {
- return $this->data['branch'];
- }
- }
-
/**
* Return the name of a FontAwesome icon to represent this project, depending on its type.
*
diff --git a/src/Model/ProjectGroup.php b/src/Model/ProjectGroup.php
index 5e9d75dc..05ab3b39 100644
--- a/src/Model/ProjectGroup.php
+++ b/src/Model/ProjectGroup.php
@@ -2,164 +2,20 @@
namespace PHPCensor\Model;
-use PHPCensor\Model;
use PHPCensor\Store\Factory;
+use PHPCensor\Model\Base\ProjectGroup as BaseProjectGroup;
+use PHPCensor\Store\ProjectStore;
-class ProjectGroup extends Model
+class ProjectGroup extends BaseProjectGroup
{
/**
- * @var string
- */
- protected $tableName = 'project_group';
-
- /**
- * @var array
- */
- protected $data = [
- 'id' => null,
- 'title' => null,
- 'create_date' => null,
- 'user_id' => 0,
- ];
-
- /**
- * @var array
- */
- protected $getters = [
- 'id' => 'getId',
- 'title' => 'getTitle',
- 'create_date' => 'getCreateDate',
- 'user_id' => 'getUserId',
- ];
-
- /**
- * @var array
- */
- protected $setters = [
- 'id' => 'setId',
- 'title' => 'setTitle',
- 'create_date' => 'setCreateDate',
- 'user_id' => 'setUserId',
- ];
-
- /**
- * @return integer
- */
- public function getId()
- {
- $rtn = $this->data['id'];
-
- return $rtn;
- }
-
- /**
- * @param integer $value
- */
- public function setId($value)
- {
- $this->validateNotNull('id', $value);
- $this->validateInt('id', $value);
-
- if ($this->data['id'] === $value) {
- return;
- }
-
- $this->data['id'] = $value;
-
- $this->setModified('id');
- }
-
- /**
- * @return string
- */
- public function getTitle()
- {
- $rtn = $this->data['title'];
-
- return $rtn;
- }
-
- /**
- * @param string $value
- */
- public function setTitle($value)
- {
- $this->validateNotNull('title', $value);
- $this->validateString('title', $value);
-
- if ($this->data['title'] === $value) {
- return;
- }
-
- $this->data['title'] = $value;
-
- $this->setModified('title');
- }
-
- /**
- * @return \DateTime
- */
- public function getCreateDate()
- {
- $rtn = $this->data['create_date'];
-
- if (!empty($rtn)) {
- $rtn = new \DateTime($rtn);
- }
-
- return $rtn;
- }
-
- /**
- * @param \DateTime $value
- */
- public function setCreateDate(\DateTime $value)
- {
- $stringValue = $value->format('Y-m-d H:i:s');
-
- if ($this->data['create_date'] === $stringValue) {
- return;
- }
-
- $this->data['create_date'] = $stringValue;
-
- $this->setModified('create_date');
- }
-
- /**
- * @return string
- */
- public function getUserId()
- {
- $rtn = $this->data['user_id'];
-
- return (integer)$rtn;
- }
-
- /**
- * @param integer $value
- */
- public function setUserId($value)
- {
- $this->validateNotNull('user_id', $value);
- $this->validateInt('user_id', $value);
-
- if ($this->data['user_id'] === $value) {
- return;
- }
-
- $this->data['user_id'] = $value;
-
- $this->setModified('user_id');
- }
-
- /**
- * Get Project models by GroupId for this ProjectGroup.
- *
- * @return \PHPCensor\Model\Project[]
+ * @return Project[]
*/
public function getGroupProjects()
{
- return Factory::getStore('Project')->getByGroupId($this->getId(), false);
+ /** @var ProjectStore $projectStore */
+ $projectStore = Factory::getStore('Project');
+
+ return $projectStore->getByGroupId($this->getId(), false);
}
}
diff --git a/src/Model/User.php b/src/Model/User.php
index 2bba224c..bc90c9d8 100644
--- a/src/Model/User.php
+++ b/src/Model/User.php
@@ -3,328 +3,13 @@
namespace PHPCensor\Model;
use PHPCensor\Config;
-use PHPCensor\Model;
+use PHPCensor\Model\Base\User as BaseUser;
/**
* @author Dan Cryer
*/
-class User extends Model
+class User extends BaseUser
{
- /**
- * @var string
- */
- protected $tableName = 'user';
-
- /**
- * @var array
- */
- protected $data = [
- 'id' => null,
- 'email' => null,
- 'hash' => null,
- 'is_admin' => null,
- 'name' => null,
- 'language' => null,
- 'per_page' => null,
- 'provider_key' => null,
- 'provider_data' => null,
- 'remember_key' => null,
- ];
-
- /**
- * @var array
- */
- protected $getters = [
- 'id' => 'getId',
- 'email' => 'getEmail',
- 'hash' => 'getHash',
- 'is_admin' => 'getIsAdmin',
- 'name' => 'getName',
- 'language' => 'getLanguage',
- 'per_page' => 'getPerPage',
- 'provider_key' => 'getProviderKey',
- 'provider_data' => 'getProviderData',
- 'remember_key' => 'getRememberKey',
- ];
-
- /**
- * @var array
- */
- protected $setters = [
- 'id' => 'setId',
- 'email' => 'setEmail',
- 'hash' => 'setHash',
- 'is_admin' => 'setIsAdmin',
- 'name' => 'setName',
- 'language' => 'setLanguage',
- 'per_page' => 'setPerPage',
- 'provider_key' => 'setProviderKey',
- 'provider_data' => 'setProviderData',
- 'remember_key' => 'setRememberKey',
- ];
-
- /**
- * @return integer
- */
- public function getId()
- {
- $rtn = $this->data['id'];
-
- return $rtn;
- }
-
- /**
- * @return string
- */
- public function getEmail()
- {
- $rtn = $this->data['email'];
-
- return $rtn;
- }
-
- /**
- * @return string
- */
- public function getHash()
- {
- $rtn = $this->data['hash'];
-
- return $rtn;
- }
-
- /**
- * @return string
- */
- public function getName()
- {
- $rtn = $this->data['name'];
-
- return $rtn;
- }
-
- /**
- * @return integer
- */
- public function getIsAdmin()
- {
- $rtn = $this->data['is_admin'];
-
- return $rtn;
- }
-
- /**
- * @return string
- */
- public function getProviderKey()
- {
- $rtn = $this->data['provider_key'];
-
- return $rtn;
- }
-
- /**
- * @return string
- */
- public function getProviderData()
- {
- $rtn = $this->data['provider_data'];
-
- return $rtn;
- }
-
- /**
- * @return string
- */
- public function getRememberKey()
- {
- $rtn = $this->data['remember_key'];
-
- return $rtn;
- }
-
- /**
- * @return string
- */
- public function getLanguage()
- {
- $rtn = $this->data['language'];
-
- return $rtn;
- }
-
- /**
- * @return string
- */
- public function getPerPage()
- {
- $rtn = $this->data['per_page'];
-
- return $rtn;
- }
-
- /**
- * @param integer $value
- */
- public function setId($value)
- {
- $this->validateNotNull('id', $value);
- $this->validateInt('id', $value);
-
- if ($this->data['id'] === $value) {
- return;
- }
-
- $this->data['id'] = $value;
-
- $this->setModified('id');
- }
-
- /**
- * @param string $value
- */
- public function setEmail($value)
- {
- $this->validateNotNull('email', $value);
- $this->validateString('email', $value);
-
- if ($this->data['email'] === $value) {
- return;
- }
-
- $this->data['email'] = $value;
-
- $this->setModified('email');
- }
-
- /**
- * @param string $value
- */
- public function setHash($value)
- {
- $this->validateNotNull('hash', $value);
- $this->validateString('hash', $value);
-
- if ($this->data['hash'] === $value) {
- return;
- }
-
- $this->data['hash'] = $value;
-
- $this->setModified('hash');
- }
-
- /**
- * @param string $value
- */
- public function setName($value)
- {
- $this->validateNotNull('name', $value);
- $this->validateString('name', $value);
-
- if ($this->data['name'] === $value) {
- return;
- }
-
- $this->data['name'] = $value;
-
- $this->setModified('name');
- }
-
- /**
- * @param integer $value
- */
- public function setIsAdmin($value)
- {
- $this->validateNotNull('is_admin', $value);
- $this->validateInt('is_admin', $value);
-
- if ($this->data['is_admin'] === $value) {
- return;
- }
-
- $this->data['is_admin'] = $value;
-
- $this->setModified('is_admin');
- }
-
- /**
- * @param string $value
- */
- public function setProviderKey($value)
- {
- $this->validateNotNull('provider_key', $value);
- $this->validateString('provider_key', $value);
-
- if ($this->data['provider_key'] === $value) {
- return;
- }
-
- $this->data['provider_key'] = $value;
-
- $this->setModified('provider_key');
- }
-
- /**
- * @param string $value
- */
- public function setProviderData($value)
- {
- $this->validateString('provider_data', $value);
-
- if ($this->data['provider_data'] === $value) {
- return;
- }
-
- $this->data['provider_data'] = $value;
-
- $this->setModified('provider_data');
- }
-
- /**
- * @param string $value
- */
- public function setRememberKey($value)
- {
- $this->validateString('remember_key', $value);
-
- if ($this->data['remember_key'] === $value) {
- return;
- }
-
- $this->data['remember_key'] = $value;
-
- $this->setModified('remember_key');
- }
-
- /**
- * @param string $value
- */
- public function setLanguage($value)
- {
- if ($this->data['language'] === $value) {
- return;
- }
-
- $this->data['language'] = $value;
-
- $this->setModified('language');
- }
-
- /**
- * @param string $value
- */
- public function setPerPage($value)
- {
- if ($this->data['per_page'] === $value) {
- return;
- }
-
- $this->data['per_page'] = $value;
-
- $this->setModified('per_page');
- }
-
/**
* @return integer
*/
@@ -332,7 +17,7 @@ class User extends Model
{
$perPage = $this->getPerPage();
if ($perPage) {
- return (integer)$perPage;
+ return $perPage;
}
return (integer)Config::getInstance()->get('php-censor.per_page', 10);
diff --git a/src/Security/Authentication/UserProvider/Ldap.php b/src/Security/Authentication/UserProvider/Ldap.php
index 54163f63..88a91fb0 100644
--- a/src/Security/Authentication/UserProvider/Ldap.php
+++ b/src/Security/Authentication/UserProvider/Ldap.php
@@ -79,6 +79,6 @@ class Ldap extends AbstractProvider implements LoginPasswordProviderInterface
$parts = explode("@", $identifier);
$username = $parts[0];
- return $userService->createUser($username, $identifier, $this->key, json_encode($this->config), '', false);
+ return $userService->createUser($username, $identifier, $this->key, $this->config, '', false);
}
}
diff --git a/src/Service/BuildService.php b/src/Service/BuildService.php
index aa59aaca..b8503fb7 100644
--- a/src/Service/BuildService.php
+++ b/src/Service/BuildService.php
@@ -43,7 +43,7 @@ class BuildService
* @param string|null $commitMessage
* @param integer $source
* @param integer $userId
- * @param string|null $extra
+ * @param array|null $extra
*
* @return \PHPCensor\Model\Build
*/
@@ -65,8 +65,12 @@ class BuildService
$build->setStatus(Build::STATUS_PENDING);
$build->setEnvironment($environment);
+ if (!is_null($extra)) {
+ $build->setExtra($extra);
+ }
+
$branches = $project->getBranchesByEnvironment($environment);
- $build->setExtraValue('branches', $branches);
+ $build->addExtraValue('branches', $branches);
$build->setSource($source);
$build->setUserId($userId);
@@ -90,10 +94,6 @@ class BuildService
$build->setCommitMessage($commitMessage);
}
- if (!is_null($extra)) {
- $build->setExtraValues($extra);
- }
-
/** @var Build $build */
$build = $this->buildStore->save($build);
$buildId = $build->getId();
@@ -123,7 +123,7 @@ class BuildService
$build->setTag($data['tag']);
$build->setCommitterEmail($data['committer_email']);
$build->setCommitMessage($data['commit_message']);
- $build->setExtra($data['extra']);
+ $build->setExtra(json_decode($data['extra'], true));
$build->setEnvironment($data['environment']);
$build->setSource($data['source']);
$build->setUserId($data['user_id']);
diff --git a/src/Service/ProjectService.php b/src/Service/ProjectService.php
index b40fdbc4..29cee64a 100644
--- a/src/Service/ProjectService.php
+++ b/src/Service/ProjectService.php
@@ -63,8 +63,8 @@ class ProjectService
$project->setTitle($title);
$project->setType($type);
$project->setReference($reference);
- $project->setAllowPublicStatus(0);
- $project->setDefaultBranchOnly(0);
+ $project->setAllowPublicStatus(false);
+ $project->setDefaultBranchOnly(false);
// Handle extra project options:
if (array_key_exists('ssh_private_key', $options)) {
@@ -80,11 +80,11 @@ class ProjectService
}
if (array_key_exists('allow_public_status', $options)) {
- $project->setAllowPublicStatus((int)$options['allow_public_status']);
+ $project->setAllowPublicStatus($options['allow_public_status']);
}
if (array_key_exists('archived', $options)) {
- $project->setArchived((bool)$options['archived']);
+ $project->setArchived($options['archived']);
}
if (array_key_exists('branch', $options)) {
@@ -92,7 +92,7 @@ class ProjectService
}
if (array_key_exists('default_branch_only', $options)) {
- $project->setDefaultBranchOnly((int)$options['default_branch_only']);
+ $project->setDefaultBranchOnly($options['default_branch_only']);
}
if (array_key_exists('group', $options)) {
diff --git a/src/Service/UserService.php b/src/Service/UserService.php
index c3abd18d..efec9846 100644
--- a/src/Service/UserService.php
+++ b/src/Service/UserService.php
@@ -29,7 +29,7 @@ class UserService
* @param string $name
* @param string $email
* @param string $providerKey
- * @param string $providerData
+ * @param array $providerData
* @param string $password
* @param boolean $isAdmin
*
@@ -43,7 +43,7 @@ class UserService
$user->setHash(password_hash($password, PASSWORD_DEFAULT));
$user->setProviderKey($providerKey);
$user->setProviderData($providerData);
- $user->setIsAdmin(($isAdmin ? 1 : 0));
+ $user->setIsAdmin($isAdmin);
return $this->store->save($user);
}
@@ -71,9 +71,9 @@ class UserService
}
if (!is_null($isAdmin)) {
- $user->setIsAdmin(($isAdmin ? 1 : 0));
+ $user->setIsAdmin($isAdmin);
}
-
+
$user->setLanguage($language);
$user->setPerPage($perPage);
diff --git a/src/View/Build/view.phtml b/src/View/Build/view.phtml
index edf57525..888323e7 100644
--- a/src/View/Build/view.phtml
+++ b/src/View/Build/view.phtml
@@ -120,7 +120,7 @@ use PHPCensor\Model\BuildError;
|
- = $build->getCommitMessage(); ?>
+ = htmlspecialchars($build->getCommitMessage()); ?>
|
diff --git a/src/View/BuildStatus/view.phtml b/src/View/BuildStatus/view.phtml
index e7382e48..92e50371 100644
--- a/src/View/BuildStatus/view.phtml
+++ b/src/View/BuildStatus/view.phtml
@@ -68,8 +68,9 @@
= $latest->getProject()->getTitle(); ?> #= $latest->getId(); ?> (= $statusText; ?>)
- getCommitMessage()): ?>
- = $latest->getCommitMessage(); ?>
+ getCommitMessage()); ?>
+
+ = $latestCommitMessage; ?>
Branch: = $latest->getBranch(); ?>
diff --git a/src/View/Email/long.phtml b/src/View/Email/long.phtml
index 33301747..db0c3ce6 100644
--- a/src/View/Email/long.phtml
+++ b/src/View/Email/long.phtml
@@ -4,7 +4,7 @@ use PHPCensor\Helper\AnsiConverter;
?>
- = $build->getCommitMessage(); ?>
+ = htmlspecialchars($build->getCommitMessage()); ?>
= AnsiConverter::convert($build->getLog()); ?>
diff --git a/src/View/Email/short.phtml b/src/View/Email/short.phtml
index 9f6475b9..ec59bd1a 100644
--- a/src/View/Email/short.phtml
+++ b/src/View/Email/short.phtml
@@ -1,3 +1,3 @@
- = $build->getCommitMessage(); ?>
+ = htmlspecialchars($build->getCommitMessage()); ?>
diff --git a/src/View/WidgetLastBuilds/update.phtml b/src/View/WidgetLastBuilds/update.phtml
index bedffa6d..4fabfdf7 100644
--- a/src/View/WidgetLastBuilds/update.phtml
+++ b/src/View/WidgetLastBuilds/update.phtml
@@ -115,9 +115,10 @@ use PHPCensor\Model\Build;
substr($build->getCommitId(), 0, 7),
$build->getCommitterEmail() ? ('(' . $build->getCommitterEmail() . ')') : ''
);
- if (!empty($build->getCommitMessage())) {
+ $buildCommitMessage = htmlspecialchars($build->getCommitMessage());
+ if ($buildCommitMessage) {
echo '
';
- print $build->getCommitMessage();
+ echo $buildCommitMessage;
}
}
?>
diff --git a/tests/src/Model/BuildTest.php b/tests/src/Model/BuildTest.php
index 02ae078f..e34c2c31 100644
--- a/tests/src/Model/BuildTest.php
+++ b/tests/src/Model/BuildTest.php
@@ -126,32 +126,16 @@ class BuildTest extends \PHPUnit\Framework\TestCase
];
$build = new Build();
- $build->setExtra(json_encode($info));
+ $build->setExtra($info);
self::assertEquals('Item One', $build->getExtra('item1'));
self::assertEquals(2, $build->getExtra('item2'));
self::assertNull($build->getExtra('item3'));
self::assertEquals($info, $build->getExtra());
- $build->setExtraValue('item3', 'Item Three');
+ $build->addExtraValue('item3', 'Item Three');
self::assertEquals('Item One', $build->getExtra('item1'));
self::assertEquals('Item Three', $build->getExtra('item3'));
-
- $build->setExtraValues([
- 'item3' => 'Item Three New',
- 'item4' => 4,
- ]);
-
- self::assertEquals('Item One', $build->getExtra('item1'));
- self::assertEquals('Item Three New', $build->getExtra('item3'));
- self::assertEquals(4, $build->getExtra('item4'));
-
- self::assertEquals([
- 'item1' => 'Item One',
- 'item2' => 2,
- 'item3' => 'Item Three New',
- 'item4' => 4,
- ], $build->getExtra());
}
}
diff --git a/tests/src/Service/BuildServiceTest.php b/tests/src/Service/BuildServiceTest.php
index b3f4d7dc..9726fcdd 100644
--- a/tests/src/Service/BuildServiceTest.php
+++ b/tests/src/Service/BuildServiceTest.php
@@ -148,7 +148,7 @@ class BuildServiceTest extends \PHPUnit\Framework\TestCase
$build->setFinishDate(new \DateTime());
$build->setCommitMessage('test');
$build->setCommitterEmail('test@example.com');
- $build->setExtra(json_encode(['item1' => 1001]));
+ $build->setExtra(['item1' => 1001]);
$returnValue = $this->testedService->createDuplicateBuild($build);
diff --git a/tests/src/Service/ProjectServiceTest.php b/tests/src/Service/ProjectServiceTest.php
index d9cd5862..3e7c7762 100644
--- a/tests/src/Service/ProjectServiceTest.php
+++ b/tests/src/Service/ProjectServiceTest.php
@@ -48,7 +48,7 @@ class ProjectServiceTest extends \PHPUnit\Framework\TestCase
$options = [
'ssh_private_key' => 'private',
'ssh_public_key' => 'public',
- 'allow_public_status' => 1,
+ 'allow_public_status' => true,
'build_config' => 'config',
'branch' => 'testbranch',
];
@@ -59,7 +59,7 @@ class ProjectServiceTest extends \PHPUnit\Framework\TestCase
self::assertEquals('public', $returnValue->getSshPublicKey());
self::assertEquals('config', $returnValue->getBuildConfig());
self::assertEquals('testbranch', $returnValue->getBranch());
- self::assertEquals(1, $returnValue->getAllowPublicStatus());
+ self::assertEquals(true, $returnValue->getAllowPublicStatus());
}
/**
@@ -92,7 +92,7 @@ class ProjectServiceTest extends \PHPUnit\Framework\TestCase
public function testExecute_EmptyPublicStatus()
{
$project = new Project();
- $project->setAllowPublicStatus(1);
+ $project->setAllowPublicStatus(true);
$options = [
'ssh_private_key' => 'private',
@@ -102,7 +102,7 @@ class ProjectServiceTest extends \PHPUnit\Framework\TestCase
$returnValue = $this->testedService->updateProject($project, 'Test Project', 'github', 'block8/phpci', $options);
- self::assertEquals(0, $returnValue->getAllowPublicStatus());
+ self::assertEquals(false, $returnValue->getAllowPublicStatus());
}
public function testExecute_DeleteProject()
diff --git a/tests/src/Service/UserServiceTest.php b/tests/src/Service/UserServiceTest.php
index cfe9096d..02874586 100644
--- a/tests/src/Service/UserServiceTest.php
+++ b/tests/src/Service/UserServiceTest.php
@@ -39,14 +39,14 @@ class UserServiceTest extends \PHPUnit\Framework\TestCase
'Test',
'test@example.com',
'internal',
- json_encode(['type' => 'internal']),
+ ['type' => 'internal'],
'testing',
false
);
self::assertEquals('Test', $user->getName());
self::assertEquals('test@example.com', $user->getEmail());
- self::assertEquals(0, $user->getIsAdmin());
+ self::assertEquals(false, $user->getIsAdmin());
self::assertTrue(password_verify('testing', $user->getHash()));
}
@@ -56,12 +56,12 @@ class UserServiceTest extends \PHPUnit\Framework\TestCase
'Test',
'test@example.com',
'internal',
- json_encode(['type' => 'internal']),
+ ['type' => 'internal'],
'testing',
true
);
- self::assertEquals(1, $user->getIsAdmin());
+ self::assertEquals(true, $user->getIsAdmin());
}
public function testExecute_RevokeAdminStatus()
@@ -69,10 +69,10 @@ class UserServiceTest extends \PHPUnit\Framework\TestCase
$user = new User();
$user->setEmail('test@example.com');
$user->setName('Test');
- $user->setIsAdmin(1);
+ $user->setIsAdmin(true);
- $user = $this->testedService->updateUser($user, 'Test', 'test@example.com', 'testing', 0);
- self::assertEquals(0, $user->getIsAdmin());
+ $user = $this->testedService->updateUser($user, 'Test', 'test@example.com', 'testing', false);
+ self::assertEquals(false, $user->getIsAdmin());
}
public function testExecute_GrantAdminStatus()
@@ -80,10 +80,10 @@ class UserServiceTest extends \PHPUnit\Framework\TestCase
$user = new User();
$user->setEmail('test@example.com');
$user->setName('Test');
- $user->setIsAdmin(0);
+ $user->setIsAdmin(false);
- $user = $this->testedService->updateUser($user, 'Test', 'test@example.com', 'testing', 1);
- self::assertEquals(1, $user->getIsAdmin());
+ $user = $this->testedService->updateUser($user, 'Test', 'test@example.com', 'testing', true);
+ self::assertEquals(true, $user->getIsAdmin());
}
public function testExecute_ChangesPasswordIfNotEmpty()
@@ -91,7 +91,7 @@ class UserServiceTest extends \PHPUnit\Framework\TestCase
$user = new User();
$user->setHash(password_hash('testing', PASSWORD_DEFAULT));
- $user = $this->testedService->updateUser($user, 'Test', 'test@example.com', 'newpassword', 0);
+ $user = $this->testedService->updateUser($user, 'Test', 'test@example.com', 'newpassword', false);
self::assertFalse(password_verify('testing', $user->getHash()));
self::assertTrue(password_verify('newpassword', $user->getHash()));
}
@@ -101,7 +101,7 @@ class UserServiceTest extends \PHPUnit\Framework\TestCase
$user = new User();
$user->setHash(password_hash('testing', PASSWORD_DEFAULT));
- $user = $this->testedService->updateUser($user, 'Test', 'test@example.com', '', 0);
+ $user = $this->testedService->updateUser($user, 'Test', 'test@example.com', '', false);
self::assertTrue(password_verify('testing', $user->getHash()));
}
}