Code style fixes (camelCased variables).

This commit is contained in:
Dmitry Khomutov 2018-03-08 10:54:52 +07:00
parent 4013fc76ff
commit 8d9c4824c7
No known key found for this signature in database
GPG key ID: EC19426474B37AAC
15 changed files with 141 additions and 142 deletions

View file

@ -221,8 +221,8 @@ class Application
$groups[] = $thisGroup; $groups[] = $thisGroup;
} }
$archived_projects = Factory::getStore('Project')->getAll(true); $archivedProjects = Factory::getStore('Project')->getAll(true);
$layout->archived_projects = $archived_projects['items']; $layout->archived_projects = $archivedProjects['items'];
$layout->groups = $groups; $layout->groups = $groups;
} }

View file

@ -195,12 +195,11 @@ class Builder implements LoggerAwareInterface
$this->build->sendStatusPostback(); $this->build->sendStatusPostback();
$success = true; $success = true;
$previous_build = $this->build->getProject()->getPreviousBuild($this->build->getBranch()); $previousBuild = $this->build->getProject()->getPreviousBuild($this->build->getBranch());
$previousState = Build::STATUS_PENDING;
$previous_state = Build::STATUS_PENDING; if ($previousBuild) {
$previousState = $previousBuild->getStatus();
if ($previous_build) {
$previous_state = $previous_build->getStatus();
} }
try { try {
@ -232,13 +231,13 @@ class Builder implements LoggerAwareInterface
if ($success) { if ($success) {
$this->pluginExecutor->executePlugins($this->config, Build::STAGE_SUCCESS); $this->pluginExecutor->executePlugins($this->config, Build::STAGE_SUCCESS);
if ($previous_state == Build::STATUS_FAILED) { if ($previousState == Build::STATUS_FAILED) {
$this->pluginExecutor->executePlugins($this->config, Build::STAGE_FIXED); $this->pluginExecutor->executePlugins($this->config, Build::STAGE_FIXED);
} }
} else { } else {
$this->pluginExecutor->executePlugins($this->config, Build::STAGE_FAILURE); $this->pluginExecutor->executePlugins($this->config, Build::STAGE_FAILURE);
if ($previous_state == Build::STATUS_SUCCESS || $previous_state == Build::STATUS_PENDING) { if ($previousState == Build::STATUS_SUCCESS || $previousState == Build::STATUS_PENDING) {
$this->pluginExecutor->executePlugins($this->config, Build::STAGE_BROKEN); $this->pluginExecutor->executePlugins($this->config, Build::STAGE_BROKEN);
} }
} }

View file

@ -71,8 +71,8 @@ class Config
$keyParts = explode('.', $key); $keyParts = explode('.', $key);
$selected = $this->config; $selected = $this->config;
$i = -1; $i = -1;
$last_part = count($keyParts) - 1; $lastPart = count($keyParts) - 1;
while ($part = array_shift($keyParts)) { while ($part = array_shift($keyParts)) {
$i++; $i++;
@ -80,7 +80,7 @@ class Config
return $default; return $default;
} }
if ($i === $last_part) { if ($i === $lastPart) {
return $selected[$part]; return $selected[$part];
} else { } else {
$selected = $selected[$part]; $selected = $selected[$part];
@ -177,25 +177,25 @@ class Config
return; return;
} }
foreach ($target as $target_key => $target_value) { foreach ($target as $targetKey => $targetValue) {
if (isset($source[$target_key])) { if (isset($source[$targetKey])) {
if (!is_array($source[$target_key]) && !is_array($target_value)) { if (!is_array($source[$targetKey]) && !is_array($targetValue)) {
// Neither value is an array, overwrite // Neither value is an array, overwrite
$source[$target_key] = $target_value; $source[$targetKey] = $targetValue;
} elseif (is_array($source[$target_key]) && is_array($target_value)) { } elseif (is_array($source[$targetKey]) && is_array($targetValue)) {
// Both are arrays, deep merge them // Both are arrays, deep merge them
self::deepMerge($source[$target_key], $target_value); self::deepMerge($source[$targetKey], $targetValue);
} elseif (is_array($source[$target_key])) { } elseif (is_array($source[$targetKey])) {
// Source is the array, push target value // Source is the array, push target value
$source[$target_key][] = $target_value; $source[$targetKey][] = $targetValue;
} else { } else {
// Target is the array, push source value and copy back // Target is the array, push source value and copy back
$target_value[] = $source[$target_key]; $targetValue[] = $source[$targetKey];
$source[$target_key] = $target_value; $source[$targetKey] = $targetValue;
} }
} else { } else {
// No merge required, just set the value // No merge required, just set the value
$source[$target_key] = $target_value; $source[$targetKey] = $targetValue;
} }
} }
} }

