1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-01 02:40:24 +02:00

Fix type errors, thanks phan

This commit is contained in:
Jordi Boggiano
2016-09-25 22:00:12 +02:00
parent 85792c8818
commit 5ce1c921ad
16 changed files with 56 additions and 68 deletions

View File

@@ -188,7 +188,7 @@ class ErrorHandler
*/
public function handleFatalError()
{
$this->reservedMemory = null;
$this->reservedMemory = '';
$lastError = error_get_last();
if ($lastError && in_array($lastError['type'], self::$fatalErrors, true)) {

View File

@@ -174,16 +174,14 @@ class ChromePHPHandler extends AbstractProcessingHandler
/**
* Verifies if the headers are accepted by the current user agent
*
* @return Boolean
*/
protected function headersAccepted()
protected function headersAccepted(): bool
{
if (empty($_SERVER['HTTP_USER_AGENT'])) {
return false;
}
return preg_match(self::USER_AGENT_REGEX, $_SERVER['HTTP_USER_AGENT']);
return preg_match(self::USER_AGENT_REGEX, $_SERVER['HTTP_USER_AGENT']) === 1;
}
/**

View File

@@ -61,7 +61,7 @@ class FirePHPHandler extends AbstractProcessingHandler
* @param string $message Log message
* @return array Complete header string ready for the client as key and message as value
*/
protected function createHeader(array $meta, $message)
protected function createHeader(array $meta, string $message): array
{
$header = sprintf('%s-%s', self::HEADER_PREFIX, join('-', $meta));
@@ -72,10 +72,8 @@ class FirePHPHandler extends AbstractProcessingHandler
* Creates message header from record
*
* @see createHeader()
* @param array $record
* @return string
*/
protected function createRecordHeader(array $record)
protected function createRecordHeader(array $record): array
{
// Wildfire is extensible to support multiple protocols & plugins in a single request,
// but we're not taking advantage of that (yet), so we're using "1" for simplicity's sake.

View File

@@ -64,8 +64,6 @@ class FlowdockHandler extends SocketHandler
/**
* Gets the default formatter.
*
* @return FormatterInterface
*/
protected function getDefaultFormatter(): FormatterInterface
{

View File

@@ -25,7 +25,7 @@ use Monolog\Formatter\FormatterInterface;
class GelfHandler extends AbstractProcessingHandler
{
/**
* @var Publisher the publisher object that sends the message to the server
* @var PublisherInterface|null the publisher object that sends the message to the server
*/
protected $publisher;

View File

@@ -29,7 +29,7 @@ class ProcessHandler extends AbstractProcessingHandler
/**
* Holds the process to receive data on its STDIN.
*
* @var resource
* @var resource|bool|null
*/
private $process;
@@ -58,20 +58,20 @@ class ProcessHandler extends AbstractProcessingHandler
];
/**
* @param int $command Command for the process to start. Absolute paths are recommended,
* @param string $command Command for the process to start. Absolute paths are recommended,
* especially if you do not use the $cwd parameter.
* @param bool|int $level The minimum logging level at which this handler will be triggered.
* @param bool|true $bubble Whether the messages that are handled can bubble up the stack or not.
* @param string|null $cwd "Current working directory" (CWD) for the process to be executed in.
* @param string|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 string $cwd "Current working directory" (CWD) for the process to be executed in.
* @throws \InvalidArgumentException
*/
public function __construct($command, $level = Logger::DEBUG, $bubble = true, $cwd = null)
public function __construct(string $command, $level = Logger::DEBUG, bool $bubble = true, string $cwd = null)
{
if (empty($command) || is_string($command) === false) {
if ($command === '') {
throw new \InvalidArgumentException('The command argument must be a non-empty string.');
}
if ($cwd !== null && (empty($cwd) || is_string($cwd) === false)) {
throw new \InvalidArgumentException('The optional CWD argument must be a non-empty string, if any.');
if ($cwd === '') {
throw new \InvalidArgumentException('The optional CWD argument must be a non-empty string or null.');
}
parent::__construct($level, $bubble);

View File

@@ -133,6 +133,7 @@ class RavenHandler extends AbstractProcessingHandler
*/
protected function write(array $record)
{
/** @var bool|null|array This is false, unless set below to null or an array of data, when we read the current user context */
$previousUserContext = false;
$options = [];
$options['level'] = $this->logLevels[$record['level']];
@@ -186,7 +187,8 @@ class RavenHandler extends AbstractProcessingHandler
$this->ravenClient->captureMessage($record['formatted'], [], $options);
}
if ($previousUserContext !== false) {
// restore the user context if it was modified
if (!is_bool($previousUserContext)) {
$this->ravenClient->user_context($previousUserContext);
}
}

View File

@@ -37,9 +37,9 @@ class RedisHandler extends AbstractProcessingHandler
* @param string $key The key name to push records to
* @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 $capSize Number of entries to limit list size to
* @param int $capSize Number of entries to limit list size to, 0 = unlimited
*/
public function __construct($redis, $key, $level = Logger::DEBUG, $bubble = true, $capSize = false)
public function __construct($redis, string $key, $level = Logger::DEBUG, bool $bubble = true, int $capSize = 0)
{
if (!(($redis instanceof \Predis\Client) || ($redis instanceof \Redis))) {
throw new \InvalidArgumentException('Predis\Client or Redis instance required');

View File

@@ -23,8 +23,11 @@ class SocketHandler extends AbstractProcessingHandler
{
private $connectionString;
private $connectionTimeout;
/** @var resource|null */
private $resource;
/** @var float */
private $timeout = 0;
/** @var float */
private $writingTimeout = 10;
private $lastSentBytes = null;
private $persistent = false;
@@ -149,20 +152,16 @@ class SocketHandler extends AbstractProcessingHandler
/**
* Get current connection timeout setting
*
* @return float
*/
public function getConnectionTimeout()
public function getConnectionTimeout(): float
{
return $this->connectionTimeout;
}
/**
* Get current in-transfer timeout
*
* @return float
*/
public function getTimeout()
public function getTimeout(): float
{
return $this->timeout;
}
@@ -172,7 +171,7 @@ class SocketHandler extends AbstractProcessingHandler
*
* @return float
*/
public function getWritingTimeout()
public function getWritingTimeout(): float
{
return $this->writingTimeout;
}

View File

@@ -22,8 +22,10 @@ use Monolog\Logger;
*/
class StreamHandler extends AbstractProcessingHandler
{
/** @var resource|null */
protected $stream;
protected $url;
/** @var string|null */
private $errorMessage;
protected $filePermission;
protected $useLocking;

View File

@@ -17,6 +17,8 @@ class UdpSocket
protected $ip;
protected $port;
/** @var resource|null */
protected $socket;
public function __construct($ip, $port = 514)

View File

@@ -393,13 +393,12 @@ class Logger implements LoggerInterface
* @param mixed $level The log level
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function log($level, $message, array $context = [])
{
$level = static::toMonologLevel($level);
return $this->addRecord($level, (string) $message, $context);
$this->addRecord($level, (string) $message, $context);
}
/**
@@ -409,11 +408,10 @@ class Logger implements LoggerInterface
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function debug($message, array $context = [])
{
return $this->addRecord(static::DEBUG, (string) $message, $context);
$this->addRecord(static::DEBUG, (string) $message, $context);
}
/**
@@ -423,11 +421,10 @@ class Logger implements LoggerInterface
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function info($message, array $context = [])
{
return $this->addRecord(static::INFO, (string) $message, $context);
$this->addRecord(static::INFO, (string) $message, $context);
}
/**
@@ -437,11 +434,10 @@ class Logger implements LoggerInterface
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function notice($message, array $context = [])
{
return $this->addRecord(static::NOTICE, (string) $message, $context);
$this->addRecord(static::NOTICE, (string) $message, $context);
}
/**
@@ -451,11 +447,10 @@ class Logger implements LoggerInterface
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function warning($message, array $context = [])
{
return $this->addRecord(static::WARNING, (string) $message, $context);
$this->addRecord(static::WARNING, (string) $message, $context);
}
/**
@@ -465,11 +460,10 @@ class Logger implements LoggerInterface
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function error($message, array $context = [])
{
return $this->addRecord(static::ERROR, (string) $message, $context);
$this->addRecord(static::ERROR, (string) $message, $context);
}
/**
@@ -479,11 +473,10 @@ class Logger implements LoggerInterface
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function critical($message, array $context = [])
{
return $this->addRecord(static::CRITICAL, (string) $message, $context);
$this->addRecord(static::CRITICAL, (string) $message, $context);
}
/**
@@ -493,11 +486,10 @@ class Logger implements LoggerInterface
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function alert($message, array $context = [])
{
return $this->addRecord(static::ALERT, (string) $message, $context);
$this->addRecord(static::ALERT, (string) $message, $context);
}
/**
@@ -507,11 +499,10 @@ class Logger implements LoggerInterface
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function emergency($message, array $context = [])
{
return $this->addRecord(static::EMERGENCY, (string) $message, $context);
$this->addRecord(static::EMERGENCY, (string) $message, $context);
}
/**

View File

@@ -28,7 +28,7 @@ class MercurialProcessor
$this->level = Logger::toMonologLevel($level);
}
public function __invoke(array $record): arra
public function __invoke(array $record): array
{
// return if the level is not high enough
if ($record['level'] < $this->level) {

View File

@@ -13,6 +13,7 @@ namespace Monolog\Test;
use Monolog\Logger;
use Monolog\DateTimeImmutable;
use Monolog\Formatter\FormatterInterface;
/**
* Lets you easily generate log records and a dummy formatter for testing purposes
@@ -51,12 +52,9 @@ class TestCase extends \PHPUnit_Framework_TestCase
];
}
/**
* @return Monolog\Formatter\FormatterInterface
*/
protected function getIdentityFormatter()
protected function getIdentityFormatter(): FormatterInterface
{
$formatter = $this->createMock('Monolog\\Formatter\\FormatterInterface');
$formatter = $this->createMock(FormatterInterface::class);
$formatter->expects($this->any())
->method('format')
->will($this->returnCallback(function ($record) {

View File

@@ -63,10 +63,10 @@ class ProcessHandlerTest extends TestCase
public function invalidCommandProvider()
{
return [
[1337],
[''],
[null],
[fopen('php://input', 'r')],
[1337, 'TypeError'],
['', 'InvalidArgumentException'],
[null, 'TypeError'],
[fopen('php://input', 'r'), 'TypeError'],
];
}
@@ -75,9 +75,9 @@ class ProcessHandlerTest extends TestCase
* @param mixed $invalidCommand
* @covers Monolog\Handler\ProcessHandler::guardAgainstInvalidCommand
*/
public function testConstructWithInvalidCommandThrowsInvalidArgumentException($invalidCommand)
public function testConstructWithInvalidCommandThrowsInvalidArgumentException($invalidCommand, $expectedExcep)
{
$this->setExpectedException('\InvalidArgumentException');
$this->setExpectedException($expectedExcep);
new ProcessHandler($invalidCommand, Logger::DEBUG);
}
@@ -89,9 +89,9 @@ class ProcessHandlerTest extends TestCase
public function invalidCwdProvider()
{
return [
[1337],
[''],
[fopen('php://input', 'r')],
[1337, 'TypeError'],
['', 'InvalidArgumentException'],
[fopen('php://input', 'r'), 'TypeError'],
];
}
@@ -100,9 +100,9 @@ class ProcessHandlerTest extends TestCase
* @param mixed $invalidCwd
* @covers Monolog\Handler\ProcessHandler::guardAgainstInvalidCwd
*/
public function testConstructWithInvalidCwdThrowsInvalidArgumentException($invalidCwd)
public function testConstructWithInvalidCwdThrowsInvalidArgumentException($invalidCwd, $expectedExcep)
{
$this->setExpectedException('\InvalidArgumentException');
$this->setExpectedException($expectedExcep);
new ProcessHandler(self::DUMMY_COMMAND, Logger::DEBUG, true, $invalidCwd);
}

View File

@@ -96,7 +96,7 @@ class LoggerTest extends \PHPUnit_Framework_TestCase
$logger->pushHandler($handler->reveal());
$this->assertTrue($logger->warning('test'));
$this->assertTrue($logger->addRecord(Logger::WARNING, 'test'));
}
/**
@@ -112,7 +112,7 @@ class LoggerTest extends \PHPUnit_Framework_TestCase
$logger->pushHandler($handler->reveal());
$this->assertFalse($logger->warning('test'));
$this->assertFalse($logger->addRecord(Logger::WARNING, 'test'));
}
public function testHandlersInCtor()