public function setStatusCode(int $code, string $text = null): Response
    {
        $this->statusCode = $code;

        // Check if the status code is valid
        if ($this->isInvalid()) {
            throw new InvalidStatusCodeException(
                sprintf('The HTTP status code "%s" is not valid.', $code)
            );
        }

        // If no text was supplied
        if (null === $text) {
            // Set the status text from the status texts array
            $this->statusText = StatusCode::TEXTS[$code] ?? 'unknown status';

            return $this;
        }

        $this->statusText = $text;

        return $this;
    }
public function setStatusCode(int $code, string $text = null): Response
    {
        $this->statusCode = $code;

        // Check if the status code is valid
        if ($this->isInvalid()) {
            throw new InvalidStatusCodeException(
                sprintf('The HTTP status code "%s" is not valid.', $code)
            );
        }

        // If no text was supplied
        if (null === $text) {
            // Set the status text from the status texts array
            $this->statusText = StatusCode::TEXTS[$code] ?? 'unknown status';

            return $this;
        }

        $this->statusText = $text;

        return $this;
    }
public function setStatusCode ( int $ code , string $ text = null ) : Response { $ this -> statusCode = $ code ; // Check if the status code is valid if ( $ this -> isInvalid ( ) ) { throw new InvalidStatusCodeException ( sprintf ( 'The HTTP status code "%s" is not valid.' , $ code ) ) ; } // If no text was supplied if ( null === $ text ) { // Set the status text from the status texts array $ this -> statusText = StatusCode :: TEXTS [ $ code ] ?? 'unknown status' ; return $ this ; } $ this -> statusText = $ text ; return $ this ; }
Sets the response status code.

@param int    $code HTTP status code
@param string $text [optional] HTTP status text

If the status text is null it will be automatically populated for the
known status codes and left empty otherwise.

@throws \Valkyrja\Http\Exceptions\InvalidStatusCodeException

@return \Valkyrja\Http\Response
Sets the response status code .