From be5c43916743540bce0ef638d4d72a772d974f47 Mon Sep 17 00:00:00 2001 From: Avtandil Kikabidze Date: Wed, 12 Sep 2018 18:20:33 +0400 Subject: [PATCH] Add more type hints --- src/Monolog/Formatter/ElasticaFormatter.php | 2 ++ src/Monolog/Formatter/ElasticsearchFormatter.php | 4 ++-- src/Monolog/Handler/ElasticaHandler.php | 4 ++-- src/Monolog/Handler/ElasticsearchHandler.php | 8 ++++---- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Monolog/Formatter/ElasticaFormatter.php b/src/Monolog/Formatter/ElasticaFormatter.php index a6354f50..128e07ab 100644 --- a/src/Monolog/Formatter/ElasticaFormatter.php +++ b/src/Monolog/Formatter/ElasticaFormatter.php @@ -65,6 +65,8 @@ class ElasticaFormatter extends NormalizerFormatter /** * Convert a log message into an Elastica Document + * @param array $record + * @return Document */ protected function getDocument(array $record): Document { diff --git a/src/Monolog/Formatter/ElasticsearchFormatter.php b/src/Monolog/Formatter/ElasticsearchFormatter.php index 682bdbe1..1667f2cc 100644 --- a/src/Monolog/Formatter/ElasticsearchFormatter.php +++ b/src/Monolog/Formatter/ElasticsearchFormatter.php @@ -34,7 +34,7 @@ class ElasticsearchFormatter extends NormalizerFormatter * @param string $index Elasticsearch index name * @param string $type Elasticsearch record type */ - public function __construct($index, $type) + public function __construct(string $index, string $type) { // Elasticsearch requires an ISO 8601 format date with optional millisecond precision. parent::__construct(DateTime::ISO8601); @@ -79,7 +79,7 @@ class ElasticsearchFormatter extends NormalizerFormatter * @param array $record Log message * @return array */ - protected function getDocument($record): array + protected function getDocument(array $record): array { $record['_index'] = $this->index; $record['_type'] = $this->type; diff --git a/src/Monolog/Handler/ElasticaHandler.php b/src/Monolog/Handler/ElasticaHandler.php index 876e15d3..4fedefc0 100644 --- a/src/Monolog/Handler/ElasticaHandler.php +++ b/src/Monolog/Handler/ElasticaHandler.php @@ -88,7 +88,7 @@ class ElasticaHandler extends AbstractProcessingHandler * Getter options * @return array */ - public function getOptions() + public function getOptions(): array { return $this->options; } @@ -115,7 +115,7 @@ class ElasticaHandler extends AbstractProcessingHandler * @param array $documents * @throws \RuntimeException */ - protected function bulkSend(array $documents) + protected function bulkSend(array $documents): void { try { $this->client->addDocuments($documents); diff --git a/src/Monolog/Handler/ElasticsearchHandler.php b/src/Monolog/Handler/ElasticsearchHandler.php index f733e4e5..690d7fee 100644 --- a/src/Monolog/Handler/ElasticsearchHandler.php +++ b/src/Monolog/Handler/ElasticsearchHandler.php @@ -59,7 +59,7 @@ class ElasticsearchHandler extends AbstractProcessingHandler * @param int $level The minimum logging level at which this handler will be triggered * @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not */ - public function __construct(Client $client, array $options = [], $level = Logger::DEBUG, $bubble = true) + public function __construct(Client $client, array $options = [], $level = Logger::DEBUG, bool $bubble = true) { parent::__construct($level, $bubble); $this->client = $client; @@ -76,7 +76,7 @@ class ElasticsearchHandler extends AbstractProcessingHandler /** * {@inheritDoc} */ - protected function write(array $record) + protected function write(array $record): void { $this->bulkSend([$record['formatted']]); } @@ -113,7 +113,7 @@ class ElasticsearchHandler extends AbstractProcessingHandler /** * {@inheritdoc} */ - public function handleBatch(array $records) + public function handleBatch(array $records): void { $documents = $this->getFormatter()->formatBatch($records); $this->bulkSend($documents); @@ -125,7 +125,7 @@ class ElasticsearchHandler extends AbstractProcessingHandler * @param array $records * @throws \RuntimeException */ - protected function bulkSend(array $records) + protected function bulkSend(array $records): void { try { $params = [