From b60e278cf9cd7693fd240196eda5b76d8fd615ed Mon Sep 17 00:00:00 2001 From: "steve.brazier" Date: Thu, 27 Feb 2014 14:23:51 +0000 Subject: [PATCH] psr2 tidy up of logging code. --- PHPCI/Logging/BuildDBLogHandler.php | 4 ++-- PHPCI/Logging/BuildLogger.php | 4 ++-- PHPCI/Logging/LoggedBuildContextTidier.php | 4 ++-- PHPCI/Logging/LoggerConfig.php | 25 +++++++++++----------- PHPCI/Logging/OutputLogHandler.php | 4 ++-- Tests/PHPCI/Logging/LoggerConfigTest.php | 2 +- 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/PHPCI/Logging/BuildDBLogHandler.php b/PHPCI/Logging/BuildDBLogHandler.php index 91196dc3..a877fe50 100644 --- a/PHPCI/Logging/BuildDBLogHandler.php +++ b/PHPCI/Logging/BuildDBLogHandler.php @@ -16,7 +16,7 @@ class BuildDBLogHandler extends AbstractProcessingHandler protected $logValue; - function __construct( + public function __construct( Build $build, $level = LogLevel::INFO, $bubble = true @@ -35,4 +35,4 @@ class BuildDBLogHandler extends AbstractProcessingHandler $this->logValue .= $message . PHP_EOL; $this->build->setLog($this->logValue); } -} \ No newline at end of file +} diff --git a/PHPCI/Logging/BuildLogger.php b/PHPCI/Logging/BuildLogger.php index f3f5ebce..f652ba01 100644 --- a/PHPCI/Logging/BuildLogger.php +++ b/PHPCI/Logging/BuildLogger.php @@ -20,7 +20,7 @@ class BuildLogger implements LoggerAwareInterface */ protected $build; - function __construct(LoggerInterface $logger = null, Build $build) + public function __construct(LoggerInterface $logger, Build $build) { $this->logger = $logger; $this->build = $build; @@ -93,4 +93,4 @@ class BuildLogger implements LoggerAwareInterface { $this->logger = $logger; } -} \ No newline at end of file +} diff --git a/PHPCI/Logging/LoggedBuildContextTidier.php b/PHPCI/Logging/LoggedBuildContextTidier.php index aa852ae5..2b70f443 100644 --- a/PHPCI/Logging/LoggedBuildContextTidier.php +++ b/PHPCI/Logging/LoggedBuildContextTidier.php @@ -6,7 +6,7 @@ use PHPCI\Model\Build; class LoggedBuildContextTidier { - function __invoke() + public function __invoke() { return $this->tidyLoggedBuildContext(func_get_arg(0)); } @@ -29,4 +29,4 @@ class LoggedBuildContextTidier } return $logRecord; } -} \ No newline at end of file +} diff --git a/PHPCI/Logging/LoggerConfig.php b/PHPCI/Logging/LoggerConfig.php index 5c579f6e..13b1f5e7 100644 --- a/PHPCI/Logging/LoggerConfig.php +++ b/PHPCI/Logging/LoggerConfig.php @@ -6,9 +6,10 @@ namespace PHPCI\Logging; use Monolog\Logger; -class LoggerConfig { +class LoggerConfig +{ - const KEY_AlwaysLoaded = "_"; + const KEY_ALWAYS_LOADED = "_"; private $config; @@ -23,8 +24,7 @@ class LoggerConfig { { if (file_exists($filePath)) { $configArray = require($filePath); - } - else { + } else { $configArray = array(); } return new self($configArray); @@ -36,7 +36,8 @@ class LoggerConfig { * array of LogHandlers. * @param array $configArray */ - function __construct(array $configArray = array()) { + public function __construct(array $configArray = array()) + { $this->config = $configArray; } @@ -46,13 +47,15 @@ class LoggerConfig { * @param $name * @return Logger */ - public function getFor($name) { - $handlers = $this->getHandlers(self::KEY_AlwaysLoaded); + public function getFor($name) + { + $handlers = $this->getHandlers(self::KEY_ALWAYS_LOADED); $handlers = array_merge($handlers, $this->getHandlers($name)); return new Logger($name, $handlers); } - protected function getHandlers($key) { + protected function getHandlers($key) + { $handlers = array(); // They key is expected to either be an array or @@ -60,12 +63,10 @@ class LoggerConfig { if (isset($this->config[$key])) { if (is_callable($this->config[$key])) { $handlers = call_user_func($this->config[$key]); - } - elseif(is_array($this->config[$key])) { + } elseif (is_array($this->config[$key])) { $handlers = $this->config[$key]; } } return $handlers; } - -} \ No newline at end of file +} diff --git a/PHPCI/Logging/OutputLogHandler.php b/PHPCI/Logging/OutputLogHandler.php index a136ad0f..d573b03d 100644 --- a/PHPCI/Logging/OutputLogHandler.php +++ b/PHPCI/Logging/OutputLogHandler.php @@ -14,7 +14,7 @@ class OutputLogHandler extends AbstractProcessingHandler */ protected $output; - function __construct( + public function __construct( OutputInterface $output, $level = LogLevel::INFO, $bubble = true @@ -30,4 +30,4 @@ class OutputLogHandler extends AbstractProcessingHandler } -} \ No newline at end of file +} diff --git a/Tests/PHPCI/Logging/LoggerConfigTest.php b/Tests/PHPCI/Logging/LoggerConfigTest.php index 68f28f3a..f1e78245 100644 --- a/Tests/PHPCI/Logging/LoggerConfigTest.php +++ b/Tests/PHPCI/Logging/LoggerConfigTest.php @@ -24,7 +24,7 @@ class LoggerConfigTest extends \PHPUnit_Framework_TestCase { $expectedHandler = new \Monolog\Handler\NullHandler(); $config = new LoggerConfig(array( - LoggerConfig::KEY_AlwaysLoaded => function() use ($expectedHandler) { + LoggerConfig::KEY_ALWAYS_LOADED => function() use ($expectedHandler) { return array($expectedHandler); } ));