Skip to content

Commit

Permalink
Add type-hint on Result class (#1720)
Browse files Browse the repository at this point in the history
  • Loading branch information
deguif authored and ruflin committed Dec 3, 2019
1 parent 2f2115a commit bfd9e79
Showing 1 changed file with 13 additions and 38 deletions.
51 changes: 13 additions & 38 deletions lib/Elastica/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,8 @@ public function getParam($name)

/**
* Test if a param from the result hit is set.
*
* @param string $name Param name to test
*
* @return bool True if the param is set, false otherwise
*/
public function hasParam($name)
public function hasParam(string $name): bool
{
return isset($this->_hit[$name]);
}
Expand Down Expand Up @@ -84,20 +80,16 @@ public function getType()

/**
* Returns list of fields.
*
* @return array Fields list
*/
public function getFields()
public function getFields(): array
{
return $this->getParam('fields');
}

/**
* Returns whether result has fields.
*
* @return bool
*/
public function hasFields()
public function hasFields(): bool
{
return $this->hasParam('fields');
}
Expand All @@ -124,10 +116,8 @@ public function getScore()

/**
* Returns the raw hit array.
*
* @return array Hit array
*/
public function getHit()
public function getHit(): array
{
return $this->_hit;
}
Expand All @@ -144,20 +134,16 @@ public function getVersion()

/**
* Returns inner hits.
*
* @return array Fields list
*/
public function getInnerHits()
public function getInnerHits(): array
{
return $this->getParam('inner_hits');
}

/**
* Returns whether result has inner hits.
*
* @return bool
*/
public function hasInnerHits()
public function hasInnerHits(): bool
{
return $this->hasParam('inner_hits');
}
Expand All @@ -182,40 +168,32 @@ public function getData()

/**
* Returns the result source.
*
* @return array Source data array
*/
public function getSource()
public function getSource(): array
{
return $this->getParam('_source');
}

/**
* Returns result data.
*
* @return array Result data array
*/
public function getHighlights()
public function getHighlights(): array
{
return $this->getParam('highlight');
}

/**
* Returns explanation on how its score was computed.
*
* @return array explanations
*/
public function getExplanation()
public function getExplanation(): array
{
return $this->getParam('_explanation');
}

/**
* Returns Document.
*
* @return Document
*/
public function getDocument()
public function getDocument(): Document
{
$doc = new Document();
$doc->setData($this->getSource());
Expand All @@ -232,10 +210,9 @@ public function getDocument()
/**
* Sets a parameter on the hit.
*
* @param string $param
* @param mixed $value
* @param mixed $value
*/
public function setParam($param, $value)
public function setParam(string $param, $value)
{
$this->_hit[$param] = $value;
}
Expand All @@ -260,10 +237,8 @@ public function __get($key)
* Magic function to support isset() calls.
*
* @param string $key Key name
*
* @return bool
*/
public function __isset($key)
public function __isset($key): bool
{
$source = $this->getData();

Expand Down

0 comments on commit bfd9e79

Please sign in to comment.