1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-08 14:16:42 +02:00

Move phpdoc to native types

This commit is contained in:
Jordi Boggiano
2022-04-20 09:21:58 +02:00
parent 2695fa86cd
commit 7952a83e0c
117 changed files with 432 additions and 766 deletions

View File

@@ -21,10 +21,7 @@ use DateTimeZone;
*/
class DateTimeImmutable extends \DateTimeImmutable implements \JsonSerializable
{
/**
* @var bool
*/
private $useMicroseconds;
private bool $useMicroseconds;
public function __construct(bool $useMicroseconds, ?DateTimeZone $timezone = null)
{

View File

@@ -11,6 +11,7 @@
namespace Monolog;
use Closure;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
@@ -25,31 +26,24 @@ use Psr\Log\LogLevel;
*/
class ErrorHandler
{
/** @var LoggerInterface */
private $logger;
private LoggerInterface $logger;
/** @var ?callable */
private $previousExceptionHandler = null;
private Closure|null $previousExceptionHandler = null;
/** @var array<class-string, LogLevel::*> an array of class name to LogLevel::* constant mapping */
private $uncaughtExceptionLevelMap = [];
private array $uncaughtExceptionLevelMap = [];
/** @var callable|true|null */
private $previousErrorHandler = null;
/** @var array<int, LogLevel::*> an array of E_* constant to LogLevel::* constant mapping */
private $errorLevelMap = [];
/** @var bool */
private $handleOnlyReportedErrors = true;
private array $errorLevelMap = [];
private bool $handleOnlyReportedErrors = true;
/** @var bool */
private $hasFatalErrorHandler = false;
/** @var LogLevel::* */
private $fatalLevel = LogLevel::ALERT;
/** @var ?string */
private $reservedMemory = null;
/** @var ?mixed */
private $lastFatalTrace;
/** @var int[] */
private static $fatalErrors = [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR];
private bool $hasFatalErrorHandler = false;
private string $fatalLevel = LogLevel::ALERT;
private string|null $reservedMemory = null;
/** @var mixed|null */
private $lastFatalTrace = null;
private const FATAL_ERRORS = [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR];
public function __construct(LoggerInterface $logger)
{
@@ -99,7 +93,7 @@ class ErrorHandler
}
}
if ($callPrevious && $prev) {
$this->previousExceptionHandler = $prev;
$this->previousExceptionHandler = $prev(...);
}
return $this;
@@ -213,7 +207,7 @@ class ErrorHandler
}
// fatal error codes are ignored if a fatal error handler is present as well to avoid duplicate log entries
if (!$this->hasFatalErrorHandler || !in_array($code, self::$fatalErrors, true)) {
if (!$this->hasFatalErrorHandler || !in_array($code, self::FATAL_ERRORS, true)) {
$level = $this->errorLevelMap[$code] ?? LogLevel::CRITICAL;
$this->logger->log($level, self::codeToString($code).': '.$message, ['code' => $code, 'message' => $message, 'file' => $file, 'line' => $line]);
} else {
@@ -239,7 +233,7 @@ class ErrorHandler
$this->reservedMemory = '';
$lastError = error_get_last();
if ($lastError && in_array($lastError['type'], self::$fatalErrors, true)) {
if ($lastError && in_array($lastError['type'], self::FATAL_ERRORS, true)) {
$this->logger->log(
$this->fatalLevel,
'Fatal Error ('.self::codeToString($lastError['type']).'): '.$lastError['message'],
@@ -254,10 +248,7 @@ class ErrorHandler
}
}
/**
* @param int $code
*/
private static function codeToString($code): string
private static function codeToString(int $code): string
{
return match ($code) {
E_ERROR => 'E_ERROR',

View File

@@ -41,7 +41,7 @@ class ChromePHPFormatter implements FormatterInterface
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function format(LogRecord $record)
{
@@ -72,7 +72,7 @@ class ChromePHPFormatter implements FormatterInterface
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function formatBatch(array $records)
{

View File

@@ -24,7 +24,7 @@ class ElasticaFormatter extends NormalizerFormatter
/**
* @var string Elastic search index name
*/
protected $index;
protected string $index;
/**
* @var ?string Elastic search document type
@@ -45,7 +45,7 @@ class ElasticaFormatter extends NormalizerFormatter
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function format(LogRecord $record)
{

View File

@@ -24,12 +24,12 @@ class ElasticsearchFormatter extends NormalizerFormatter
/**
* @var string Elasticsearch index name
*/
protected $index;
protected string $index;
/**
* @var string Elasticsearch record type
*/
protected $type;
protected string $type;
/**
* @param string $index Elasticsearch index name
@@ -45,7 +45,7 @@ class ElasticsearchFormatter extends NormalizerFormatter
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function format(LogRecord $record)
{

View File

@@ -20,15 +20,9 @@ use Monolog\LogRecord;
*/
class FlowdockFormatter implements FormatterInterface
{
/**
* @var string
*/
private $source;
private string $source;
/**
* @var string
*/
private $sourceEmail;
private string $sourceEmail;
public function __construct(string $source, string $sourceEmail)
{
@@ -37,7 +31,7 @@ class FlowdockFormatter implements FormatterInterface
}
/**
* {@inheritDoc}
* @inheritDoc
*
* @return mixed[]
*/
@@ -71,7 +65,7 @@ class FlowdockFormatter implements FormatterInterface
}
/**
* {@inheritDoc}
* @inheritDoc
*
* @return mixed[][]
*/

View File

@@ -40,7 +40,7 @@ class FluentdFormatter implements FormatterInterface
/**
* @var bool $levelTag should message level be a part of the fluentd tag
*/
protected $levelTag = false;
protected bool $levelTag = false;
public function __construct(bool $levelTag = false)
{

View File

@@ -29,22 +29,22 @@ class GelfMessageFormatter extends NormalizerFormatter
/**
* @var string the name of the system for the Gelf log message
*/
protected $systemName;
protected string $systemName;
/**
* @var string a prefix for 'extra' fields from the Monolog record (optional)
*/
protected $extraPrefix;
protected string $extraPrefix;
/**
* @var string a prefix for 'context' fields from the Monolog record (optional)
*/
protected $contextPrefix;
protected string $contextPrefix;
/**
* @var int max length per field
*/
protected $maxLength;
protected int $maxLength;
/**
* Translates Monolog log levels to Graylog2 log priorities.
@@ -79,7 +79,7 @@ class GelfMessageFormatter extends NormalizerFormatter
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function format(LogRecord $record): Message
{

View File

@@ -69,7 +69,7 @@ class JsonFormatter extends NormalizerFormatter
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function format(LogRecord $record): string
{
@@ -94,7 +94,7 @@ class JsonFormatter extends NormalizerFormatter
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function formatBatch(array $records): string
{
@@ -104,8 +104,6 @@ class JsonFormatter extends NormalizerFormatter
};
}
/**
*/
public function includeStacktraces(bool $include = true): self
{
$this->includeStacktraces = $include;
@@ -183,7 +181,7 @@ class JsonFormatter extends NormalizerFormatter
* Normalizes given exception with or without its own stack trace based on
* `includeStacktraces` property.
*
* {@inheritDoc}
* @inheritDoc
*/
protected function normalizeException(Throwable $e, int $depth = 0): array
{

View File

@@ -26,14 +26,10 @@ class LineFormatter extends NormalizerFormatter
{
public const SIMPLE_FORMAT = "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n";
/** @var string */
protected $format;
/** @var bool */
protected $allowInlineLineBreaks;
/** @var bool */
protected $ignoreEmptyContextAndExtra;
/** @var bool */
protected $includeStacktraces;
protected string $format;
protected bool $allowInlineLineBreaks;
protected bool $ignoreEmptyContextAndExtra;
protected bool $includeStacktraces;
/**
* @param string|null $format The format of the message
@@ -74,7 +70,7 @@ class LineFormatter extends NormalizerFormatter
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function format(LogRecord $record): string
{

View File

@@ -22,15 +22,9 @@ class LogmaticFormatter extends JsonFormatter
{
protected const MARKERS = ["sourcecode", "php"];
/**
* @var string
*/
protected $hostname = '';
protected string $hostname = '';
/**
* @var string
*/
protected $appname = '';
protected string $appname = '';
public function setHostname(string $hostname): self
{

View File

@@ -26,22 +26,22 @@ class LogstashFormatter extends NormalizerFormatter
/**
* @var string the name of the system for the Logstash log message, used to fill the @source field
*/
protected $systemName;
protected string $systemName;
/**
* @var string an application name for the Logstash log message, used to fill the @type field
*/
protected $applicationName;
protected string $applicationName;
/**
* @var string the key for 'extra' fields from the Monolog record
*/
protected $extraKey;
protected string $extraKey;
/**
* @var string the key for 'context' fields from the Monolog record
*/
protected $contextKey;
protected string $contextKey;
/**
* @param string $applicationName The application that sends the data, used as the "type" field of logstash
@@ -61,7 +61,7 @@ class LogstashFormatter extends NormalizerFormatter
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function format(LogRecord $record): string
{

View File

@@ -23,12 +23,9 @@ use Monolog\LogRecord;
*/
class MongoDBFormatter implements FormatterInterface
{
/** @var bool */
private $exceptionTraceAsString;
/** @var int */
private $maxNestingLevel;
/** @var bool */
private $isLegacyMongoExt;
private bool $exceptionTraceAsString;
private int $maxNestingLevel;
private bool $isLegacyMongoExt;
/**
* @param int $maxNestingLevel 0 means infinite nesting, the $record itself is level 1, $record->context is 2
@@ -43,7 +40,7 @@ class MongoDBFormatter implements FormatterInterface
}
/**
* {@inheritDoc}
* @inheritDoc
*
* @return mixed[]
*/
@@ -56,7 +53,7 @@ class MongoDBFormatter implements FormatterInterface
}
/**
* {@inheritDoc}
* @inheritDoc
*
* @return array<mixed[]>
*/

View File

@@ -25,15 +25,11 @@ class NormalizerFormatter implements FormatterInterface
{
public const SIMPLE_DATE = "Y-m-d\TH:i:sP";
/** @var string */
protected $dateFormat;
/** @var int */
protected $maxNormalizeDepth = 9;
/** @var int */
protected $maxNormalizeItemCount = 1000;
protected string $dateFormat;
protected int $maxNormalizeDepth = 9;
protected int $maxNormalizeItemCount = 1000;
/** @var int */
private $jsonEncodeOptions = Utils::DEFAULT_JSON_FLAGS;
private int $jsonEncodeOptions = Utils::DEFAULT_JSON_FLAGS;
/**
* @param string|null $dateFormat The format of the timestamp: one supported by DateTime::format
@@ -47,7 +43,7 @@ class NormalizerFormatter implements FormatterInterface
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function format(LogRecord $record)
{
@@ -65,7 +61,7 @@ class NormalizerFormatter implements FormatterInterface
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function formatBatch(array $records)
{
@@ -277,10 +273,7 @@ class NormalizerFormatter implements FormatterInterface
return Utils::jsonEncode($data, $this->jsonEncodeOptions, $ignoreErrors);
}
/**
* @return string
*/
protected function formatDate(\DateTimeInterface $date)
protected function formatDate(\DateTimeInterface $date): string
{
// in case the date format isn't custom then we defer to the custom DateTimeImmutable
// formatting logic, which will pick the right format based on whether useMicroseconds is on

View File

@@ -22,7 +22,7 @@ use Monolog\LogRecord;
class ScalarFormatter extends NormalizerFormatter
{
/**
* {@inheritDoc}
* @inheritDoc
*
* @phpstan-return array<string, scalar|null> $record
*/

View File

@@ -54,7 +54,7 @@ class WildfireFormatter extends NormalizerFormatter
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function format(LogRecord $record): string
{
@@ -112,7 +112,7 @@ class WildfireFormatter extends NormalizerFormatter
}
/**
* {@inheritDoc}
* @inheritDoc
*
* @phpstan-return never
*/
@@ -122,7 +122,7 @@ class WildfireFormatter extends NormalizerFormatter
}
/**
* {@inheritDoc}
* @inheritDoc
*
* @return null|scalar|array<mixed[]|scalar|null>|object
*/

View File

@@ -26,8 +26,7 @@ use Monolog\LogRecord;
abstract class AbstractHandler extends Handler implements ResettableInterface
{
protected Level $level = Level::Debug;
/** @var bool */
protected $bubble = true;
protected bool $bubble = true;
/**
* @param int|string|Level|LevelName|LogLevel::* $level The minimum logging level at which this handler will be triggered
@@ -42,7 +41,7 @@ abstract class AbstractHandler extends Handler implements ResettableInterface
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function isHandling(LogRecord $record): bool
{
@@ -96,9 +95,9 @@ abstract class AbstractHandler extends Handler implements ResettableInterface
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function reset()
public function reset(): void
{
}
}

View File

@@ -27,7 +27,7 @@ abstract class AbstractProcessingHandler extends AbstractHandler implements Proc
use FormattableHandlerTrait;
/**
* {@inheritDoc}
* @inheritDoc
*/
public function handle(LogRecord $record): bool
{
@@ -51,10 +51,7 @@ abstract class AbstractProcessingHandler extends AbstractHandler implements Proc
*/
abstract protected function write(LogRecord $record): void;
/**
* @return void
*/
public function reset()
public function reset(): void
{
parent::reset();

View File

@@ -20,8 +20,7 @@ use Monolog\Formatter\LineFormatter;
*/
abstract class AbstractSyslogHandler extends AbstractProcessingHandler
{
/** @var int */
protected $facility;
protected int $facility;
/**
* Translates Monolog log levels to syslog log priorities.
@@ -44,7 +43,7 @@ abstract class AbstractSyslogHandler extends AbstractProcessingHandler
* List of valid log facility names.
* @var array<string, int>
*/
protected $facilities = [
protected array $facilities = [
'auth' => \LOG_AUTH,
'authpriv' => \LOG_AUTHPRIV,
'cron' => \LOG_CRON,
@@ -96,7 +95,7 @@ abstract class AbstractSyslogHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function getDefaultFormatter(): FormatterInterface
{

View File

@@ -26,10 +26,7 @@ class AmqpHandler extends AbstractProcessingHandler
*/
protected $exchange;
/**
* @var string
*/
protected $exchangeName;
protected string $exchangeName;
/**
* @param AMQPExchange|AMQPChannel $exchange AMQPExchange (php AMQP ext) or PHP AMQP lib channel, ready for use
@@ -50,7 +47,7 @@ class AmqpHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function write(LogRecord $record): void
{
@@ -77,7 +74,7 @@ class AmqpHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function handleBatch(array $records): void
{
@@ -127,7 +124,7 @@ class AmqpHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function getDefaultFormatter(): FormatterInterface
{

View File

@@ -37,7 +37,7 @@ class BrowserConsoleHandler extends AbstractProcessingHandler
protected const FORMAT_UNKNOWN = 'unknown';
/**
* {@inheritDoc}
* @inheritDoc
*
* Formatted output may contain some formatting markers to be transferred to `console.log` using the %c format.
*
@@ -51,7 +51,7 @@ class BrowserConsoleHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function write(LogRecord $record): void
{
@@ -91,7 +91,7 @@ class BrowserConsoleHandler extends AbstractProcessingHandler
self::resetStatic();
}
public function reset()
public function reset(): void
{
parent::reset();

View File

@@ -56,7 +56,7 @@ class BufferHandler extends AbstractHandler implements ProcessableHandlerInterfa
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function handle(LogRecord $record): bool
{
@@ -107,7 +107,7 @@ class BufferHandler extends AbstractHandler implements ProcessableHandlerInterfa
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function close(): void
{
@@ -125,7 +125,7 @@ class BufferHandler extends AbstractHandler implements ProcessableHandlerInterfa
$this->buffer = [];
}
public function reset()
public function reset(): void
{
$this->flush();
@@ -139,7 +139,7 @@ class BufferHandler extends AbstractHandler implements ProcessableHandlerInterfa
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function setFormatter(FormatterInterface $formatter): HandlerInterface
{
@@ -153,7 +153,7 @@ class BufferHandler extends AbstractHandler implements ProcessableHandlerInterfa
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function getFormatter(): FormatterInterface
{

View File

@@ -44,27 +44,23 @@ class ChromePHPHandler extends AbstractProcessingHandler
*/
protected const USER_AGENT_REGEX = '{\b(?:Chrome/\d+(?:\.\d+)*|HeadlessChrome|Firefox/(?:4[3-9]|[5-9]\d|\d{3,})(?:\.\d)*)\b}';
/** @var bool */
protected static $initialized = false;
protected static bool $initialized = false;
/**
* Tracks whether we sent too much data
*
* Chrome limits the headers to 4KB, so when we sent 3KB we stop sending
*
* @var bool
*/
protected static $overflowed = false;
protected static bool $overflowed = false;
/** @var mixed[] */
protected static $json = [
protected static array $json = [
'version' => self::VERSION,
'columns' => ['label', 'log', 'backtrace', 'type'],
'rows' => [],
];
/** @var bool */
protected static $sendHeaders = true;
protected static bool $sendHeaders = true;
public function __construct($level = Level::Debug, bool $bubble = true)
{
@@ -75,7 +71,7 @@ class ChromePHPHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function handleBatch(array $records): void
{
@@ -102,7 +98,7 @@ class ChromePHPHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function getDefaultFormatter(): FormatterInterface
{

View File

@@ -24,7 +24,7 @@ use Monolog\LogRecord;
class CouchDBHandler extends AbstractProcessingHandler
{
/** @var mixed[] */
private $options;
private array $options;
/**
* @param mixed[] $options
@@ -43,7 +43,7 @@ class CouchDBHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function write(LogRecord $record): void
{
@@ -69,7 +69,7 @@ class CouchDBHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function getDefaultFormatter(): FormatterInterface
{

View File

@@ -23,18 +23,13 @@ use Monolog\LogRecord;
*/
class CubeHandler extends AbstractProcessingHandler
{
/** @var \Socket|null */
private $udpConnection = null;
/** @var \CurlHandle|null */
private $httpConnection = null;
/** @var string */
private $scheme;
/** @var string */
private $host;
/** @var int */
private $port;
private ?\Socket $udpConnection = null;
private ?\CurlHandle $httpConnection = null;
private string $scheme;
private string $host;
private int $port;
/** @var string[] */
private $acceptedSchemes = ['http', 'udp'];
private array $acceptedSchemes = ['http', 'udp'];
/**
* Create a Cube handler
@@ -111,7 +106,7 @@ class CubeHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function write(LogRecord $record): void
{

View File

@@ -21,7 +21,7 @@ use CurlHandle;
final class Util
{
/** @var array<int> */
private static $retriableErrorCodes = [
private static array $retriableErrorCodes = [
CURLE_COULDNT_RESOLVE_HOST,
CURLE_COULDNT_CONNECT,
CURLE_HTTP_NOT_FOUND,
@@ -37,7 +37,7 @@ final class Util
* @param CurlHandle $ch curl handler
* @return bool|string @see curl_exec
*/
public static function execute($ch, int $retries = 5, bool $closeAfterDone = true)
public static function execute(CurlHandle $ch, int $retries = 5, bool $closeAfterDone = true)
{
while ($retries--) {
$curlResponse = curl_exec($ch);

View File

@@ -39,25 +39,13 @@ use Monolog\LogRecord;
*/
class DeduplicationHandler extends BufferHandler
{
/**
* @var string
*/
protected $deduplicationStore;
protected string $deduplicationStore;
/**
* @var Level
*/
protected $deduplicationLevel;
protected Level $deduplicationLevel;
/**
* @var int
*/
protected $time;
protected int $time;
/**
* @var bool
*/
private $gc = false;
private bool $gc = false;
/**
* @param HandlerInterface $handler Handler.

View File

@@ -24,8 +24,7 @@ use Monolog\LogRecord;
*/
class DoctrineCouchDBHandler extends AbstractProcessingHandler
{
/** @var CouchDBClient */
private $client;
private CouchDBClient $client;
public function __construct(CouchDBClient $client, $level = Level::Debug, bool $bubble = true)
{
@@ -34,7 +33,7 @@ class DoctrineCouchDBHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function write(LogRecord $record): void
{

View File

@@ -29,20 +29,11 @@ class DynamoDbHandler extends AbstractProcessingHandler
{
public const DATE_FORMAT = 'Y-m-d\TH:i:s.uO';
/**
* @var DynamoDbClient
*/
protected $client;
protected DynamoDbClient $client;
/**
* @var string
*/
protected $table;
protected string $table;
/**
* @var Marshaler
*/
protected $marshaler;
protected Marshaler $marshaler;
public function __construct(DynamoDbClient $client, string $table, $level = Level::Debug, bool $bubble = true)
{
@@ -55,7 +46,7 @@ class DynamoDbHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function write(LogRecord $record): void
{
@@ -80,7 +71,7 @@ class DynamoDbHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function getDefaultFormatter(): FormatterInterface
{

View File

@@ -37,15 +37,12 @@ use Monolog\LogRecord;
*/
class ElasticaHandler extends AbstractProcessingHandler
{
/**
* @var Client
*/
protected $client;
protected Client $client;
/**
* @var mixed[] Handler config options
*/
protected $options = [];
protected array $options = [];
/**
* @param Client $client Elastica Client object
@@ -66,7 +63,7 @@ class ElasticaHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function write(LogRecord $record): void
{
@@ -74,7 +71,7 @@ class ElasticaHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function setFormatter(FormatterInterface $formatter): HandlerInterface
{
@@ -94,7 +91,7 @@ class ElasticaHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function getDefaultFormatter(): FormatterInterface
{
@@ -102,7 +99,7 @@ class ElasticaHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function handleBatch(array $records): void
{

View File

@@ -44,15 +44,12 @@ use Monolog\LogRecord;
*/
class ElasticsearchHandler extends AbstractProcessingHandler
{
/**
* @var Client
*/
protected $client;
protected Client $client;
/**
* @var mixed[] Handler config options
*/
protected $options = [];
protected array $options = [];
/**
* @param Client $client Elasticsearch Client object
@@ -73,7 +70,7 @@ class ElasticsearchHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function write(LogRecord $record): void
{
@@ -81,7 +78,7 @@ class ElasticsearchHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function setFormatter(FormatterInterface $formatter): HandlerInterface
{
@@ -103,7 +100,7 @@ class ElasticsearchHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function getDefaultFormatter(): FormatterInterface
{
@@ -111,7 +108,7 @@ class ElasticsearchHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function handleBatch(array $records): void
{

View File

@@ -27,10 +27,8 @@ class ErrorLogHandler extends AbstractProcessingHandler
public const OPERATING_SYSTEM = 0;
public const SAPI = 4;
/** @var int */
protected $messageType;
/** @var bool */
protected $expandNewlines;
protected int $messageType;
protected bool $expandNewlines;
/**
* @param int $messageType Says where the error should go.
@@ -62,7 +60,7 @@ class ErrorLogHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function getDefaultFormatter(): FormatterInterface
{
@@ -70,7 +68,7 @@ class ErrorLogHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function write(LogRecord $record): void
{

View File

@@ -24,7 +24,7 @@ use Monolog\LogRecord;
class FallbackGroupHandler extends GroupHandler
{
/**
* {@inheritDoc}
* @inheritDoc
*/
public function handle(LogRecord $record): bool
{
@@ -44,7 +44,7 @@ class FallbackGroupHandler extends GroupHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function handleBatch(array $records): void
{

View File

@@ -49,10 +49,8 @@ class FilterHandler extends Handler implements ProcessableHandlerInterface, Rese
/**
* Whether the messages that are handled can bubble up the stack or not
*
* @var bool
*/
protected $bubble;
protected bool $bubble;
/**
* @phpstan-param (callable(LogRecord|null, HandlerInterface): HandlerInterface)|HandlerInterface $handler
@@ -109,7 +107,7 @@ class FilterHandler extends Handler implements ProcessableHandlerInterface, Rese
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function isHandling(LogRecord $record): bool
{
@@ -117,7 +115,7 @@ class FilterHandler extends Handler implements ProcessableHandlerInterface, Rese
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function handle(LogRecord $record): bool
{
@@ -135,7 +133,7 @@ class FilterHandler extends Handler implements ProcessableHandlerInterface, Rese
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function handleBatch(array $records): void
{
@@ -155,10 +153,8 @@ class FilterHandler extends Handler implements ProcessableHandlerInterface, Rese
* Return the nested handler
*
* If the handler was provided as a factory callable, this will trigger the handler's instantiation.
*
* @return HandlerInterface
*/
public function getHandler(LogRecord $record = null)
public function getHandler(LogRecord $record = null): HandlerInterface
{
if (!$this->handler instanceof HandlerInterface) {
$this->handler = ($this->handler)($record, $this);
@@ -171,7 +167,7 @@ class FilterHandler extends Handler implements ProcessableHandlerInterface, Rese
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function setFormatter(FormatterInterface $formatter): HandlerInterface
{
@@ -186,7 +182,7 @@ class FilterHandler extends Handler implements ProcessableHandlerInterface, Rese
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function getFormatter(): FormatterInterface
{
@@ -198,7 +194,7 @@ class FilterHandler extends Handler implements ProcessableHandlerInterface, Rese
throw new \UnexpectedValueException('The nested handler of type '.get_class($handler).' does not support formatters.');
}
public function reset()
public function reset(): void
{
$this->resetProcessors();

View File

@@ -46,19 +46,14 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa
* @phpstan-var (callable(LogRecord|null, HandlerInterface): HandlerInterface)|HandlerInterface
*/
protected $handler;
/** @var ActivationStrategyInterface */
protected $activationStrategy;
/** @var bool */
protected $buffering = true;
/** @var int */
protected $bufferSize;
protected ActivationStrategyInterface $activationStrategy;
protected bool $buffering = true;
protected int $bufferSize;
/** @var LogRecord[] */
protected $buffer = [];
/** @var bool */
protected $stopBuffering;
protected array $buffer = [];
protected bool $stopBuffering;
protected Level|null $passthruLevel = null;
/** @var bool */
protected $bubble;
protected bool $bubble;
/**
* @phpstan-param (callable(LogRecord|null, HandlerInterface): HandlerInterface)|HandlerInterface $handler
@@ -100,7 +95,7 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function isHandling(LogRecord $record): bool
{
@@ -121,7 +116,7 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function handle(LogRecord $record): bool
{
@@ -145,7 +140,7 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function close(): void
{
@@ -154,7 +149,7 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa
$this->getHandler()->close();
}
public function reset()
public function reset(): void
{
$this->flushBuffer();
@@ -199,10 +194,8 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa
* Return the nested handler
*
* If the handler was provided as a factory callable, this will trigger the handler's instantiation.
*
* @return HandlerInterface
*/
public function getHandler(LogRecord $record = null)
public function getHandler(LogRecord $record = null): HandlerInterface
{
if (!$this->handler instanceof HandlerInterface) {
$this->handler = ($this->handler)($record, $this);
@@ -215,7 +208,7 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function setFormatter(FormatterInterface $formatter): HandlerInterface
{
@@ -230,7 +223,7 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function getFormatter(): FormatterInterface
{

View File

@@ -46,18 +46,15 @@ class FirePHPHandler extends AbstractProcessingHandler
/**
* Whether or not Wildfire vendor-specific headers have been generated & sent yet
* @var bool
*/
protected static $initialized = false;
protected static bool $initialized = false;
/**
* Shared static message index between potentially multiple handlers
* @var int
*/
protected static $messageIndex = 1;
protected static int $messageIndex = 1;
/** @var bool */
protected static $sendHeaders = true;
protected static bool $sendHeaders = true;
/**
* Base header creation function used by init headers & record headers
@@ -96,7 +93,7 @@ class FirePHPHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function getDefaultFormatter(): FormatterInterface
{

View File

@@ -33,7 +33,7 @@ class FleepHookHandler extends SocketHandler
/**
* @var string Webhook token (specifies the conversation where logs are sent)
*/
protected $token;
protected string $token;
/**
* Construct a new Fleep.io Handler.
@@ -95,7 +95,7 @@ class FleepHookHandler extends SocketHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function generateDataStream(LogRecord $record): string
{

View File

@@ -30,10 +30,7 @@ use Monolog\LogRecord;
*/
class FlowdockHandler extends SocketHandler
{
/**
* @var string
*/
protected $apiToken;
protected string $apiToken;
/**
* @throws MissingExtensionException if OpenSSL is missing
@@ -66,7 +63,7 @@ class FlowdockHandler extends SocketHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function setFormatter(FormatterInterface $formatter): HandlerInterface
{
@@ -86,7 +83,7 @@ class FlowdockHandler extends SocketHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function write(LogRecord $record): void
{
@@ -96,7 +93,7 @@ class FlowdockHandler extends SocketHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function generateDataStream(LogRecord $record): string
{

View File

@@ -27,7 +27,7 @@ trait FormattableHandlerTrait
protected $formatter;
/**
* {@inheritDoc}
* @inheritDoc
*/
public function setFormatter(FormatterInterface $formatter): HandlerInterface
{
@@ -37,7 +37,7 @@ trait FormattableHandlerTrait
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function getFormatter(): FormatterInterface
{

View File

@@ -28,7 +28,7 @@ class GelfHandler extends AbstractProcessingHandler
/**
* @var PublisherInterface the publisher object that sends the message to the server
*/
protected $publisher;
protected PublisherInterface $publisher;
/**
* @param PublisherInterface $publisher a gelf publisher object
@@ -41,7 +41,7 @@ class GelfHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function write(LogRecord $record): void
{
@@ -49,7 +49,7 @@ class GelfHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function getDefaultFormatter(): FormatterInterface
{

View File

@@ -25,9 +25,8 @@ class GroupHandler extends Handler implements ProcessableHandlerInterface, Reset
use ProcessableHandlerTrait;
/** @var HandlerInterface[] */
protected $handlers;
/** @var bool */
protected $bubble;
protected array $handlers;
protected bool $bubble;
/**
* @param HandlerInterface[] $handlers Array of Handlers.
@@ -46,7 +45,7 @@ class GroupHandler extends Handler implements ProcessableHandlerInterface, Reset
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function isHandling(LogRecord $record): bool
{
@@ -60,7 +59,7 @@ class GroupHandler extends Handler implements ProcessableHandlerInterface, Reset
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function handle(LogRecord $record): bool
{
@@ -76,7 +75,7 @@ class GroupHandler extends Handler implements ProcessableHandlerInterface, Reset
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function handleBatch(array $records): void
{
@@ -93,7 +92,7 @@ class GroupHandler extends Handler implements ProcessableHandlerInterface, Reset
}
}
public function reset()
public function reset(): void
{
$this->resetProcessors();
@@ -114,7 +113,7 @@ class GroupHandler extends Handler implements ProcessableHandlerInterface, Reset
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function setFormatter(FormatterInterface $formatter): HandlerInterface
{

View File

@@ -19,7 +19,7 @@ namespace Monolog\Handler;
abstract class Handler implements HandlerInterface
{
/**
* {@inheritDoc}
* @inheritDoc
*/
public function handleBatch(array $records): void
{
@@ -29,7 +29,7 @@ abstract class Handler implements HandlerInterface
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function close(): void
{

View File

@@ -34,10 +34,7 @@ use Monolog\LogRecord;
*/
class HandlerWrapper implements HandlerInterface, ProcessableHandlerInterface, FormattableHandlerInterface, ResettableInterface
{
/**
* @var HandlerInterface
*/
protected $handler;
protected HandlerInterface $handler;
public function __construct(HandlerInterface $handler)
{
@@ -45,7 +42,7 @@ class HandlerWrapper implements HandlerInterface, ProcessableHandlerInterface, F
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function isHandling(LogRecord $record): bool
{
@@ -53,7 +50,7 @@ class HandlerWrapper implements HandlerInterface, ProcessableHandlerInterface, F
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function handle(LogRecord $record): bool
{
@@ -61,7 +58,7 @@ class HandlerWrapper implements HandlerInterface, ProcessableHandlerInterface, F
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function handleBatch(array $records): void
{
@@ -69,7 +66,7 @@ class HandlerWrapper implements HandlerInterface, ProcessableHandlerInterface, F
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function close(): void
{
@@ -77,7 +74,7 @@ class HandlerWrapper implements HandlerInterface, ProcessableHandlerInterface, F
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function pushProcessor(callable $callback): HandlerInterface
{
@@ -91,7 +88,7 @@ class HandlerWrapper implements HandlerInterface, ProcessableHandlerInterface, F
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function popProcessor(): callable
{
@@ -103,7 +100,7 @@ class HandlerWrapper implements HandlerInterface, ProcessableHandlerInterface, F
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function setFormatter(FormatterInterface $formatter): HandlerInterface
{
@@ -117,7 +114,7 @@ class HandlerWrapper implements HandlerInterface, ProcessableHandlerInterface, F
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function getFormatter(): FormatterInterface
{
@@ -128,7 +125,7 @@ class HandlerWrapper implements HandlerInterface, ProcessableHandlerInterface, F
throw new \LogicException('The wrapped handler does not implement ' . FormattableHandlerInterface::class);
}
public function reset()
public function reset(): void
{
if ($this->handler instanceof ResettableInterface) {
$this->handler->reset();

View File

@@ -28,10 +28,8 @@ use Monolog\LogRecord;
*/
class IFTTTHandler extends AbstractProcessingHandler
{
/** @var string */
private $eventName;
/** @var string */
private $secretKey;
private string $eventName;
private string $secretKey;
/**
* @param string $eventName The name of the IFTTT Maker event that should be triggered
@@ -50,7 +48,7 @@ class IFTTTHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function write(LogRecord $record): void
{

View File

@@ -22,10 +22,7 @@ use Monolog\LogRecord;
*/
class InsightOpsHandler extends SocketHandler
{
/**
* @var string
*/
protected $logToken;
protected string $logToken;
/**
* @param string $token Log token supplied by InsightOps
@@ -68,7 +65,7 @@ class InsightOpsHandler extends SocketHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function generateDataStream(LogRecord $record): string
{

View File

@@ -19,10 +19,7 @@ use Monolog\LogRecord;
*/
class LogEntriesHandler extends SocketHandler
{
/**
* @var string
*/
protected $logToken;
protected string $logToken;
/**
* @param string $token Log token supplied by LogEntries
@@ -62,7 +59,7 @@ class LogEntriesHandler extends SocketHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function generateDataStream(LogRecord $record): string
{

View File

@@ -36,13 +36,12 @@ class LogglyHandler extends AbstractProcessingHandler
*
* @var CurlHandle[]
*/
protected $curlHandlers = [];
protected array $curlHandlers = [];
/** @var string */
protected $token;
protected string $token;
/** @var string[] */
protected $tag = [];
protected array $tag = [];
/**
* @param string $token API token supplied by Loggly
@@ -62,11 +61,8 @@ class LogglyHandler extends AbstractProcessingHandler
/**
* Loads and returns the shared curl handler for the given endpoint.
*
*
* @return CurlHandle
*/
protected function getCurlHandler(string $endpoint)
protected function getCurlHandler(string $endpoint): CurlHandle
{
if (!array_key_exists($endpoint, $this->curlHandlers)) {
$this->curlHandlers[$endpoint] = $this->loadCurlHandle($endpoint);
@@ -77,11 +73,8 @@ class LogglyHandler extends AbstractProcessingHandler
/**
* Starts a fresh curl session for the given endpoint and returns its handler.
*
*
* @return CurlHandle
*/
private function loadCurlHandle(string $endpoint)
private function loadCurlHandle(string $endpoint): CurlHandle
{
$url = sprintf("https://%s/%s/%s/", static::HOST, $endpoint, $this->token);

View File

@@ -21,20 +21,11 @@ use Monolog\LogRecord;
*/
class LogmaticHandler extends SocketHandler
{
/**
* @var string
*/
private $logToken;
private string $logToken;
/**
* @var string
*/
private $hostname;
private string $hostname;
/**
* @var string
*/
private $appname;
private string $appname;
/**
* @param string $token Log token supplied by Logmatic.
@@ -81,7 +72,7 @@ class LogmaticHandler extends SocketHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function generateDataStream(LogRecord $record): string
{
@@ -89,7 +80,7 @@ class LogmaticHandler extends SocketHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function getDefaultFormatter(): FormatterInterface
{

View File

@@ -23,7 +23,7 @@ use Monolog\LogRecord;
abstract class MailHandler extends AbstractProcessingHandler
{
/**
* {@inheritDoc}
* @inheritDoc
*/
public function handleBatch(array $records): void
{
@@ -54,7 +54,7 @@ abstract class MailHandler extends AbstractProcessingHandler
abstract protected function send(string $content, array $records): void;
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function write(LogRecord $record): void
{

View File

@@ -22,10 +22,8 @@ use Swift_Message;
*/
class MandrillHandler extends MailHandler
{
/** @var Swift_Message */
protected $message;
/** @var string */
protected $apiKey;
protected Swift_Message $message;
protected string $apiKey;
/**
* @phpstan-param (Swift_Message|callable(): Swift_Message) $message
@@ -48,7 +46,7 @@ class MandrillHandler extends MailHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function send(string $content, array $records): void
{

View File

@@ -77,7 +77,7 @@ class MongoDBHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function getDefaultFormatter(): FormatterInterface
{

View File

@@ -26,43 +26,39 @@ class NativeMailerHandler extends MailHandler
* The email addresses to which the message will be sent
* @var string[]
*/
protected $to;
protected array $to;
/**
* The subject of the email
* @var string
*/
protected $subject;
protected string $subject;
/**
* Optional headers for the message
* @var string[]
*/
protected $headers = [];
protected array $headers = [];
/**
* Optional parameters for the message
* @var string[]
*/
protected $parameters = [];
protected array $parameters = [];
/**
* The wordwrap length for the message
* @var int
*/
protected $maxColumnWidth;
protected int $maxColumnWidth;
/**
* The Content-type for the message
* @var string|null
*/
protected $contentType;
protected string|null $contentType = null;
/**
* The encoding for the message
* @var string
*/
protected $encoding = 'utf-8';
protected string $encoding = 'utf-8';
/**
* @param string|string[] $to The receiver of the mail
@@ -109,7 +105,7 @@ class NativeMailerHandler extends MailHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function send(string $content, array $records): void
{

View File

@@ -45,13 +45,11 @@ class NewRelicHandler extends AbstractProcessingHandler
/**
* Some context and extra data is passed into the handler as arrays of values. Do we send them as is
* (useful if we are using the API), or explode them for display on the NewRelic RPM website?
*
* @var bool
*/
protected $explodeArrays;
protected bool $explodeArrays;
/**
* {@inheritDoc}
* @inheritDoc
*/
public function __construct(
$level = Level::Error,
@@ -68,7 +66,7 @@ class NewRelicHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function write(LogRecord $record): void
{
@@ -184,7 +182,7 @@ class NewRelicHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function getDefaultFormatter(): FormatterInterface
{

View File

@@ -25,7 +25,7 @@ use Monolog\LogRecord;
class NoopHandler extends Handler
{
/**
* {@inheritDoc}
* @inheritDoc
*/
public function isHandling(LogRecord $record): bool
{
@@ -33,7 +33,7 @@ class NoopHandler extends Handler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function handle(LogRecord $record): bool
{

View File

@@ -40,7 +40,7 @@ class NullHandler extends Handler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function isHandling(LogRecord $record): bool
{
@@ -48,7 +48,7 @@ class NullHandler extends Handler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function handle(LogRecord $record): bool
{

View File

@@ -37,18 +37,17 @@ use Monolog\LogRecord;
*/
class OverflowHandler extends AbstractHandler implements FormattableHandlerInterface
{
/** @var HandlerInterface */
private $handler;
private HandlerInterface $handler;
/** @var array<int, int> */
private $thresholdMap = [];
private array $thresholdMap = [];
/**
* Buffer of all messages passed to the handler before the threshold was reached
*
* @var mixed[][]
*/
private $buffer = [];
private array $buffer = [];
/**
* @param array<int, int> $thresholdMap Dictionary of log level value => threshold
@@ -76,7 +75,7 @@ class OverflowHandler extends AbstractHandler implements FormattableHandlerInter
* 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.
*
* {@inheritDoc}
* @inheritDoc
*/
public function handle(LogRecord $record): bool
{
@@ -113,7 +112,7 @@ class OverflowHandler extends AbstractHandler implements FormattableHandlerInter
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function setFormatter(FormatterInterface $formatter): HandlerInterface
{
@@ -127,7 +126,7 @@ class OverflowHandler extends AbstractHandler implements FormattableHandlerInter
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function getFormatter(): FormatterInterface
{

View File

@@ -42,7 +42,7 @@ use Monolog\LogRecord;
class PHPConsoleHandler extends AbstractProcessingHandler
{
/** @var array<string, mixed> */
private $options = [
private array $options = [
'enabled' => true, // bool Is PHP Console server enabled
'classesPartialsTraceIgnore' => ['Monolog\\'], // array Hide calls of classes started with...
'debugTagsKeysInContext' => [0, 'tag'], // bool Is PHP Console server enabled
@@ -65,8 +65,7 @@ class PHPConsoleHandler extends AbstractProcessingHandler
'dataStorage' => null, // \PhpConsole\Storage|null Fixes problem with custom $_SESSION handler(see http://goo.gl/Ne8juJ)
];
/** @var Connector */
private $connector;
private Connector $connector;
/**
* @param array<string, mixed> $options See \Monolog\Handler\PHPConsoleHandler::$options for more details
@@ -243,7 +242,7 @@ class PHPConsoleHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function getDefaultFormatter(): FormatterInterface
{

View File

@@ -34,20 +34,14 @@ class ProcessHandler extends AbstractProcessingHandler
*/
private $process;
/**
* @var string
*/
private $command;
private string $command;
/**
* @var string|null
*/
private $cwd;
private ?string $cwd;
/**
* @var resource[]
*/
private $pipes = [];
private array $pipes = [];
/**
* @var array<int, string[]>
@@ -177,7 +171,7 @@ class ProcessHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function close(): void
{

View File

@@ -26,10 +26,10 @@ trait ProcessableHandlerTrait
* @var callable[]
* @phpstan-var array<(callable(LogRecord): LogRecord)|ProcessorInterface>
*/
protected $processors = [];
protected array $processors = [];
/**
* {@inheritDoc}
* @inheritDoc
*/
public function pushProcessor(callable $callback): HandlerInterface
{
@@ -39,7 +39,7 @@ trait ProcessableHandlerTrait
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function popProcessor(): callable
{

View File

@@ -29,15 +29,10 @@ class PsrHandler extends AbstractHandler implements FormattableHandlerInterface
{
/**
* PSR-3 compliant logger
*
* @var LoggerInterface
*/
protected $logger;
protected LoggerInterface $logger;
/**
* @var FormatterInterface|null
*/
protected $formatter;
protected FormatterInterface|null $formatter = null;
/**
* @param LoggerInterface $logger The underlying PSR-3 compliant logger to which messages will be proxied
@@ -50,7 +45,7 @@ class PsrHandler extends AbstractHandler implements FormattableHandlerInterface
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function handle(LogRecord $record): bool
{

View File

@@ -26,30 +26,25 @@ use Monolog\LogRecord;
*/
class PushoverHandler extends SocketHandler
{
/** @var string */
private $token;
private string $token;
/** @var array<int|string> */
private $users;
/** @var string */
private $title;
private array $users;
private string $title;
/** @var string|int|null */
private $user = null;
/** @var int */
private $retry;
/** @var int */
private $expire;
private int $retry;
private int $expire;
private Level $highPriorityLevel;
private Level $emergencyLevel;
/** @var bool */
private $useFormattedMessage = false;
private bool $useFormattedMessage = false;
/**
* All parameters that can be sent to Pushover
* @see https://pushover.net/api
* @var array<string, bool>
*/
private $parameterNames = [
private array $parameterNames = [
'token' => true,
'user' => true,
'message' => true,
@@ -70,7 +65,7 @@ class PushoverHandler extends SocketHandler
* @see https://pushover.net/api#sounds
* @var string[]
*/
private $sounds = [
private array $sounds = [
'pushover', 'bike', 'bugle', 'cashregister', 'classical', 'cosmic', 'falling', 'gamelan', 'incoming',
'intermission', 'magic', 'mechanical', 'pianobar', 'siren', 'spacealarm', 'tugboat', 'alien', 'climb',
'persistent', 'echo', 'updown', 'none',

View File

@@ -31,10 +31,8 @@ class RedisHandler extends AbstractProcessingHandler
{
/** @var \Predis\Client<\Predis\Client>|\Redis */
private $redisClient;
/** @var string */
private $redisKey;
/** @var int */
protected $capSize;
private string $redisKey;
protected int $capSize;
/**
* @param \Predis\Client<\Predis\Client>|\Redis $redis The redis instance
@@ -55,7 +53,7 @@ class RedisHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function write(LogRecord $record): void
{
@@ -89,7 +87,7 @@ class RedisHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function getDefaultFormatter(): FormatterInterface
{

View File

@@ -31,8 +31,7 @@ class RedisPubSubHandler extends AbstractProcessingHandler
{
/** @var \Predis\Client<\Predis\Client>|\Redis */
private $redisClient;
/** @var string */
private $channelKey;
private string $channelKey;
/**
* @param \Predis\Client<\Predis\Client>|\Redis $redis The redis instance
@@ -51,7 +50,7 @@ class RedisPubSubHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function write(LogRecord $record): void
{
@@ -59,7 +58,7 @@ class RedisPubSubHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function getDefaultFormatter(): FormatterInterface
{

View File

@@ -35,20 +35,14 @@ use Monolog\LogRecord;
*/
class RollbarHandler extends AbstractProcessingHandler
{
/**
* @var RollbarLogger
*/
protected $rollbarLogger;
protected RollbarLogger $rollbarLogger;
/**
* Records whether any log records have been added since the last flush of the rollbar notifier
*
* @var bool
*/
private $hasRecords = false;
private bool $hasRecords = false;
/** @var bool */
protected $initialized = false;
protected bool $initialized = false;
/**
* @param RollbarLogger $rollbarLogger RollbarLogger object constructed with valid token
@@ -80,7 +74,7 @@ class RollbarHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function write(LogRecord $record): void
{
@@ -121,7 +115,7 @@ class RollbarHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function close(): void
{
@@ -129,9 +123,9 @@ class RollbarHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function reset()
public function reset(): void
{
$this->flush();

View File

@@ -31,18 +31,12 @@ class RotatingFileHandler extends StreamHandler
public const FILE_PER_MONTH = 'Y-m';
public const FILE_PER_YEAR = 'Y';
/** @var string */
protected $filename;
/** @var int */
protected $maxFiles;
/** @var bool */
protected $mustRotate;
/** @var \DateTimeImmutable */
protected $nextRotation;
/** @var string */
protected $filenameFormat;
/** @var string */
protected $dateFormat;
protected string $filename;
protected int $maxFiles;
protected bool|null $mustRotate = null;
protected \DateTimeImmutable $nextRotation;
protected string $filenameFormat;
protected string $dateFormat;
/**
* @param int $maxFiles The maximal amount of files to keep (0 means unlimited)
@@ -61,7 +55,7 @@ class RotatingFileHandler extends StreamHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function close(): void
{
@@ -73,9 +67,9 @@ class RotatingFileHandler extends StreamHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function reset()
public function reset(): void
{
parent::reset();
@@ -108,7 +102,7 @@ class RotatingFileHandler extends StreamHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function write(LogRecord $record): void
{

View File

@@ -38,10 +38,7 @@ class SamplingHandler extends AbstractHandler implements ProcessableHandlerInter
*/
protected $handler;
/**
* @var int $factor
*/
protected $factor;
protected int $factor;
/**
* @phpstan-param (callable(LogRecord|null, HandlerInterface): HandlerInterface)|HandlerInterface $handler
@@ -82,10 +79,8 @@ class SamplingHandler extends AbstractHandler implements ProcessableHandlerInter
* Return the nested handler
*
* If the handler was provided as a factory callable, this will trigger the handler's instantiation.
*
* @return HandlerInterface
*/
public function getHandler(LogRecord $record = null)
public function getHandler(LogRecord $record = null): HandlerInterface
{
if (!$this->handler instanceof HandlerInterface) {
$this->handler = ($this->handler)($record, $this);
@@ -98,7 +93,7 @@ class SamplingHandler extends AbstractHandler implements ProcessableHandlerInter
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function setFormatter(FormatterInterface $formatter): HandlerInterface
{
@@ -113,7 +108,7 @@ class SamplingHandler extends AbstractHandler implements ProcessableHandlerInter
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function getFormatter(): FormatterInterface
{

View File

@@ -22,33 +22,29 @@ class SendGridHandler extends MailHandler
{
/**
* The SendGrid API User
* @var string
*/
protected $apiUser;
protected string $apiUser;
/**
* The SendGrid API Key
* @var string
*/
protected $apiKey;
protected string $apiKey;
/**
* The email addresses to which the message will be sent
* @var string
*/
protected $from;
protected string $from;
/**
* The email addresses to which the message will be sent
* @var string[]
*/
protected $to;
protected array $to;
/**
* The subject of the email
* @var string
*/
protected $subject;
protected string $subject;
/**
* @param string $apiUser The SendGrid API User
@@ -72,7 +68,7 @@ class SendGridHandler extends MailHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function send(string $content, array $records): void
{

View File

@@ -37,55 +37,46 @@ class SlackRecord
/**
* Slack channel (encoded ID or name)
* @var string|null
*/
private $channel;
private ?string $channel;
/**
* Name of a bot
* @var string|null
*/
private $username;
private ?string $username;
/**
* User icon e.g. 'ghost', 'http://example.com/user.png'
* @var string|null
*/
private $userIcon;
private ?string $userIcon;
/**
* Whether the message should be added to Slack as attachment (plain text otherwise)
* @var bool
*/
private $useAttachment;
private bool $useAttachment;
/**
* Whether the the context/extra messages added to Slack as attachments are in a short style
* @var bool
*/
private $useShortAttachment;
private bool $useShortAttachment;
/**
* Whether the attachment should include context and extra data
* @var bool
*/
private $includeContextAndExtra;
private bool $includeContextAndExtra;
/**
* Dot separated list of fields to exclude from slack message. E.g. ['context.field1', 'extra.field2']
* @var string[]
*/
private $excludeFields;
private array $excludeFields;
/**
* @var ?FormatterInterface
*/
private $formatter;
/**
* @var NormalizerFormatter
*/
private $normalizerFormatter;
private NormalizerFormatter $normalizerFormatter;
/**
* @param string[] $excludeFields

View File

@@ -27,15 +27,13 @@ class SlackHandler extends SocketHandler
{
/**
* Slack API token
* @var string
*/
private $token;
private string $token;
/**
* Instance of the SlackRecord util class preparing data for Slack API.
* @var SlackRecord
*/
private $slackRecord;
private SlackRecord $slackRecord;
/**
* @param string $token Slack API token
@@ -104,7 +102,7 @@ class SlackHandler extends SocketHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function generateDataStream(LogRecord $record): string
{
@@ -153,7 +151,7 @@ class SlackHandler extends SocketHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function write(LogRecord $record): void
{

View File

@@ -27,15 +27,13 @@ class SlackWebhookHandler extends AbstractProcessingHandler
{
/**
* Slack Webhook token
* @var string
*/
private $webhookUrl;
private string $webhookUrl;
/**
* Instance of the SlackRecord util class preparing data for Slack API.
* @var SlackRecord
*/
private $slackRecord;
private SlackRecord $slackRecord;
/**
* @param string $webhookUrl Slack Webhook URL
@@ -89,7 +87,7 @@ class SlackWebhookHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function write(LogRecord $record): void
{

View File

@@ -22,22 +22,17 @@ use Monolog\LogRecord;
*/
class SocketHandler extends AbstractProcessingHandler
{
/** @var string */
private $connectionString;
/** @var float */
private $connectionTimeout;
private string $connectionString;
private float $connectionTimeout;
/** @var resource|null */
private $resource;
/** @var float */
private $timeout;
/** @var float */
private $writingTimeout;
private float $timeout;
private float $writingTimeout;
/** @var ?int */
private $lastSentBytes = null;
/** @var ?int */
private $chunkSize;
/** @var bool */
private $persistent;
private bool $persistent;
/** @var ?int */
private $errno = null;
/** @var ?string */
@@ -85,7 +80,7 @@ class SocketHandler extends AbstractProcessingHandler
/**
* Connect (if necessary) and write to the socket
*
* {@inheritDoc}
* @inheritDoc
*
* @throws \UnexpectedValueException
* @throws \RuntimeException
@@ -260,10 +255,8 @@ class SocketHandler extends AbstractProcessingHandler
* Wrapper to allow mocking
*
* @see http://php.net/manual/en/function.stream-set-timeout.php
*
* @return bool
*/
protected function streamSetTimeout()
protected function streamSetTimeout(): bool
{
$seconds = floor($this->timeout);
$microseconds = round(($this->timeout - $seconds) * 1e6);

View File

@@ -28,10 +28,8 @@ class SqsHandler extends AbstractProcessingHandler
/** 100 KB in bytes - head message size for new error log */
protected const HEAD_MESSAGE_SIZE = 102400;
/** @var SqsClient */
private $client;
/** @var string */
private $queueUrl;
private SqsClient $client;
private string $queueUrl;
public function __construct(SqsClient $sqsClient, string $queueUrl, $level = Level::Debug, bool $bubble = true)
{
@@ -42,7 +40,7 @@ class SqsHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function write(LogRecord $record): void
{

View File

@@ -28,8 +28,7 @@ class StreamHandler extends AbstractProcessingHandler
protected const MAX_CHUNK_SIZE = 2147483647;
/** @const int 10MB */
protected const DEFAULT_CHUNK_SIZE = 10 * 1024 * 1024;
/** @var int */
protected $streamChunkSize;
protected int $streamChunkSize;
/** @var resource|null */
protected $stream;
/** @var ?string */
@@ -38,10 +37,9 @@ class StreamHandler extends AbstractProcessingHandler
private $errorMessage = null;
/** @var ?int */
protected $filePermission;
/** @var bool */
protected $useLocking;
protected bool $useLocking;
/** @var true|null */
private $dirCreated = null;
private ?bool $dirCreated = null;
/**
* @param resource|string $stream If a missing path can't be created, an UnexpectedValueException will be thrown on first write
@@ -82,7 +80,7 @@ class StreamHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function close(): void
{
@@ -111,15 +109,13 @@ class StreamHandler extends AbstractProcessingHandler
return $this->url;
}
/**
*/
public function getStreamChunkSize(): int
{
return $this->streamChunkSize;
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function write(LogRecord $record): void
{

View File

@@ -30,10 +30,8 @@ use Monolog\LogRecord;
*/
class SyslogHandler extends AbstractSyslogHandler
{
/** @var string */
protected $ident;
/** @var int */
protected $logopts;
protected string $ident;
protected int $logopts;
/**
* @param string|int $facility Either one of the names of the keys in $this->facilities, or a LOG_* facility constant
@@ -48,7 +46,7 @@ class SyslogHandler extends AbstractSyslogHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function close(): void
{
@@ -56,7 +54,7 @@ class SyslogHandler extends AbstractSyslogHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function write(LogRecord $record): void
{

View File

@@ -18,12 +18,9 @@ class UdpSocket
{
protected const DATAGRAM_MAX_LENGTH = 65023;
/** @var string */
protected $ip;
/** @var int */
protected $port;
/** @var Socket|null */
protected $socket;
protected string $ip;
protected int $port;
protected ?Socket $socket;
public function __construct(string $ip, int $port = 514)
{
@@ -39,12 +36,7 @@ class UdpSocket
$this->socket = socket_create($domain, SOCK_DGRAM, $protocol) ?: null;
}
/**
* @param string $line
* @param string $header
* @return void
*/
public function write($line, $header = "")
public function write(string $line, string $header = ""): void
{
$this->send($this->assembleMessage($line, $header));
}

View File

@@ -30,16 +30,14 @@ class SyslogUdpHandler extends AbstractSyslogHandler
const RFC5424e = 2;
/** @var array<self::RFC*, string> */
private $dateFormats = [
private array $dateFormats = [
self::RFC3164 => 'M d H:i:s',
self::RFC5424 => \DateTime::RFC3339,
self::RFC5424e => \DateTime::RFC3339_EXTENDED,
];
/** @var UdpSocket */
protected $socket;
/** @var string */
protected $ident;
protected UdpSocket $socket;
protected string $ident;
/** @var self::RFC* */
protected $rfc;

View File

@@ -51,16 +51,14 @@ class TelegramBotHandler extends AbstractProcessingHandler
/**
* Telegram bot access token provided by BotFather.
* Create telegram bot with https://telegram.me/BotFather and use access token from it.
* @var string
*/
private $apiKey;
private string $apiKey;
/**
* Telegram channel name.
* Since to start with '@' symbol as prefix.
* @var string
*/
private $channel;
private string $channel;
/**
* The kind of formatting that is used for the message.
@@ -85,15 +83,13 @@ class TelegramBotHandler extends AbstractProcessingHandler
/**
* True - split a message longer than MAX_MESSAGE_LENGTH into parts and send in multiple messages.
* False - truncates a message that is too long.
* @var bool
*/
private $splitLongMessages;
private bool $splitLongMessages;
/**
* Adds 1-second delay between sending a split message (according to Telegram API to avoid 429 Too Many Requests).
* @var bool
*/
private $delayBetweenMessages;
private bool $delayBetweenMessages;
/**
* @param string $apiKey Telegram bot access token provided by BotFather
@@ -177,7 +173,7 @@ class TelegramBotHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function handleBatch(array $records): void
{

View File

@@ -72,43 +72,33 @@ use Monolog\LogRecord;
class TestHandler extends AbstractProcessingHandler
{
/** @var LogRecord[] */
protected $records = [];
protected array $records = [];
/** @phpstan-var array<value-of<Level::VALUES>, LogRecord[]> */
protected array $recordsByLevel = [];
/** @var bool */
private $skipReset = false;
private bool $skipReset = false;
/**
* @return array<LogRecord>
*/
public function getRecords()
public function getRecords(): array
{
return $this->records;
}
/**
* @return void
*/
public function clear()
public function clear(): void
{
$this->records = [];
$this->recordsByLevel = [];
}
/**
* @return void
*/
public function reset()
public function reset(): void
{
if (!$this->skipReset) {
$this->clear();
}
}
/**
* @return void
*/
public function setSkipReset(bool $skipReset)
public function setSkipReset(bool $skipReset): void
{
$this->skipReset = $skipReset;
}
@@ -177,7 +167,7 @@ class TestHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function write(LogRecord $record): void
{
@@ -186,11 +176,9 @@ class TestHandler extends AbstractProcessingHandler
}
/**
* @param string $method
* @param mixed[] $args
* @return bool
* @param mixed[] $args
*/
public function __call($method, $args)
public function __call(string $method, array $args): bool
{
if (preg_match('/(.*)(Debug|Info|Notice|Warning|Error|Critical|Alert|Emergency)(.*)/', $method, $matches) > 0) {
$genericMethod = $matches[1] . ('Records' !== $matches[3] ? 'Record' : '') . $matches[3];

View File

@@ -23,7 +23,7 @@ use Throwable;
class WhatFailureGroupHandler extends GroupHandler
{
/**
* {@inheritDoc}
* @inheritDoc
*/
public function handle(LogRecord $record): bool
{
@@ -43,7 +43,7 @@ class WhatFailureGroupHandler extends GroupHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function handleBatch(array $records): void
{

View File

@@ -56,7 +56,7 @@ class ZendMonitorHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
protected function write(LogRecord $record): void
{
@@ -81,7 +81,7 @@ class ZendMonitorHandler extends AbstractProcessingHandler
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function getDefaultFormatter(): FormatterInterface
{

View File

@@ -106,17 +106,14 @@ class Logger implements LoggerInterface, ResettableInterface
*/
public const API = 3;
/**
* @var string
*/
protected $name;
protected string $name;
/**
* The handler stack
*
* @var HandlerInterface[]
*/
protected $handlers;
protected array $handlers;
/**
* Processors that will process all log records
@@ -127,15 +124,9 @@ class Logger implements LoggerInterface, ResettableInterface
*/
protected $processors;
/**
* @var bool
*/
protected $microsecondTimestamps = true;
protected bool $microsecondTimestamps = true;
/**
* @var DateTimeZone
*/
protected $timezone;
protected DateTimeZone $timezone;
/**
* @var callable|null
@@ -150,7 +141,7 @@ class Logger implements LoggerInterface, ResettableInterface
*
* @phpstan-param array<(callable(LogRecord): LogRecord)|ProcessorInterface> $processors
*/
public function __construct(string $name, array $handlers = [], array $processors = [], ?DateTimeZone $timezone = null)
public function __construct(string $name, array $handlers = [], array $processors = [], DateTimeZone|null $timezone = null)
{
$this->name = $name;
$this->setHandlers($handlers);

View File

@@ -40,7 +40,7 @@ class GitProcessor implements ProcessorInterface
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function __invoke(LogRecord $record): LogRecord
{

View File

@@ -18,8 +18,7 @@ use Monolog\LogRecord;
*/
class HostnameProcessor implements ProcessorInterface
{
/** @var string */
private static $host;
private static string $host;
public function __construct()
{
@@ -27,7 +26,7 @@ class HostnameProcessor implements ProcessorInterface
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function __invoke(LogRecord $record): LogRecord
{

View File

@@ -56,7 +56,7 @@ class IntrospectionProcessor implements ProcessorInterface
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function __invoke(LogRecord $record): LogRecord
{

View File

@@ -22,7 +22,7 @@ use Monolog\LogRecord;
class MemoryPeakUsageProcessor extends MemoryProcessor
{
/**
* {@inheritDoc}
* @inheritDoc
*/
public function __invoke(LogRecord $record): LogRecord
{

View File

@@ -21,12 +21,12 @@ abstract class MemoryProcessor implements ProcessorInterface
/**
* @var bool If true, get the real size of memory allocated from system. Else, only the memory used by emalloc() is reported.
*/
protected $realUsage;
protected bool $realUsage;
/**
* @var bool If true, then format memory size to human readable string (MB, KB, B depending on size)
*/
protected $useFormatting;
protected bool $useFormatting;
/**
* @param bool $realUsage Set this to true to get the real size of memory allocated from system.

View File

@@ -22,7 +22,7 @@ use Monolog\LogRecord;
class MemoryUsageProcessor extends MemoryProcessor
{
/**
* {@inheritDoc}
* @inheritDoc
*/
public function __invoke(LogRecord $record): LogRecord
{

View File

@@ -39,7 +39,7 @@ class MercurialProcessor implements ProcessorInterface
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function __invoke(LogRecord $record): LogRecord
{

View File

@@ -21,7 +21,7 @@ use Monolog\LogRecord;
class ProcessIdProcessor implements ProcessorInterface
{
/**
* {@inheritDoc}
* @inheritDoc
*/
public function __invoke(LogRecord $record): LogRecord
{

View File

@@ -23,5 +23,5 @@ interface ProcessorInterface
/**
* @return LogRecord The processed record
*/
public function __invoke(LogRecord $record);
public function __invoke(LogRecord $record): LogRecord;
}

View File

@@ -25,11 +25,9 @@ class PsrLogMessageProcessor implements ProcessorInterface
{
public const SIMPLE_DATE = "Y-m-d\TH:i:s.uP";
/** @var string|null */
private $dateFormat;
private ?string $dateFormat;
/** @var bool */
private $removeUsedContextFields;
private bool $removeUsedContextFields;
/**
* @param string|null $dateFormat The format of the timestamp: one supported by DateTime::format
@@ -42,7 +40,7 @@ class PsrLogMessageProcessor implements ProcessorInterface
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function __invoke(LogRecord $record): LogRecord
{

View File

@@ -21,7 +21,7 @@ use Monolog\LogRecord;
class TagProcessor implements ProcessorInterface
{
/** @var string[] */
private $tags;
private array $tags;
/**
* @param string[] $tags
@@ -52,7 +52,7 @@ class TagProcessor implements ProcessorInterface
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function __invoke(LogRecord $record): LogRecord
{

View File

@@ -37,7 +37,7 @@ class UidProcessor implements ProcessorInterface, ResettableInterface
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function __invoke(LogRecord $record): LogRecord
{
@@ -51,7 +51,7 @@ class UidProcessor implements ProcessorInterface, ResettableInterface
return $this->uid;
}
public function reset()
public function reset(): void
{
$this->uid = $this->generateUid(strlen($this->uid));
}

View File

@@ -32,7 +32,7 @@ class WebProcessor implements ProcessorInterface
*
* @var array<string, string>
*/
protected $extraFields = [
protected array $extraFields = [
'url' => 'REQUEST_URI',
'ip' => 'REMOTE_ADDR',
'http_method' => 'REQUEST_METHOD',
@@ -76,7 +76,7 @@ class WebProcessor implements ProcessorInterface
}
/**
* {@inheritDoc}
* @inheritDoc
*/
public function __invoke(LogRecord $record): LogRecord
{

View File

@@ -42,7 +42,7 @@ class Registry
*
* @var Logger[]
*/
private static $loggers = [];
private static array $loggers = [];
/**
* Adds new logging channel to the registry
@@ -51,9 +51,8 @@ class Registry
* @param string|null $name Name of the logging channel ($logger->getName() by default)
* @param bool $overwrite Overwrite instance in the registry if the given name already exists?
* @throws \InvalidArgumentException If $overwrite set to false and named Logger instance already exists
* @return void
*/
public static function addLogger(Logger $logger, ?string $name = null, bool $overwrite = false)
public static function addLogger(Logger $logger, ?string $name = null, bool $overwrite = false): void
{
$name = $name ?: $logger->getName();
@@ -110,7 +109,7 @@ class Registry
* @param string $name Name of the requested Logger instance
* @throws \InvalidArgumentException If named Logger instance is not in the registry
*/
public static function getInstance($name): Logger
public static function getInstance(string $name): Logger
{
if (!isset(self::$loggers[$name])) {
throw new InvalidArgumentException(sprintf('Requested "%s" logger instance is not in the registry', $name));
@@ -127,7 +126,7 @@ class Registry
* @throws \InvalidArgumentException If named Logger instance is not in the registry
* @return Logger Requested instance of Logger
*/
public static function __callStatic($name, $arguments)
public static function __callStatic(string $name, array $arguments): Logger
{
return self::getInstance($name);
}

View File

@@ -27,8 +27,5 @@ namespace Monolog;
*/
interface ResettableInterface
{
/**
* @return void
*/
public function reset();
public function reset(): void;
}

View File

@@ -22,15 +22,14 @@ use ReflectionExtension;
*/
class SignalHandler
{
/** @var LoggerInterface */
private $logger;
private LoggerInterface $logger;
/** @var array<int, callable|string|int> SIG_DFL, SIG_IGN or previous callable */
private $previousSignalHandler = [];
private array $previousSignalHandler = [];
/** @var array<int, \Psr\Log\LogLevel::*> */
private $signalLevelMap = [];
private array $signalLevelMap = [];
/** @var array<int, bool> */
private $signalRestartSyscalls = [];
private array $signalRestartSyscalls = [];
public function __construct(LoggerInterface $logger)
{

View File

@@ -125,7 +125,6 @@ class ErrorHandlerTest extends \PHPUnit\Framework\TestCase
$this->assertEquals('E_DEPRECATED', $method->invokeArgs(null, [E_DEPRECATED]));
$this->assertEquals('E_USER_DEPRECATED', $method->invokeArgs(null, [E_USER_DEPRECATED]));
$this->assertEquals('Unknown PHP error', $method->invokeArgs(null, ['RANDOM_TEXT']));
$this->assertEquals('Unknown PHP error', $method->invokeArgs(null, [E_ALL]));
}
}

View File

@@ -191,12 +191,9 @@ class JsonFormatterTest extends TestCase
}
/**
* @param string $expected
* @param string $actual
*
* @internal param string $exception
*/
private function assertContextContainsFormattedException($expected, $actual)
private function assertContextContainsFormattedException(string $expected, string $actual)
{
$this->assertEquals(
'{"message":"foobar","context":{"exception":'.$expected.'},"level":500,"level_name":"CRITICAL","channel":"core","datetime":"2022-02-22T00:00:00+00:00","extra":{}}'."\n",
@@ -204,10 +201,7 @@ class JsonFormatterTest extends TestCase
);
}
/**
* @return string
*/
private function formatRecordWithExceptionInContext(JsonFormatter $formatter, \Throwable $exception)
private function formatRecordWithExceptionInContext(JsonFormatter $formatter, \Throwable $exception): string
{
$message = $formatter->format($this->getRecord(
Level::Critical,
@@ -222,10 +216,8 @@ class JsonFormatterTest extends TestCase
/**
* @param \Exception|\Throwable $exception
*
* @return string
*/
private function formatExceptionFilePathWithLine($exception)
private function formatExceptionFilePathWithLine($exception): string
{
$options = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
$path = substr(json_encode($exception->getFile(), $options), 1, -1);
@@ -235,12 +227,8 @@ class JsonFormatterTest extends TestCase
/**
* @param \Exception|\Throwable $exception
*
* @param null|string $previous
*
* @return string
*/
private function formatException($exception, $previous = null)
private function formatException($exception, ?string $previous = null): string
{
$formattedException =
'{"class":"' . get_class($exception) .

View File

@@ -371,10 +371,7 @@ class NormalizerFormatterTest extends TestCase
);
}
/**
* @return string
*/
private function formatRecordWithExceptionInContext(NormalizerFormatter $formatter, \Throwable $exception)
private function formatRecordWithExceptionInContext(NormalizerFormatter $formatter, \Throwable $exception): array
{
$message = $formatter->format($this->getRecord(
Level::Critical,

Some files were not shown because too many files have changed in this diff Show More