View file

@ -45,10 +45,10 @@ class GroupController extends Controller
'title' => $group->getTitle(), 'title' => $group->getTitle(),
'id' => $group->getId(), 'id' => $group->getId(),
]; ];
$projects_active = Factory::getStore('Project')->getByGroupId($group->getId(), false); $projectsActive = Factory::getStore('Project')->getByGroupId($group->getId(), false);
$projects_archived = Factory::getStore('Project')->getByGroupId($group->getId(), true); $projectsArchived = Factory::getStore('Project')->getByGroupId($group->getId(), true);
$thisGroup['projects'] = array_merge($projects_active['items'], $projects_archived['items']); $thisGroup['projects'] = array_merge($projectsActive['items'], $projectsArchived['items']);
$groups[] = $thisGroup; $groups[] = $thisGroup;
} }

View file

@ -192,12 +192,12 @@ class Database extends \PDO
/** /**
* @param string $statement * @param string $statement
* @param array $driver_options * @param array $driverOptions
* *
* @return \PDOStatement * @return \PDOStatement
*/ */
public function prepareCommon($statement, array $driver_options = []) public function prepareCommon($statement, array $driverOptions = [])
{ {
return parent::prepare($this->quoteNames($statement), $driver_options); return parent::prepare($this->quoteNames($statement), $driverOptions);
} }
} }

View file

@ -756,27 +756,27 @@ class Build extends Model
*/ */
protected function handleConfig(Builder $builder, $buildPath) protected function handleConfig(Builder $builder, $buildPath)
{ {
$build_config = $this->getProject()->getBuildConfig(); $buildConfig = $this->getProject()->getBuildConfig();
if (empty($build_config)) { if (empty($buildConfig)) {
if (file_exists($buildPath . '/.php-censor.yml')) { if (file_exists($buildPath . '/.php-censor.yml')) {
$build_config = file_get_contents($buildPath . '/.php-censor.yml'); $buildConfig = file_get_contents($buildPath . '/.php-censor.yml');
} elseif (file_exists($buildPath . '/.phpci.yml')) { } elseif (file_exists($buildPath . '/.phpci.yml')) {
$build_config = file_get_contents($buildPath . '/.phpci.yml'); $buildConfig = file_get_contents($buildPath . '/.phpci.yml');
} elseif (file_exists($buildPath . '/phpci.yml')) { } elseif (file_exists($buildPath . '/phpci.yml')) {
$build_config = file_get_contents($buildPath . '/phpci.yml'); $buildConfig = file_get_contents($buildPath . '/phpci.yml');
} else { } else {
$build_config = $this->getZeroConfigPlugins($builder); $buildConfig = $this->getZeroConfigPlugins($builder);
} }
} }
// for YAML configs from files/DB // for YAML configs from files/DB
if (is_string($build_config)) { if (is_string($buildConfig)) {
$yamlParser = new YamlParser(); $yamlParser = new YamlParser();
$build_config = $yamlParser->parse($build_config); $buildConfig = $yamlParser->parse($buildConfig);
} }
$builder->setConfigArray($build_config); $builder->setConfigArray($buildConfig);
return true; return true;
} }
@ -989,11 +989,11 @@ class Build extends Model
$end = new \DateTime(); $end = new \DateTime();
} }
$diff = date_diff($start, $end); $diff = date_diff($start, $end);
$parts = []; $parts = [];
foreach (['y', 'm', 'd', 'h', 'i', 's'] as $time_part) { foreach (['y', 'm', 'd', 'h', 'i', 's'] as $timePart) {
if ($diff->{$time_part} != 0) { if ($diff->{$timePart} != 0) {
$parts[] = $diff->{$time_part} . ($time_part == 'i' ? 'm' : $time_part); $parts[] = $diff->{$timePart} . ($timePart == 'i' ? 'm' : $timePart);
} }
} }

