Lukasoppermann\Httpstatus\Httpstatus::getReasonPhrase PHP Method

getReasonPhrase() public method

Get the text for a given status code.
public getReasonPhrase ( string $statusCode ) : string
$statusCode string http status code
return string Returns text for the given status code
    public function getReasonPhrase($statusCode)
    {
        $statusCode = $this->filterStatusCode($statusCode);
        if (!isset($this->httpStatus[$statusCode])) {
            throw new OutOfBoundsException(sprintf('Unknown http status code: `%s`', $statusCode));
        }
        return $this->httpStatus[$statusCode];
    }

Usage Example

 /**
  * Sends fail response
  * @param $data
  * @author Oluwarotimi Akintewe <*****@*****.**>
  * @author Adegoke Obasa <*****@*****.**>
  * @param int $httpStatusCode
  * @return array
  */
 public function sendFailResponse($data, $httpStatusCode = 500)
 {
     \Yii::$app->response->format = Response::FORMAT_JSON;
     \Yii::$app->response->setStatusCode($httpStatusCode, $this->httpStatuses->getReasonPhrase($httpStatusCode));
     return ['status' => 'fail', 'data' => $data];
 }