1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-23 09:36:11 +02:00

Add Record/Level/LevelName type aliases and improve phpstan type coverage to level 6

This commit is contained in:
Jordi Boggiano
2021-05-28 10:29:33 +02:00
parent 5c9d9bf43e
commit 01d104aa78
88 changed files with 791 additions and 180 deletions

View File

@@ -23,6 +23,8 @@ use Monolog\Formatter\FormatterInterface;
* @author Haralan Dobrev <hkdobrev@gmail.com>
* @see https://api.slack.com/incoming-webhooks
* @see https://api.slack.com/docs/message-attachments
*
* @phpstan-import-type FormattedRecord from \Monolog\Handler\AbstractProcessingHandler
*/
class SlackRecord
{
@@ -72,7 +74,7 @@ class SlackRecord
/**
* Dot separated list of fields to exclude from slack message. E.g. ['context.field1', 'extra.field2']
* @var array
* @var string[]
*/
private $excludeFields;
@@ -86,6 +88,9 @@ class SlackRecord
*/
private $normalizerFormatter;
/**
* @param string[] $excludeFields
*/
public function __construct(
?string $channel = null,
?string $username = null,
@@ -114,6 +119,9 @@ class SlackRecord
/**
* Returns required data in format that Slack
* is expecting.
*
* @phpstan-param FormattedRecord $record
* @phpstan-return string[]
*/
public function getSlackData(array $record): array
{
@@ -208,6 +216,8 @@ class SlackRecord
/**
* Stringifies an array of key/value pairs to be used in attachment fields
*
* @param mixed[] $fields
*/
public function stringify(array $fields): string
{
@@ -285,6 +295,9 @@ class SlackRecord
return $this;
}
/**
* @param string[] $excludeFields
*/
public function excludeFields(array $excludeFields = []): self
{
$this->excludeFields = $excludeFields;
@@ -302,7 +315,8 @@ class SlackRecord
/**
* Generates attachment field
*
* @param string|array $value
* @param string|mixed[] $value
* @return array{title: string, value: string, short: false}
*/
private function generateAttachmentField(string $title, $value): array
{
@@ -319,6 +333,9 @@ class SlackRecord
/**
* Generates a collection of attachment fields from array
*
* @param mixed[] $data
* @return array<array{title: string, value: string, short: false}>
*/
private function generateAttachmentFields(array $data): array
{
@@ -332,6 +349,9 @@ class SlackRecord
/**
* Get a copy of record with fields excluded according to $this->excludeFields
*
* @phpstan-param FormattedRecord $record
* @return mixed[]
*/
private function removeExcludedFields(array $record): array
{