From efbf2650bbc444457719a60e38744ac71ea8a5f4 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Mon, 8 May 2017 12:32:01 +0700 Subject: [PATCH] Code style fixes. --- src/PHPCensor/Command/CreateAdminCommand.php | 1 - src/PHPCensor/Model/Project.php | 2 +- src/PHPCensor/Plugin/HipchatNotify.php | 1 - src/PHPCensor/Store/BuildErrorWriter.php | 238 +++++++++---------- src/PHPCensor/Store/BuildStore.php | 2 +- 5 files changed, 121 insertions(+), 123 deletions(-) diff --git a/src/PHPCensor/Command/CreateAdminCommand.php b/src/PHPCensor/Command/CreateAdminCommand.php index fa2cd88b..a7f14929 100644 --- a/src/PHPCensor/Command/CreateAdminCommand.php +++ b/src/PHPCensor/Command/CreateAdminCommand.php @@ -3,7 +3,6 @@ namespace PHPCensor\Command; use PHPCensor\Service\UserService; -use b8\Store\Factory; use PHPCensor\Store\UserStore; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; diff --git a/src/PHPCensor/Model/Project.php b/src/PHPCensor/Model/Project.php index 95c80d7a..219691ac 100644 --- a/src/PHPCensor/Model/Project.php +++ b/src/PHPCensor/Model/Project.php @@ -889,7 +889,7 @@ class Project extends Model $default_branch = ($branch == $this->getBranch()); foreach($environments['items'] as $environment) { /** @var Environment $environment */ - if ($default_branch or in_array($branch, $environment->getBranches())) { + if ($default_branch || in_array($branch, $environment->getBranches())) { $environments_names[] = $environment->getName(); } } diff --git a/src/PHPCensor/Plugin/HipchatNotify.php b/src/PHPCensor/Plugin/HipchatNotify.php index 9b2cb710..b855ddff 100644 --- a/src/PHPCensor/Plugin/HipchatNotify.php +++ b/src/PHPCensor/Plugin/HipchatNotify.php @@ -3,7 +3,6 @@ namespace PHPCensor\Plugin; use PHPCensor\Builder; -use PHPCensor\Helper\Lang; use PHPCensor\Model\Build; use PHPCensor\Plugin; use HipChat\HipChat; diff --git a/src/PHPCensor/Store/BuildErrorWriter.php b/src/PHPCensor/Store/BuildErrorWriter.php index 3fef1e57..a58cbaae 100644 --- a/src/PHPCensor/Store/BuildErrorWriter.php +++ b/src/PHPCensor/Store/BuildErrorWriter.php @@ -1,119 +1,119 @@ -build_id = $build_id; - $this->buffer_size = max((int) $buffer_size, 1); - } - - /** - * Destructor - */ - public function __destruct() - { - $this->flush(); - } - - /** - * Write error - * - * @param string $plugin - * @param string $message - * @param int $severity - * @param string $file - * @param int $line_start - * @param int $line_end - * @param \DateTime $created_date - */ - public function write($plugin, $message, $severity, $file = null, $line_start = null, $line_end = null, $created_date = null) - { - if (is_null($created_date)) { - $created_date = new \DateTime(); - } - $this->errors[] = array( - 'plugin' => (string)$plugin, - 'message' => (string)$message, - 'severity' => (int)$severity, - 'file' => !is_null($file) ? (string)$file : null, - 'line_start' => !is_null($line_start) ? (int)$line_start : null, - 'line_end' => !is_null($line_end) ? (int)$line_end : null, - 'created_date' => $created_date->format('Y-m-d H:i:s'), - ); - if (count($this->errors) >= $this->buffer_size) { - $this->flush(); - } - } - - /** - * Flush buffer - */ - public function flush() - { - if (empty($this->errors)) { - return; - } - - $insert_values_placeholders = []; - $insert_values_data = []; - foreach ($this->errors as $i => $error) { - $insert_values_placeholders[] = '( - :build_id' . $i . ', - :plugin' . $i . ', - :file' . $i . ', - :line_start' . $i . ', - :line_end' . $i . ', - :severity' . $i . ', - :message' . $i . ', - :created_date' . $i . ' - )'; - $insert_values_data['build_id' . $i] = $this->build_id; - $insert_values_data['plugin' . $i] = $error['plugin']; - $insert_values_data['file' . $i] = $error['file']; - $insert_values_data['line_start' . $i] = $error['line_start']; - $insert_values_data['line_end' . $i] = $error['line_end']; - $insert_values_data['severity' . $i] = $error['severity']; - $insert_values_data['message' . $i] = $error['message']; - $insert_values_data['created_date' . $i] = $error['created_date']; - } - $query = ' - INSERT INTO {{build_error}} ( - {{build_id}}, - {{plugin}}, - {{file}}, - {{line_start}}, - {{line_end}}, - {{severity}}, - {{message}}, - {{created_date}} - ) - VALUES ' . join(', ', $insert_values_placeholders) . ' - '; - $stmt = Database::getConnection('write')->prepareCommon($query); - $stmt->execute($insert_values_data); - $this->errors = []; - } -} +build_id = $build_id; + $this->buffer_size = max((int) $buffer_size, 1); + } + + /** + * Destructor + */ + public function __destruct() + { + $this->flush(); + } + + /** + * Write error + * + * @param string $plugin + * @param string $message + * @param int $severity + * @param string $file + * @param int $line_start + * @param int $line_end + * @param \DateTime $created_date + */ + public function write($plugin, $message, $severity, $file = null, $line_start = null, $line_end = null, $created_date = null) + { + if (is_null($created_date)) { + $created_date = new \DateTime(); + } + $this->errors[] = array( + 'plugin' => (string)$plugin, + 'message' => (string)$message, + 'severity' => (int)$severity, + 'file' => !is_null($file) ? (string)$file : null, + 'line_start' => !is_null($line_start) ? (int)$line_start : null, + 'line_end' => !is_null($line_end) ? (int)$line_end : null, + 'created_date' => $created_date->format('Y-m-d H:i:s'), + ); + if (count($this->errors) >= $this->buffer_size) { + $this->flush(); + } + } + + /** + * Flush buffer + */ + public function flush() + { + if (empty($this->errors)) { + return; + } + + $insert_values_placeholders = []; + $insert_values_data = []; + foreach ($this->errors as $i => $error) { + $insert_values_placeholders[] = '( + :build_id' . $i . ', + :plugin' . $i . ', + :file' . $i . ', + :line_start' . $i . ', + :line_end' . $i . ', + :severity' . $i . ', + :message' . $i . ', + :created_date' . $i . ' + )'; + $insert_values_data['build_id' . $i] = $this->build_id; + $insert_values_data['plugin' . $i] = $error['plugin']; + $insert_values_data['file' . $i] = $error['file']; + $insert_values_data['line_start' . $i] = $error['line_start']; + $insert_values_data['line_end' . $i] = $error['line_end']; + $insert_values_data['severity' . $i] = $error['severity']; + $insert_values_data['message' . $i] = $error['message']; + $insert_values_data['created_date' . $i] = $error['created_date']; + } + $query = ' + INSERT INTO {{build_error}} ( + {{build_id}}, + {{plugin}}, + {{file}}, + {{line_start}}, + {{line_end}}, + {{severity}}, + {{message}}, + {{created_date}} + ) + VALUES ' . join(', ', $insert_values_placeholders) . ' + '; + $stmt = Database::getConnection('write')->prepareCommon($query); + $stmt->execute($insert_values_data); + $this->errors = []; + } +} diff --git a/src/PHPCensor/Store/BuildStore.php b/src/PHPCensor/Store/BuildStore.php index 9c1e1751..15c0a82d 100644 --- a/src/PHPCensor/Store/BuildStore.php +++ b/src/PHPCensor/Store/BuildStore.php @@ -328,7 +328,7 @@ class BuildStore extends Store $stmt->bindValue(':id', $build->getId(), \PDO::PARAM_INT); $stmt->bindValue(':status_current', $build->getStatus(), \PDO::PARAM_INT); $stmt->bindValue(':status_new', $status, \PDO::PARAM_INT); - return ($stmt->execute() and ($stmt->rowCount() == 1)); + return ($stmt->execute() && ($stmt->rowCount() == 1)); } catch (\Exception $e) { return false; }