Skip to content

Commit 985e7a5

Browse files
authored
Merge pull request #1653 from deguif/type-hint-client-signatures
Add type-hints on signatures of client and logger methods
2 parents 6a369a2 + 6238ea9 commit 985e7a5

File tree

3 files changed

+13
-29
lines changed

3 files changed

+13
-29
lines changed

CHANGELOG-6.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ in 6.0 versions.
1717
* [BC break] Signature of methods `getPager`, `getOptions` and `getObjectPersister` from interface `FOS\ElasticaBundle\Persister\Event\PersistEvent` were changed.
1818
* [BC break] Signature of methods `getNbResults`, `getNbPages`, `getCurrentPage`, `setCurrentPage`, `getMaxPerPage` and `setMaxPerPage` from interface `FOS\ElasticaBundle\Provider\PagerInterface` were changed.
1919
* [BC break] Signature of methods `findPaginated`, `createPaginatorAdapter` and `createRawPaginatorAdapter` from interface `FOS\ElasticaBundle\Finder\PaginatedFinderInterface` were changed.
20+
* [BC break] Signature of methods `request`, `getIndex`, `getIndexTemplate` and `setStopwatch` from class `FOS\ElasticaBundle\Elastica\Client` were changed.
21+
* [BC break] Signature of methods `logQuery`, `getNbQueries` and `getQueries` from class `FOS\ElasticaBundle\Logger\ElasticaLogger` were changed.
2022
* [BC break] Removed `Elastica\Type`.
2123
* [BC break] Removed `_parent`.
2224
* [BC Break] Removed `FOS\ElasticaBundle\Persister\Event\Events` class, use class events instead.

src/Elastica/Client.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Client extends BaseClient
5151
/**
5252
* {@inheritdoc}
5353
*/
54-
public function request($path, $method = Request::GET, $data = [], array $query = [], $contentType = Request::DEFAULT_CONTENT_TYPE): Response
54+
public function request(string $path, string $method = Request::GET, $data = [], array $query = [], string $contentType = Request::DEFAULT_CONTENT_TYPE): Response
5555
{
5656
if ($this->stopwatch) {
5757
$this->stopwatch->start('es_request', 'fos_elastica');
@@ -92,7 +92,7 @@ public function getIndex(string $name): BaseIndex
9292
return $this->indexCache[$name] = new Index($this, $name);
9393
}
9494

95-
public function getIndexTemplate($name)
95+
public function getIndexTemplate($name): IndexTemplate
9696
{
9797
if (isset($this->indexTemplateCache[$name])) {
9898
return $this->indexTemplateCache[$name];
@@ -103,27 +103,22 @@ public function getIndexTemplate($name)
103103

104104
/**
105105
* Sets a stopwatch instance for debugging purposes.
106-
*
107-
* @param Stopwatch $stopwatch
108106
*/
109-
public function setStopwatch(Stopwatch $stopwatch = null)
107+
public function setStopwatch(?Stopwatch $stopwatch = null)
110108
{
111109
$this->stopwatch = $stopwatch;
112110
}
113111

114112
/**
115113
* Log the query if we have an instance of ElasticaLogger.
116114
*
117-
* @param string $path
118-
* @param string $method
119115
* @param array|string $data
120116
* @param int $queryTime
121117
* @param int $engineMS
122-
* @param int $itemCount
123118
*/
124-
private function logQuery($path, $method, $data, array $query, $queryTime, $engineMS = 0, $itemCount = 0): void
119+
private function logQuery(string $path, string $method, $data, array $query, $queryTime, $engineMS = 0, int $itemCount = 0): void
125120
{
126-
if (!$this->_logger or !$this->_logger instanceof ElasticaLogger) {
121+
if (!$this->_logger instanceof ElasticaLogger) {
127122
return;
128123
}
129124

@@ -136,8 +131,6 @@ private function logQuery($path, $method, $data, array $query, $queryTime, $engi
136131
'headers' => $connection->hasConfig('headers') ? $connection->getConfig('headers') : [],
137132
];
138133

139-
/** @var ElasticaLogger $logger */
140-
$logger = $this->_logger;
141-
$logger->logQuery($path, $method, $data, $queryTime, $connectionArray, $query, $engineMS, $itemCount);
134+
$this->_logger->logQuery($path, $method, $data, $queryTime, $connectionArray, $query, $engineMS, $itemCount);
142135
}
143136
}

src/Logger/ElasticaLogger.php

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,7 @@ class ElasticaLogger extends AbstractLogger
3939
*/
4040
protected $debug;
4141

42-
/**
43-
* Constructor.
44-
*
45-
* @param LoggerInterface|null $logger The Symfony logger
46-
* @param bool $debug
47-
*/
48-
public function __construct(LoggerInterface $logger = null, $debug = false)
42+
public function __construct(?LoggerInterface $logger = null, bool $debug = false)
4943
{
5044
$this->logger = $logger;
5145
$this->debug = $debug;
@@ -61,9 +55,8 @@ public function __construct(LoggerInterface $logger = null, $debug = false)
6155
* @param array $connection Host, port, transport, and headers of the query
6256
* @param array $query Arguments
6357
* @param int $engineTime
64-
* @param int $itemCount
6558
*/
66-
public function logQuery($path, $method, $data, $queryTime, $connection = [], $query = [], $engineTime = 0, $itemCount = 0)
59+
public function logQuery(string $path, string $method, $data, $queryTime, $connection = [], $query = [], $engineTime = 0, int $itemCount = 0)
6760
{
6861
$executionMS = $queryTime * 1000;
6962

@@ -102,20 +95,16 @@ public function logQuery($path, $method, $data, $queryTime, $connection = [], $q
10295

10396
/**
10497
* Returns the number of queries that have been logged.
105-
*
106-
* @return int The number of queries logged
10798
*/
108-
public function getNbQueries()
99+
public function getNbQueries(): int
109100
{
110101
return count($this->queries);
111102
}
112103

113104
/**
114105
* Returns a human-readable array of queries logged.
115-
*
116-
* @return array An array of queries
117106
*/
118-
public function getQueries()
107+
public function getQueries(): array
119108
{
120109
return $this->queries;
121110
}
@@ -125,7 +114,7 @@ public function getQueries()
125114
*/
126115
public function log($level, $message, array $context = [])
127116
{
128-
return $this->logger->log($level, $message, $context);
117+
$this->logger->log($level, $message, $context);
129118
}
130119

131120
public function reset()

0 commit comments

Comments
 (0)