diff --git a/.php_cs b/.php_cs index 34eb329f..6fc3ca2e 100644 --- a/.php_cs +++ b/.php_cs @@ -24,14 +24,13 @@ return PhpCsFixer\Config::create() '@PSR2' => true, // some rules disabled as long as 1.x branch is maintained 'binary_operator_spaces' => array( - 'align_double_arrow' => null, - 'align_equals' => null, + 'default' => null, ), - 'blank_line_before_return' => true, - 'cast_spaces' => true, - 'header_comment' => array('header' => $header), + 'blank_line_before_statement' => ['statements' => ['continue', 'declare', 'return', 'throw', 'try']], + 'cast_spaces' => ['space' => 'single'], + 'header_comment' => ['header' => $header], 'include' => true, - 'method_separation' => true, + 'class_attributes_separation' => ['elements' => ['method']], 'no_blank_lines_after_class_opening' => true, 'no_blank_lines_after_phpdoc' => true, 'no_empty_statement' => true, diff --git a/src/Monolog/ErrorHandler.php b/src/Monolog/ErrorHandler.php index 9a1e3004..d32c25d5 100644 --- a/src/Monolog/ErrorHandler.php +++ b/src/Monolog/ErrorHandler.php @@ -105,7 +105,7 @@ class ErrorHandler } /** - * @param string|null $level a LogLevel::* constant, null to use the default LogLevel::ALERT or false to disable fatal error handling + * @param string|null $level a LogLevel::* constant, null to use the default LogLevel::ALERT or false to disable fatal error handling * @param int $reservedMemorySize Amount of KBs to reserve in memory so that it can be freed when handling fatal errors giving Monolog some room in memory to get its job done */ public function registerFatalHandler($level = null, int $reservedMemorySize = 20): self diff --git a/src/Monolog/Handler/AbstractSyslogHandler.php b/src/Monolog/Handler/AbstractSyslogHandler.php index 95589e3e..0c692aa9 100644 --- a/src/Monolog/Handler/AbstractSyslogHandler.php +++ b/src/Monolog/Handler/AbstractSyslogHandler.php @@ -55,8 +55,8 @@ abstract class AbstractSyslogHandler extends AbstractProcessingHandler /** * @param mixed $facility - * @param int $level The minimum logging level at which this handler will be triggered - * @param bool $bubble Whether the messages that are handled can bubble up the stack or not + * @param int $level The minimum logging level at which this handler will be triggered + * @param bool $bubble Whether the messages that are handled can bubble up the stack or not */ public function __construct($facility = LOG_USER, $level = Logger::DEBUG, $bubble = true) { diff --git a/src/Monolog/Handler/BrowserConsoleHandler.php b/src/Monolog/Handler/BrowserConsoleHandler.php index 681fe0cf..7774adef 100755 --- a/src/Monolog/Handler/BrowserConsoleHandler.php +++ b/src/Monolog/Handler/BrowserConsoleHandler.php @@ -141,7 +141,8 @@ class BrowserConsoleHandler extends AbstractProcessingHandler if (empty($context) && empty($extra)) { $script[] = static::call_array('log', static::handleStyles($record['formatted'])); } else { - $script = array_merge($script, + $script = array_merge( + $script, [static::call_array('groupCollapsed', static::handleStyles($record['formatted']))], $context, $extra, diff --git a/src/Monolog/Handler/ChromePHPHandler.php b/src/Monolog/Handler/ChromePHPHandler.php index 4cd76bf8..9c1ca523 100644 --- a/src/Monolog/Handler/ChromePHPHandler.php +++ b/src/Monolog/Handler/ChromePHPHandler.php @@ -24,7 +24,6 @@ use Monolog\Logger; */ class ChromePHPHandler extends AbstractProcessingHandler { - use WebRequestRecognizerTrait; /** diff --git a/src/Monolog/Handler/CubeHandler.php b/src/Monolog/Handler/CubeHandler.php index ab6e007e..82b16921 100644 --- a/src/Monolog/Handler/CubeHandler.php +++ b/src/Monolog/Handler/CubeHandler.php @@ -46,7 +46,8 @@ class CubeHandler extends AbstractProcessingHandler if (!in_array($urlInfo['scheme'], $this->acceptedSchemes)) { throw new \UnexpectedValueException( 'Invalid protocol (' . $urlInfo['scheme'] . ').' - . ' Valid options are ' . implode(', ', $this->acceptedSchemes)); + . ' Valid options are ' . implode(', ', $this->acceptedSchemes) + ); } $this->scheme = $urlInfo['scheme']; diff --git a/src/Monolog/Handler/ElasticSearchHandler.php b/src/Monolog/Handler/ElasticSearchHandler.php index 9b9f485f..b7dc5676 100644 --- a/src/Monolog/Handler/ElasticSearchHandler.php +++ b/src/Monolog/Handler/ElasticSearchHandler.php @@ -81,6 +81,7 @@ class ElasticSearchHandler extends AbstractProcessingHandler if ($formatter instanceof ElasticaFormatter) { return parent::setFormatter($formatter); } + throw new \InvalidArgumentException('ElasticSearchHandler is only compatible with ElasticaFormatter'); } diff --git a/src/Monolog/Handler/ErrorLogHandler.php b/src/Monolog/Handler/ErrorLogHandler.php index cc7dbb10..3108aed7 100644 --- a/src/Monolog/Handler/ErrorLogHandler.php +++ b/src/Monolog/Handler/ErrorLogHandler.php @@ -40,6 +40,7 @@ class ErrorLogHandler extends AbstractProcessingHandler if (false === in_array($messageType, self::getAvailableTypes(), true)) { $message = sprintf('The given message type "%s" is not supported', print_r($messageType, true)); + throw new \InvalidArgumentException($message); } @@ -73,9 +74,10 @@ class ErrorLogHandler extends AbstractProcessingHandler { if (!$this->expandNewlines) { error_log((string) $record['formatted'], $this->messageType); + return; - } - + } + $lines = preg_split('{[\r\n]+}', (string) $record['formatted']); foreach ($lines as $line) { error_log($line, $this->messageType); diff --git a/src/Monolog/Handler/FingersCrossed/ActivationStrategyInterface.php b/src/Monolog/Handler/FingersCrossed/ActivationStrategyInterface.php index d4a8a51b..b73854ad 100644 --- a/src/Monolog/Handler/FingersCrossed/ActivationStrategyInterface.php +++ b/src/Monolog/Handler/FingersCrossed/ActivationStrategyInterface.php @@ -21,7 +21,7 @@ interface ActivationStrategyInterface /** * Returns whether the given record activates the handler. * - * @param array $record + * @param array $record * @return bool */ public function isHandlerActivated(array $record); diff --git a/src/Monolog/Handler/FirePHPHandler.php b/src/Monolog/Handler/FirePHPHandler.php index d92e2db5..8f5c0c69 100644 --- a/src/Monolog/Handler/FirePHPHandler.php +++ b/src/Monolog/Handler/FirePHPHandler.php @@ -21,7 +21,6 @@ use Monolog\Formatter\FormatterInterface; */ class FirePHPHandler extends AbstractProcessingHandler { - use WebRequestRecognizerTrait; /** diff --git a/src/Monolog/Handler/HandlerInterface.php b/src/Monolog/Handler/HandlerInterface.php index 90e8e16f..8ad7e38f 100644 --- a/src/Monolog/Handler/HandlerInterface.php +++ b/src/Monolog/Handler/HandlerInterface.php @@ -43,9 +43,9 @@ interface HandlerInterface * Unless the bubbling is interrupted (by returning true), the Logger class will keep on * calling further handlers in the stack with a given log record. * - * @param array $record The record to handle - * @return bool true means that this handler handled the record, and that bubbling is not permitted. - * false means the record was either not processed or that this handler allows bubbling. + * @param array $record The record to handle + * @return bool true means that this handler handled the record, and that bubbling is not permitted. + * false means the record was either not processed or that this handler allows bubbling. */ public function handle(array $record): bool; diff --git a/src/Monolog/Handler/InsightOpsHandler.php b/src/Monolog/Handler/InsightOpsHandler.php index 8da3a638..bd6dfe60 100644 --- a/src/Monolog/Handler/InsightOpsHandler.php +++ b/src/Monolog/Handler/InsightOpsHandler.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ - namespace Monolog\Handler; +namespace Monolog\Handler; - use Monolog\Logger; +use Monolog\Logger; -/** + /** * Inspired on LogEntriesHandler. * * @author Robert Kaufmann III diff --git a/src/Monolog/Handler/RollbarHandler.php b/src/Monolog/Handler/RollbarHandler.php index f330eeaa..2f35093c 100644 --- a/src/Monolog/Handler/RollbarHandler.php +++ b/src/Monolog/Handler/RollbarHandler.php @@ -19,7 +19,7 @@ use Monolog\Logger; * Sends errors to Rollbar * * If the context data contains a `payload` key, that is used as an array - * of payload options to RollbarLogger's log method. + * of payload options to RollbarLogger's log method. * * Rollbar's context info will contain the context + extra keys from the log record * merged, and then on top of that a few keys: @@ -59,9 +59,9 @@ class RollbarHandler extends AbstractProcessingHandler protected $initialized = false; /** - * @param RollbarLogger $rollbarLogger RollbarLogger object constructed with valid token - * @param int $level The minimum logging level at which this handler will be triggered - * @param bool $bubble Whether the messages that are handled can bubble up the stack or not + * @param RollbarLogger $rollbarLogger RollbarLogger object constructed with valid token + * @param int $level The minimum logging level at which this handler will be triggered + * @param bool $bubble Whether the messages that are handled can bubble up the stack or not */ public function __construct(RollbarLogger $rollbarLogger, $level = Logger::ERROR, $bubble = true) { @@ -96,7 +96,7 @@ class RollbarHandler extends AbstractProcessingHandler } else { $toLog = $record['message']; } - + $this->rollbarLogger->log($context['level'], $toLog, $context); $this->hasRecords = true; diff --git a/src/Monolog/Handler/SlackWebhookHandler.php b/src/Monolog/Handler/SlackWebhookHandler.php index 7576cacb..2904db3f 100644 --- a/src/Monolog/Handler/SlackWebhookHandler.php +++ b/src/Monolog/Handler/SlackWebhookHandler.php @@ -90,7 +90,7 @@ class SlackWebhookHandler extends AbstractProcessingHandler CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => array('Content-type: application/json'), - CURLOPT_POSTFIELDS => $postString + CURLOPT_POSTFIELDS => $postString, ); if (defined('CURLOPT_SAFE_UPLOAD')) { $options[CURLOPT_SAFE_UPLOAD] = true; diff --git a/src/Monolog/Handler/SqsHandler.php b/src/Monolog/Handler/SqsHandler.php index 3b2a713d..ed595c71 100644 --- a/src/Monolog/Handler/SqsHandler.php +++ b/src/Monolog/Handler/SqsHandler.php @@ -21,7 +21,6 @@ use Monolog\Logger; */ class SqsHandler extends AbstractProcessingHandler { - /** 256 KB in bytes - maximum message size in SQS */ const MAX_MESSAGE_SIZE = 262144; /** 100 KB in bytes - head message size for new error log */ diff --git a/src/Monolog/Handler/StreamHandler.php b/src/Monolog/Handler/StreamHandler.php index 13361c88..6631ef4e 100644 --- a/src/Monolog/Handler/StreamHandler.php +++ b/src/Monolog/Handler/StreamHandler.php @@ -106,6 +106,7 @@ class StreamHandler extends AbstractProcessingHandler restore_error_handler(); if (!is_resource($this->stream)) { $this->stream = null; + throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened: '.$this->errorMessage, $this->url)); } } diff --git a/src/Monolog/Handler/TestHandler.php b/src/Monolog/Handler/TestHandler.php index b176721d..55c48334 100644 --- a/src/Monolog/Handler/TestHandler.php +++ b/src/Monolog/Handler/TestHandler.php @@ -101,6 +101,7 @@ class TestHandler extends AbstractProcessingHandler if (isset($record['context']) && $rec['context'] !== $record['context']) { return false; } + return true; }, $level); } diff --git a/src/Monolog/Handler/WebRequestRecognizerTrait.php b/src/Monolog/Handler/WebRequestRecognizerTrait.php index fb137561..c8183528 100644 --- a/src/Monolog/Handler/WebRequestRecognizerTrait.php +++ b/src/Monolog/Handler/WebRequestRecognizerTrait.php @@ -1,10 +1,18 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Monolog\Handler; trait WebRequestRecognizerTrait { - /** * Checks if PHP's serving a web request * @return bool diff --git a/src/Monolog/Logger.php b/src/Monolog/Logger.php index 7a2dcf1c..a22bf7ec 100644 --- a/src/Monolog/Logger.php +++ b/src/Monolog/Logger.php @@ -276,10 +276,10 @@ class Logger implements LoggerInterface /** * Adds a log record. * - * @param int $level The logging level - * @param string $message The log message - * @param array $context The log context - * @return bool Whether the record has been processed + * @param int $level The logging level + * @param string $message The log message + * @param array $context The log context + * @return bool Whether the record has been processed */ public function addRecord(int $level, string $message, array $context = []): bool { diff --git a/src/Monolog/Processor/HostnameProcessor.php b/src/Monolog/Processor/HostnameProcessor.php index 23ddaf48..fef40849 100644 --- a/src/Monolog/Processor/HostnameProcessor.php +++ b/src/Monolog/Processor/HostnameProcessor.php @@ -11,8 +11,6 @@ namespace Monolog\Processor; -use Monolog\Logger; - /** * Injects value of gethostname in all records */ diff --git a/src/Monolog/Processor/IntrospectionProcessor.php b/src/Monolog/Processor/IntrospectionProcessor.php index e1b5d3a3..5fe5b2aa 100644 --- a/src/Monolog/Processor/IntrospectionProcessor.php +++ b/src/Monolog/Processor/IntrospectionProcessor.php @@ -65,11 +65,13 @@ class IntrospectionProcessor foreach ($this->skipClassesPartials as $part) { if (strpos($trace[$i]['class'], $part) !== false) { $i++; + continue 2; } } } elseif (in_array($trace[$i]['function'], $this->skipFunctions)) { $i++; + continue; } diff --git a/src/Monolog/Processor/PsrLogMessageProcessor.php b/src/Monolog/Processor/PsrLogMessageProcessor.php index f845f883..7311c2be 100644 --- a/src/Monolog/Processor/PsrLogMessageProcessor.php +++ b/src/Monolog/Processor/PsrLogMessageProcessor.php @@ -28,8 +28,8 @@ class PsrLogMessageProcessor private $removeUsedContextFields; /** - * @param string $dateFormat The format of the timestamp: one supported by DateTime::format - * @param bool $removeUsedContextFields If set to true the fields interpolated into message gets unset + * @param string $dateFormat The format of the timestamp: one supported by DateTime::format + * @param bool $removeUsedContextFields If set to true the fields interpolated into message gets unset */ public function __construct(string $dateFormat = null, bool $removeUsedContextFields = false) { diff --git a/tests/Monolog/Formatter/GelfMessageFormatterTest.php b/tests/Monolog/Formatter/GelfMessageFormatterTest.php index 39eeaf70..012de3cd 100644 --- a/tests/Monolog/Formatter/GelfMessageFormatterTest.php +++ b/tests/Monolog/Formatter/GelfMessageFormatterTest.php @@ -234,7 +234,7 @@ class GelfMessageFormatterTest extends \PHPUnit\Framework\TestCase 'context' => array('exception' => str_repeat(' ', 32767 * 2)), 'datetime' => new \DateTime("@0"), 'extra' => array('key' => str_repeat(' ', 32767 * 2)), - 'message' => 'log' + 'message' => 'log', ); $message = $formatter->format($record); $messageArray = $message->toArray(); diff --git a/tests/Monolog/Handler/ElasticSearchHandlerTest.php b/tests/Monolog/Handler/ElasticSearchHandlerTest.php index e0e207db..7c92555a 100644 --- a/tests/Monolog/Handler/ElasticSearchHandlerTest.php +++ b/tests/Monolog/Handler/ElasticSearchHandlerTest.php @@ -183,6 +183,7 @@ class ElasticSearchHandlerTest extends TestCase $client = new Client(); $handler = new ElasticSearchHandler($client, $this->options); + try { $handler->handleBatch([$msg]); } catch (\RuntimeException $e) { diff --git a/tests/Monolog/Handler/FilterHandlerTest.php b/tests/Monolog/Handler/FilterHandlerTest.php index 0e64e769..b0072de0 100644 --- a/tests/Monolog/Handler/FilterHandlerTest.php +++ b/tests/Monolog/Handler/FilterHandlerTest.php @@ -146,7 +146,10 @@ class FilterHandlerTest extends TestCase $handler = new FilterHandler( function ($record, $handler) use ($test) { return $test; - }, Logger::INFO, Logger::NOTICE, false + }, + Logger::INFO, + Logger::NOTICE, + false ); $handler->handle($this->getRecord(Logger::DEBUG)); $handler->handle($this->getRecord(Logger::INFO)); diff --git a/tests/Monolog/Handler/InsightOpsHandlerTest.php b/tests/Monolog/Handler/InsightOpsHandlerTest.php index a0338b66..209858ae 100644 --- a/tests/Monolog/Handler/InsightOpsHandlerTest.php +++ b/tests/Monolog/Handler/InsightOpsHandlerTest.php @@ -1,4 +1,4 @@ - * @author Gabriel Machado */ @@ -62,7 +62,6 @@ class InsightOpsHandlerTest extends TestCase ->setConstructorArgs($args) ->getMock(); - $reflectionProperty = new \ReflectionProperty('\Monolog\Handler\SocketHandler', 'connectionString'); $reflectionProperty->setAccessible(true); $reflectionProperty->setValue($this->handler, 'localhost:1234'); diff --git a/tests/Monolog/Handler/RollbarHandlerTest.php b/tests/Monolog/Handler/RollbarHandlerTest.php index 96d8a30a..67a0eb68 100644 --- a/tests/Monolog/Handler/RollbarHandlerTest.php +++ b/tests/Monolog/Handler/RollbarHandlerTest.php @@ -59,9 +59,9 @@ class RollbarHandlerTest extends TestCase { $config = array( 'access_token' => 'ad865e76e7fb496fab096ac07b1dbabb', - 'environment' => 'test' + 'environment' => 'test', ); - + $this->rollbarLogger = $this->getMockBuilder(RollbarLogger::class) ->setConstructorArgs(array($config)) ->setMethods(array('log')) diff --git a/tests/Monolog/Handler/RotatingFileHandlerTest.php b/tests/Monolog/Handler/RotatingFileHandlerTest.php index 9454b0f5..7d3e8c4f 100644 --- a/tests/Monolog/Handler/RotatingFileHandlerTest.php +++ b/tests/Monolog/Handler/RotatingFileHandlerTest.php @@ -102,10 +102,10 @@ class RotatingFileHandlerTest extends TestCase $dayCallback = function ($ago) use ($now) { return $now + 86400 * $ago; }; - $monthCallback = function($ago) { + $monthCallback = function ($ago) { return gmmktime(0, 0, 0, (int) (date('n') + $ago), 1, (int) date('Y')); }; - $yearCallback = function($ago) { + $yearCallback = function ($ago) { return gmmktime(0, 0, 0, 1, 1, (int) (date('Y') + $ago)); }; @@ -216,7 +216,6 @@ class RotatingFileHandlerTest extends TestCase public function rotationWhenSimilarFilesExistTests() { - return array( 'Rotation is triggered when the file of the current day is not present but similar exists' => array(RotatingFileHandler::FILE_PER_DAY), diff --git a/tests/Monolog/Handler/TestHandlerTest.php b/tests/Monolog/Handler/TestHandlerTest.php index 9214983f..cc8e60ff 100644 --- a/tests/Monolog/Handler/TestHandlerTest.php +++ b/tests/Monolog/Handler/TestHandlerTest.php @@ -54,7 +54,8 @@ class TestHandlerTest extends TestCase $this->assertEquals([$record], $records); } - public function testHandlerAssertEmptyContext() { + public function testHandlerAssertEmptyContext() + { $handler = new TestHandler; $record = $this->getRecord(Logger::WARNING, 'test', []); $this->assertFalse($handler->hasWarning([ @@ -71,18 +72,19 @@ class TestHandlerTest extends TestCase $this->assertFalse($handler->hasWarning([ 'message' => 'test', 'context' => [ - 'foo' => 'bar' + 'foo' => 'bar', ], ])); } - public function testHandlerAssertNonEmptyContext() { + public function testHandlerAssertNonEmptyContext() + { $handler = new TestHandler; $record = $this->getRecord(Logger::WARNING, 'test', ['foo' => 'bar']); $this->assertFalse($handler->hasWarning([ 'message' => 'test', 'context' => [ - 'foo' => 'bar' + 'foo' => 'bar', ], ])); @@ -91,7 +93,7 @@ class TestHandlerTest extends TestCase $this->assertTrue($handler->hasWarning([ 'message' => 'test', 'context' => [ - 'foo' => 'bar' + 'foo' => 'bar', ], ])); $this->assertFalse($handler->hasWarning([