View file

@ -702,14 +702,14 @@ class Project extends Model
*/ */
public function getEnvironmentsNames() public function getEnvironmentsNames()
{ {
$environments = $this->getEnvironmentsObjects(); $environments = $this->getEnvironmentsObjects();
$environments_names = []; $environmentsNames = [];
foreach($environments['items'] as $environment) { foreach($environments['items'] as $environment) {
/** @var Environment $environment */ /** @var Environment $environment */
$environments_names[] = $environment->getName(); $environmentsNames[] = $environment->getName();
} }
return $environments_names; return $environmentsNames;
} }
/** /**
@ -719,15 +719,15 @@ class Project extends Model
*/ */
public function getEnvironments() public function getEnvironments()
{ {
$environments = $this->getEnvironmentsObjects(); $environments = $this->getEnvironmentsObjects();
$environments_config = []; $environmentsConfig = [];
foreach($environments['items'] as $environment) { foreach($environments['items'] as $environment) {
/** @var Environment $environment */ /** @var Environment $environment */
$environments_config[$environment->getName()] = $environment->getBranches(); $environmentsConfig[$environment->getName()] = $environment->getBranches();
} }
$yaml_dumper = new YamlDumper(); $yamlDumper = new YamlDumper();
$value = $yaml_dumper->dump($environments_config, 10, 0, true, false); $value = $yamlDumper->dump($environmentsConfig, 10, 0, true, false);
return $value; return $value;
} }
@ -739,18 +739,18 @@ class Project extends Model
*/ */
public function setEnvironments($value) public function setEnvironments($value)
{ {
$yaml_parser = new YamlParser(); $yamlParser = new YamlParser();
$environments_config = $yaml_parser->parse($value); $environmentsConfig = $yamlParser->parse($value);
$environments_names = !empty($environments_config) ? array_keys($environments_config) : []; $environmentsNames = !empty($environmentsConfig) ? array_keys($environmentsConfig) : [];
$current_environments = $this->getEnvironmentsObjects(); $currentEnvironments = $this->getEnvironmentsObjects();
$store = $this->getEnvironmentStore(); $store = $this->getEnvironmentStore();
foreach ($current_environments['items'] as $environment) { foreach ($currentEnvironments['items'] as $environment) {
/** @var Environment $environment */ /** @var Environment $environment */
$key = array_search($environment->getName(), $environments_names); $key = array_search($environment->getName(), $environmentsNames);
if ($key !== false) { if ($key !== false) {
// already exist // already exist
unset($environments_names[$key]); unset($environmentsNames[$key]);
$environment->setBranches(!empty($environments_config[$environment->getName()]) ? $environments_config[$environment->getName()] : []); $environment->setBranches(!empty($environmentsConfig[$environment->getName()]) ? $environmentsConfig[$environment->getName()] : []);
$store->save($environment); $store->save($environment);
} else { } else {
// remove // remove
@ -758,13 +758,13 @@ class Project extends Model
} }
} }
if (!empty($environments_names)) { if (!empty($environmentsNames)) {
// add // add
foreach ($environments_names as $environment_name) { foreach ($environmentsNames as $environmentName) {
$environment = new Environment(); $environment = new Environment();
$environment->setProjectId($this->getId()); $environment->setProjectId($this->getId());
$environment->setName($environment_name); $environment->setName($environmentName);
$environment->setBranches(!empty($environments_config[$environment->getName()]) ? $environments_config[$environment->getName()] : []); $environment->setBranches(!empty($environmentsConfig[$environment->getName()]) ? $environmentsConfig[$environment->getName()] : []);
$store->save($environment); $store->save($environment);
} }
} }
@ -777,31 +777,31 @@ class Project extends Model
*/ */
public function getEnvironmentsNamesByBranch($branch) public function getEnvironmentsNamesByBranch($branch)
{ {
$environments_names = []; $environmentsNames = [];
$environments = $this->getEnvironmentsObjects(); $environments = $this->getEnvironmentsObjects();
$default_branch = ($branch == $this->getBranch()); $defaultBranch = ($branch == $this->getBranch());
foreach($environments['items'] as $environment) { foreach($environments['items'] as $environment) {
/** @var Environment $environment */ /** @var Environment $environment */
if ($default_branch || in_array($branch, $environment->getBranches())) { if ($defaultBranch || in_array($branch, $environment->getBranches())) {
$environments_names[] = $environment->getName(); $environmentsNames[] = $environment->getName();
} }
} }
return $environments_names; return $environmentsNames;
} }
/** /**
* @param string $environment_name * @param string $environmentName
* *
* @return string[] * @return string[]
*/ */
public function getBranchesByEnvironment($environment_name) public function getBranchesByEnvironment($environmentName)
{ {
$branches = []; $branches = [];
$environments = $this->getEnvironmentsObjects(); $environments = $this->getEnvironmentsObjects();
foreach($environments['items'] as $environment) { foreach($environments['items'] as $environment) {
/** @var Environment $environment */ /** @var Environment $environment */
if ($environment_name == $environment->getName()) { if ($environmentName == $environment->getName()) {
return $environment->getBranches(); return $environment->getBranches();
} }
} }

View file

@ -9,7 +9,7 @@ use PHPCensor\Plugin;
/** /**
* Behat BDD Plugin * Behat BDD Plugin
* *
* @author Dan Cryer <dan@block8.co.uk> * @author Dan Cryer <dan@block8.co.uk>
*/ */
class Behat extends Plugin class Behat extends Plugin
@ -50,7 +50,7 @@ class Behat extends Plugin
*/ */
public function execute() public function execute()
{ {
$current_dir = getcwd(); $currentDir = getcwd();
chdir($this->builder->buildPath); chdir($this->builder->buildPath);
$behat = $this->executable; $behat = $this->executable;
@ -62,7 +62,7 @@ class Behat extends Plugin
} }
$success = $this->builder->executeCommand($behat . ' %s', $this->features); $success = $this->builder->executeCommand($behat . ' %s', $this->features);
chdir($current_dir); chdir($currentDir);
list($errorCount, $data) = $this->parseBehatOutput(); list($errorCount, $data) = $this->parseBehatOutput();

View file

@ -130,26 +130,26 @@ class Mysql extends Plugin
/** /**
* Builds the MySQL import command required to import/execute the specified file * Builds the MySQL import command required to import/execute the specified file
* *
* @param string $import_file Path to file, relative to the build root * @param string $importFile Path to file, relative to the build root
* @param string $database If specified, this database is selected before execution * @param string $database If specified, this database is selected before execution
* *
* @return string * @return string
*/ */
protected function getImportCommand($import_file, $database = null) protected function getImportCommand($importFile, $database = null)
{ {
$decompression = [ $decompression = [
'bz2' => '| bzip2 --decompress', 'bz2' => '| bzip2 --decompress',
'gz' => '| gzip --decompress', 'gz' => '| gzip --decompress',
]; ];
$extension = strtolower(pathinfo($import_file, PATHINFO_EXTENSION)); $extension = strtolower(pathinfo($importFile, PATHINFO_EXTENSION));
$decompressionCmd = ''; $decompressionCmd = '';
if (array_key_exists($extension, $decompression)) { if (array_key_exists($extension, $decompression)) {
$decompressionCmd = $decompression[$extension]; $decompressionCmd = $decompression[$extension];
} }
$args = [ $args = [
':import_file' => escapeshellarg($import_file), ':import_file' => escapeshellarg($importFile),
':decomp_cmd' => $decompressionCmd, ':decomp_cmd' => $decompressionCmd,
':host' => escapeshellarg($this->host), ':host' => escapeshellarg($this->host),
':user' => escapeshellarg($this->user), ':user' => escapeshellarg($this->user),

View file

@ -97,8 +97,8 @@ class PhpSpec extends Plugin
$error['message'] = (String)$attr['message']; $error['message'] = (String)$attr['message'];
} }
foreach ($child->xpath('system-err') as $system_err) { foreach ($child->xpath('system-err') as $systemError) {
$error['raw'] = (String)$system_err; $error['raw'] = (String)$systemError;
} }
$case['error'] = $error; $case['error'] = $error;

View file

@ -35,12 +35,12 @@ class PhpTalLint extends Plugin
/** /**
* @var int * @var int
*/ */
protected $allowed_warnings; protected $allowedWarnings;
/** /**
* @var int * @var int
*/ */
protected $allowed_errors; protected $allowedErrors;
/** /**
* @var array The results of the lint scan * @var array The results of the lint scan
@ -58,8 +58,8 @@ class PhpTalLint extends Plugin
$this->suffixes = ['zpt']; $this->suffixes = ['zpt'];
$this->ignore = $this->builder->ignore; $this->ignore = $this->builder->ignore;
$this->allowed_warnings = 0; $this->allowedWarnings = 0;
$this->allowed_errors = 0; $this->allowedErrors = 0;
if (!empty($options['directory'])) { if (!empty($options['directory'])) {
$this->directories = [$options['directory']]; $this->directories = [$options['directory']];
@ -102,11 +102,11 @@ class PhpTalLint extends Plugin
$success = true; $success = true;
if ($this->allowed_warnings != -1 && $warnings > $this->allowed_warnings) { if ($this->allowedWarnings != -1 && $warnings > $this->allowedWarnings) {
$success = false; $success = false;
} }
if ($this->allowed_errors != -1 && $errors > $this->allowed_errors) { if ($this->allowedErrors != -1 && $errors > $this->allowedErrors) {
$success = false; $success = false;
} }

View file

@ -39,39 +39,39 @@ class Codeception implements ParserInterface
$this->results = new \SimpleXMLElement($this->resultsXml); $this->results = new \SimpleXMLElement($this->resultsXml);
// calculate total results // calculate total results
foreach ($this->results->testsuite as $test_suite) { foreach ($this->results->testsuite as $testSuite) {
$this->totalTests += (int)$test_suite['tests']; $this->totalTests += (int)$testSuite['tests'];
$this->totalTimeTaken += (float)$test_suite['time']; $this->totalTimeTaken += (float)$testSuite['time'];
$this->totalFailures += (int)$test_suite['failures']; $this->totalFailures += (int)$testSuite['failures'];
$this->totalErrors += (int)$test_suite['errors']; $this->totalErrors += (int)$testSuite['errors'];
foreach ($test_suite->testcase as $test_case) { foreach ($testSuite->testcase as $testCase) {
$test_result = [ $testResult = [
'suite' => (string)$test_suite['name'], 'suite' => (string)$testSuite['name'],
'file' => str_replace($this->builder->buildPath, '/', (string) $test_case['file']), 'file' => str_replace($this->builder->buildPath, '/', (string) $testCase['file']),
'name' => (string)$test_case['name'], 'name' => (string)$testCase['name'],
'feature' => (string)$test_case['feature'], 'feature' => (string)$testCase['feature'],
'assertions' => (int)$test_case['assertions'], 'assertions' => (int)$testCase['assertions'],
'time' => (float)$test_case['time'] 'time' => (float)$testCase['time']
]; ];
if (isset($test_case['class'])) { if (isset($testCase['class'])) {
$test_result['class'] = (string) $test_case['class']; $testResult['class'] = (string) $testCase['class'];
} }
// PHPUnit testcases does not have feature field. Use class::method instead // PHPUnit testcases does not have feature field. Use class::method instead
if (!$test_result['feature']) { if (!$testResult['feature']) {
$test_result['feature'] = sprintf('%s::%s', $test_result['class'], $test_result['name']); $testResult['feature'] = sprintf('%s::%s', $testResult['class'], $testResult['name']);
} }
if (isset($test_case->failure) || isset($test_case->error)) { if (isset($testCase->failure) || isset($testCase->error)) {
$test_result['pass'] = false; $testResult['pass'] = false;
$test_result['message'] = isset($test_case->failure) ? (string)$test_case->failure : (string)$test_case->error; $testResult['message'] = isset($testCase->failure) ? (string)$testCase->failure : (string)$testCase->error;
} else { } else {
$test_result['pass'] = true; $testResult['pass'] = true;
} }
$rtn[] = $test_result; $rtn[] = $testResult;
} }
} }

View file

@ -140,10 +140,10 @@ class XMPP extends Plugin
/* /*
* Try to build conf file * Try to build conf file
*/ */
$config_file = $this->builder->buildPath . '/.sendxmpprc'; $configFile = $this->builder->buildPath . '/.sendxmpprc';
if (is_null($this->findConfigFile())) { if (is_null($this->findConfigFile())) {
file_put_contents($config_file, $this->getConfigFormat()); file_put_contents($configFile, $this->getConfigFormat());
chmod($config_file, 0600); chmod($configFile, 0600);
} }
/* /*
@ -154,8 +154,8 @@ class XMPP extends Plugin
$tls = ' -t'; $tls = ' -t';
} }
$message_file = $this->builder->buildPath . '/' . uniqid('xmppmessage'); $messageFile = $this->builder->buildPath . '/' . uniqid('xmppmessage');
if ($this->buildMessage($message_file) === false) { if ($this->buildMessage($messageFile) === false) {
return false; return false;
} }
@ -165,23 +165,23 @@ class XMPP extends Plugin
$cmd = $sendxmpp . "%s -f %s -m %s %s"; $cmd = $sendxmpp . "%s -f %s -m %s %s";
$recipients = implode(' ', $this->recipients); $recipients = implode(' ', $this->recipients);
$success = $this->builder->executeCommand($cmd, $tls, $config_file, $message_file, $recipients); $success = $this->builder->executeCommand($cmd, $tls, $configFile, $messageFile, $recipients);
print $this->builder->getLastOutput(); print $this->builder->getLastOutput();
/* /*
* Remove temp message file * Remove temp message file
*/ */
$this->builder->executeCommand("rm -rf ".$message_file); $this->builder->executeCommand("rm -rf ".$messageFile);
return $success; return $success;
} }
/** /**
* @param $message_file * @param $messageFile
* @return int * @return int
*/ */
protected function buildMessage($message_file) protected function buildMessage($messageFile)
{ {
if ($this->build->isSuccessful()) { if ($this->build->isSuccessful()) {
$message = "✔ [".$this->build->getProjectTitle()."] Build #" . $this->build->getId()." successful"; $message = "✔ [".$this->build->getProjectTitle()."] Build #" . $this->build->getId()." successful";
@ -191,6 +191,6 @@ class XMPP extends Plugin
$message .= ' ('.strftime($this->dateFormat).')'; $message .= ' ('.strftime($this->dateFormat).')';
return file_put_contents($message_file, $message); return file_put_contents($messageFile, $message);
} }
} }

View file

@ -144,19 +144,19 @@ abstract class Store
$data = $obj->getDataArray(); $data = $obj->getDataArray();
$modified = ($saveAllColumns) ? array_keys($data) : $obj->getModified(); $modified = ($saveAllColumns) ? array_keys($data) : $obj->getModified();
$updates = []; $updates = [];
$update_params = []; $updateParams = [];
foreach ($modified as $key) { foreach ($modified as $key) {
$updates[] = $key . ' = :' . $key; $updates[] = $key . ' = :' . $key;
$update_params[] = [$key, $data[$key]]; $updateParams[] = [$key, $data[$key]];
} }
if (count($updates)) { if (count($updates)) {
$qs = 'UPDATE {{' . $this->tableName . '}} SET ' . implode(', ', $updates) . ' WHERE {{' . $this->primaryKey . '}} = :primaryKey'; $qs = 'UPDATE {{' . $this->tableName . '}} SET ' . implode(', ', $updates) . ' WHERE {{' . $this->primaryKey . '}} = :primaryKey';
$q = Database::getConnection('write')->prepareCommon($qs); $q = Database::getConnection('write')->prepareCommon($qs);
foreach ($update_params as $update_param) { foreach ($updateParams as $updateParam) {
$q->bindValue(':' . $update_param[0], $update_param[1]); $q->bindValue(':' . $updateParam[0], $updateParam[1]);
} }
$q->bindValue(':primaryKey', $data[$this->primaryKey]); $q->bindValue(':primaryKey', $data[$this->primaryKey]);

View file

@ -239,12 +239,12 @@ class BuildStore extends Store
/** /**
* Return an array of the latest builds for all projects. * Return an array of the latest builds for all projects.
* *
* @param integer $limit_by_project * @param integer $limitByProject
* @param integer $limit_all * @param integer $limitAll
* *
* @return array * @return array
*/ */
public function getAllProjectsLatestBuilds($limit_by_project = 5, $limit_all = 10) public function getAllProjectsLatestBuilds($limitByProject = 5, $limitAll = 10)
{ {
// don't fetch log field - contain many data // don't fetch log field - contain many data
$query = ' $query = '
@ -275,40 +275,40 @@ class BuildStore extends Store
$projects = []; $projects = [];
$latest = []; $latest = [];
foreach ($res as $item) { foreach ($res as $item) {
$project_id = $item['project_id']; $projectId = $item['project_id'];
$environment = $item['environment']; $environment = $item['environment'];
if (empty($projects[$project_id])) { if (empty($projects[$projectId])) {
$projects[$project_id] = []; $projects[$projectId] = [];
} }
if (empty($projects[$project_id][$environment])) { if (empty($projects[$projectId][$environment])) {
$projects[$project_id][$environment] = [ $projects[$projectId][$environment] = [
'latest' => [], 'latest' => [],
'success' => null, 'success' => null,
'failed' => null, 'failed' => null,
]; ];
} }
$build = null; $build = null;
if (count($projects[$project_id][$environment]['latest']) < $limit_by_project) { if (count($projects[$projectId][$environment]['latest']) < $limitByProject) {
$build = new Build($item); $build = new Build($item);
$projects[$project_id][$environment]['latest'][] = $build; $projects[$projectId][$environment]['latest'][] = $build;
} }
if (count($latest) < $limit_all) { if (count($latest) < $limitAll) {
if (is_null($build)) { if (is_null($build)) {
$build = new Build($item); $build = new Build($item);
} }
$latest[] = $build; $latest[] = $build;
} }
if (empty($projects[$project_id][$environment]['success']) && Build::STATUS_SUCCESS === $item['status']) { if (empty($projects[$projectId][$environment]['success']) && Build::STATUS_SUCCESS === $item['status']) {
if (is_null($build)) { if (is_null($build)) {
$build = new Build($item); $build = new Build($item);
} }
$projects[$project_id][$environment]['success'] = $build; $projects[$projectId][$environment]['success'] = $build;
} }
if (empty($projects[$project_id][$environment]['failed']) && Build::STATUS_FAILED === $item['status']) { if (empty($projects[$projectId][$environment]['failed']) && Build::STATUS_FAILED === $item['status']) {
if (is_null($build)) { if (is_null($build)) {
$build = new Build($item); $build = new Build($item);
} }
$projects[$project_id][$environment]['failed'] = $build; $projects[$projectId][$environment]['failed'] = $build;
} }
} }