mirror of
https://github.com/Seldaek/monolog.git
synced 2025-10-23 01:26:11 +02:00
More type hints on some handler classes
This commit is contained in:
@@ -35,19 +35,19 @@ class SlackRecord
|
||||
|
||||
/**
|
||||
* Slack channel (encoded ID or name)
|
||||
* @var string|null
|
||||
* @var ?string
|
||||
*/
|
||||
private $channel;
|
||||
|
||||
/**
|
||||
* Name of a bot
|
||||
* @var string|null
|
||||
* @var ?string
|
||||
*/
|
||||
private $username;
|
||||
|
||||
/**
|
||||
* User icon e.g. 'ghost', 'http://example.com/user.png'
|
||||
* @var string
|
||||
* @var ?string
|
||||
*/
|
||||
private $userIcon;
|
||||
|
||||
@@ -85,7 +85,7 @@ class SlackRecord
|
||||
*/
|
||||
private $normalizerFormatter;
|
||||
|
||||
public function __construct($channel = null, $username = null, $useAttachment = true, $userIcon = null, $useShortAttachment = false, $includeContextAndExtra = false, array $excludeFields = array(), FormatterInterface $formatter = null)
|
||||
public function __construct(?string $channel = null, ?string $username = null, bool $useAttachment = true, ?string $userIcon = null, bool $useShortAttachment = false, bool $includeContextAndExtra = false, array $excludeFields = array(), FormatterInterface $formatter = null)
|
||||
{
|
||||
$this->channel = $channel;
|
||||
$this->username = $username;
|
||||
@@ -101,7 +101,7 @@ class SlackRecord
|
||||
}
|
||||
}
|
||||
|
||||
public function getSlackData(array $record)
|
||||
public function getSlackData(array $record): array
|
||||
{
|
||||
$dataArray = array();
|
||||
$record = $this->excludeFields($record);
|
||||
@@ -177,11 +177,8 @@ class SlackRecord
|
||||
/**
|
||||
* Returned a Slack message attachment color associated with
|
||||
* provided level.
|
||||
*
|
||||
* @param int $level
|
||||
* @return string
|
||||
*/
|
||||
public function getAttachmentColor($level)
|
||||
public function getAttachmentColor(int $level): string
|
||||
{
|
||||
switch (true) {
|
||||
case $level >= Logger::ERROR:
|
||||
@@ -197,12 +194,8 @@ class SlackRecord
|
||||
|
||||
/**
|
||||
* Stringifies an array of key/value pairs to be used in attachment fields
|
||||
*
|
||||
* @param array $fields
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function stringify($fields)
|
||||
public function stringify(array $fields): string
|
||||
{
|
||||
$normalized = $this->normalizerFormatter->format($fields);
|
||||
$prettyPrintFlag = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 128;
|
||||
@@ -215,25 +208,19 @@ class SlackRecord
|
||||
: json_encode($normalized, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the formatter
|
||||
*
|
||||
* @param FormatterInterface $formatter
|
||||
*/
|
||||
public function setFormatter(FormatterInterface $formatter)
|
||||
public function setFormatter(FormatterInterface $formatter): self
|
||||
{
|
||||
$this->formatter = $formatter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates attachment field
|
||||
*
|
||||
* @param string $title
|
||||
* @param string|array $value
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function generateAttachmentField($title, $value)
|
||||
private function generateAttachmentField(string $title, $value): array
|
||||
{
|
||||
$value = is_array($value)
|
||||
? sprintf('```%s```', $this->stringify($value))
|
||||
@@ -248,12 +235,8 @@ class SlackRecord
|
||||
|
||||
/**
|
||||
* Generates a collection of attachment fields from array
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function generateAttachmentFields(array $data)
|
||||
private function generateAttachmentFields(array $data): array
|
||||
{
|
||||
$fields = array();
|
||||
foreach ($this->normalizerFormatter->format($data) as $key => $value) {
|
||||
@@ -265,12 +248,8 @@ class SlackRecord
|
||||
|
||||
/**
|
||||
* Get a copy of record with fields excluded according to $this->excludeFields
|
||||
*
|
||||
* @param array $record
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function excludeFields(array $record)
|
||||
private function excludeFields(array $record): array
|
||||
{
|
||||
foreach ($this->excludeFields as $field) {
|
||||
$keys = explode('.', $field);
|
||||
|
Reference in New Issue
Block a user