Skip to content

Commit

Permalink
Merge pull request #40 from BedrockStreaming/fix/type-reenforcement
Browse files Browse the repository at this point in the history
  • Loading branch information
Yokann committed Aug 8, 2023
2 parents 1f4014e + 12d5c0f commit 4b1d8b9
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 230 deletions.
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
"require": {
"php": ">=7.4",
"ext-json": "*",
"elasticsearch/elasticsearch": "^5.1.0||^6.0.0||^7.0"
"elasticsearch/elasticsearch": "^5.1.0||^6.0.0||^7.0",
"symfony/event-dispatcher": "^4.4||^5.0||^6.0",
"symfony/yaml": "^4.4||^5.0||^6.0",
"symfony/http-foundation": "^4.4||^5.0||^6.0",
"symfony/config": "^4.4||^5.0||^6.0",
"symfony/http-kernel": "^4.4||^5.0||^6.0",
"symfony/dependency-injection": "^4.4||^5.0||^6.0"
},
"require-dev": {
"atoum/atoum": "^4.0",
"m6web/php-cs-fixer-config": "^2.0",
"symfony/dependency-injection": "^4.4||^5.0||^6.0",
"symfony/event-dispatcher": "^4.4||^5.0||^6.0",
"symfony/config": "^4.4||^5.0||^6.0",
"symfony/yaml": "^4.4||^5.0||^6.0",
"symfony/http-foundation": "^4.4||^5.0||^6.0",
"symfony/http-kernel": "^4.4||^5.0||^6.0"
"atoum/atoum": "^4.0",
"m6web/php-cs-fixer-config": "^2.0"
},
"autoload": {
"psr-0": { "": "src/" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,17 @@ public function collect(Request $request, Response $response, \Throwable $except
/**
* {@inheritdoc}
*/
public function getName()
public function getName(): string
{
return 'elasticsearch';
}

/**
* Get queries
*
* @return array
*/
public function getQueries()
public function getQueries(): array
{
return $this->data['queries'];
}

/**
* Get total execution time
*
* @return float
*/
public function getTotalExecutionTime()
public function getTotalExecutionTime(): float
{
return $this->data['total_execution_time'];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Configuration implements ConfigurationInterface
/**
* {@inheritDoc}
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('m6web_elasticsearch');
$rootNode = $treeBuilder->getRootNode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,8 @@ protected function createElasticsearchClient(ContainerBuilder $container, $name,

/**
* Create request handler
*
* @param string $definitionId
*
* @return string
*/
protected function createHandler(ContainerBuilder $container, array $config, $definitionId)
protected function createHandler(ContainerBuilder $container, array $config, string $definitionId): string
{
// cURL handler
$singleHandler = (new Definition('GuzzleHttp\Ring\Client\CurlHandler'))
Expand Down Expand Up @@ -136,11 +132,7 @@ protected function createHandler(ContainerBuilder $container, array $config, $de
return $eventHandlerId;
}

/**
* @param string $className
* @param string $method
*/
private function setFactoryToDefinition($className, $method, Definition $definition)
private function setFactoryToDefinition(string $className, string $method, Definition $definition)
{
$definition
->setFactory([$className, $method]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,29 @@
*/
class StaticAliveNoPingConnectionPool extends StaticNoPingConnectionPool
{
/** @var int */
private $pingTimeout = 60;

/** @var int */
private $maxPingTimeout = 3600;
private int $pingTimeout = 60;
private int $maxPingTimeout = 3600;

/**
* > Allow to customize the ping time out.
*
* @param int $pingTimeout
*/
public function setPingTimeout($pingTimeout)
public function setPingTimeout(int $pingTimeout)
{
$this->pingTimeout = $pingTimeout;
}

/**
* > Allow to customize the ping max time out.
*
* @param int $maxPingTimeout
*/
public function setMaxPingTimeout($maxPingTimeout)
public function setMaxPingTimeout(int $maxPingTimeout)
{
$this->maxPingTimeout = $maxPingTimeout;
}

/**
* @param bool $force
*
* @return Connection
*
* @throws \Elasticsearch\Common\Exceptions\NoNodesAvailableException
* @throws NoNodesAvailableException
*/
public function nextConnection($force = false): ConnectionInterface
public function nextConnection(bool $force = false): ConnectionInterface
{
// > Replace $this->connections by $connections in order to modify the list later.
$connections = $this->connections;
Expand Down Expand Up @@ -80,10 +69,8 @@ function ($baseConnection) use ($connection) {

/**
* > Same as parent private method.
*
* @return bool
*/
protected function readyToRevive(Connection $connection)
protected function readyToRevive(Connection $connection): bool
{
$timeout = min(
$this->pingTimeout * pow(2, $connection->getPingFailures()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,201 +6,118 @@

use Symfony\Contracts\EventDispatcher\Event;

/**
* Class ElasticsearchEvent
*/
class ElasticsearchEvent extends Event
{
/** @var float duration of the Elasticsearch request in milliseconds */
private $duration;
/** duration of the Elasticsearch request in milliseconds */
private ?float $duration = null;

/** @var string HTTP method */
private $method;
/** HTTP method */
private ?string $method = null;

/** @var string Elasticsearch URI */
private $uri;
/** Elasticsearch URI */
private ?string $uri = null;

/** @var int HTTP status code */
private $statusCode;
/** HTTP status code */
private ?int $statusCode = null;

/**
* Time in milliseconds for Elasticsearch to execute the search
*
* @var int
*/
private $took;
/** Time in milliseconds for Elasticsearch to execute the search */
private ?int $took = null;
private array $headers = [];

/** @var array */
private $headers;
/** Body of the ES request */
private string $body = '';
private string $error = '';

/**
* Body of the ES request
*
* @var string
*/
private $body;

/** @var string */
private $error;

/**
* @return float
*/
public function getDuration()
public function getDuration(): ?float
{
return $this->duration;
}

/**
* @param float $duration
*
* @return $this
*/
public function setDuration($duration)
public function setDuration(float $duration): self
{
$this->duration = $duration;

return $this;
}

/**
* @return string
*/
public function getMethod()
public function getMethod(): ?string
{
return $this->method;
}

/**
* @param string $method
*
* @return $this
*/
public function setMethod($method)
public function setMethod(?string $method): self
{
$this->method = $method;

return $this;
}

/**
* @return string
*/
public function getUri()
public function getUri(): ?string
{
return $this->uri;
}

/**
* @param string $uri
*
* @return $this
*/
public function setUri($uri)
public function setUri(?string $uri): self
{
$this->uri = $uri;

return $this;
}

/**
* @return int
*/
public function getStatusCode()
public function getStatusCode(): ?int
{
return $this->statusCode;
}

/**
* @param int $statusCode
*
* @return $this
*/
public function setStatusCode($statusCode)
public function setStatusCode(?int $statusCode): self
{
$this->statusCode = $statusCode;

return $this;
}

/**
* Get took
*
* @return int
*/
public function getTook()
public function getTook(): ?int
{
return $this->took;
}

/**
* Set took
*
* @param int $took
*
* @return $this
*/
public function setTook($took)
public function setTook(?int $took): self
{
$this->took = $took;

return $this;
}

/**
* @return array
*/
public function getHeaders()
public function getHeaders(): array
{
return $this->headers;
}

/**
* @param array $headers
*
* @return $this
*/
public function setHeaders($headers)
public function setHeaders(array $headers): self
{
$this->headers = $headers;

return $this;
}

/**
* @return string
*/
public function getBody()
public function getBody(): string
{
return $this->body;
}

/**
* @param string $body
*
* @return $this
*/
public function setBody($body)
public function setBody(string $body): self
{
$this->body = $body;

return $this;
}

/**
* @return string
*/
public function getError()
public function getError(): string
{
return $this->error;
}

/**
* @param string $error
*
* @return $this
*/
public function setError($error)
public function setError(string $error): self
{
$this->error = $error;

Expand Down

0 comments on commit 4b1d8b9

Please sign in to comment.