Fixing some more PHPCS/PHPMD errors

This commit is contained in:
Dan Cryer 2013-10-10 01:18:05 +01:00
parent 16003ff01b
commit 05be06f9b3
2 changed files with 7 additions and 35 deletions

View file

@ -6,8 +6,6 @@
namespace PHPCI\Model;
require_once(APPLICATION_PATH . 'PHPCI/Model/Base/BuildMetaBase.php');
use PHPCI\Model\Base\BuildMetaBase;
/**
@ -16,5 +14,5 @@ use PHPCI\Model\Base\BuildMetaBase;
*/
class BuildMeta extends BuildMetaBase
{
// This class has been left blank so that you can modify it - changes in this file will not be overwritten.
// This class has been left blank so that you can modify it - changes in this file will not be overwritten.
}

View file

@ -39,39 +39,12 @@ class BuildStore extends BuildStoreBase
}
}
public function getBuildSummary()
{
$query = 'SELECT COUNT(*) AS cnt FROM build b LEFT JOIN project p on p.id = b.project_id GROUP BY b.project_id ORDER BY p.title ASC, b.id DESC';
$stmt = \b8\Database::getConnection('read')->prepare($query);
if ($stmt->execute()) {
$res = $stmt->fetch(\PDO::FETCH_ASSOC);
$count = (int)$res['cnt'];
} else {
$count = 0;
}
$query = 'SELECT b.* FROM build b LEFT JOIN project p on p.id = b.project_id ORDER BY p.title ASC, b.id DESC';
$stmt = \b8\Database::getConnection('read')->prepare($query);
if ($stmt->execute()) {
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$map = function ($item) {
return new \PHPCI\Model\Build($item);
};
$rtn = array_map($map, $res);
return array('items' => $rtn, 'count' => $count);
} else {
return array('items' => array(), 'count' => 0);
}
}
public function getMeta($key, $projectId, $buildId = null, $numResults = 1)
{
$select = '`build_id`, `meta_key`, `meta_value`';
$and = $numResults > 1 ? ' AND (`build_id` <= :buildId) ' : ' AND (`build_id` = :buildId) ';
$query = 'SELECT `build_id`, `meta_key`, `meta_value` FROM `build_meta` WHERE `meta_key` = :key AND `project_id` = :projectId ' . $and . ' ORDER BY id DESC LIMIT :numResults';
$where = '`meta_key` = :key AND `project_id` = :projectId ' . $and;
$query = 'SELECT '.$select.' FROM `build_meta` WHERE '.$where.' ORDER BY id DESC LIMIT :numResults';
$stmt = \b8\Database::getConnection('read')->prepare($query);
$stmt->bindValue(':key', $key, \PDO::PARAM_STR);
@ -83,7 +56,7 @@ class BuildStore extends BuildStoreBase
$rtn = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$rtn = array_reverse($rtn);
$rtn = array_map(function($item) {
$rtn = array_map(function ($item) {
$item['meta_value'] = json_decode($item['meta_value'], true);
return $item;
}, $rtn);
@ -101,7 +74,8 @@ class BuildStore extends BuildStoreBase
public function setMeta($projectId, $buildId, $key, $value)
{
$query = 'REPLACE INTO build_meta (project_id, build_id, `meta_key`, `meta_value`) VALUES (:projectId, :buildId, :key, :value)';
$cols = '`project_id`, `build_id`, `meta_key`, `meta_value`';
$query = 'REPLACE INTO build_meta ('.$cols.') VALUES (:projectId, :buildId, :key, :value)';
$stmt = \b8\Database::getConnection('read')->prepare($query);
$stmt->bindValue(':key', $key, \PDO::PARAM_STR);