Skip to content

Commit

Permalink
Attempt to automate adding all type hints to remove warnings
Browse files Browse the repository at this point in the history
Used IntelliJ and a PHP plugin to automate all of this w/ some manual intervention in the BXML library
  • Loading branch information
ajrice6713 committed May 17, 2023
1 parent 82561ac commit d2d385d
Show file tree
Hide file tree
Showing 40 changed files with 1,089 additions and 410 deletions.
30 changes: 15 additions & 15 deletions src/APIHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class APIHelper
{
/**
* Replaces template parameters in the given url
* @param string $url The query string builder to replace the template parameters
* @param array $parameters The parameters to replace in the url
* @param string $url The query string builder to replace the template parameters
* @param array $parameters The parameters to replace in the url
* @return string The processed url
*/
public static function appendUrlWithTemplateParameters($url, $parameters, $encode = true)
public static function appendUrlWithTemplateParameters(string $url, array $parameters, $encode = true): string
{
//perform parameter validation
if (is_null($url) || !is_string($url)) {
Expand Down Expand Up @@ -55,11 +55,11 @@ public static function appendUrlWithTemplateParameters($url, $parameters, $encod

/**
* Appends the given set of parameters to the given query string
* @param string $queryBuilder The query url string to append the parameters
* @param array $parameters The parameters to append
* @param string $queryBuilder The query url string to append the parameters
* @param array $parameters The parameters to append
* @return void
*/
public static function appendUrlWithQueryParameters(&$queryBuilder, $parameters)
public static function appendUrlWithQueryParameters(string &$queryBuilder, array $parameters)
{
//perform parameter validation
if (is_null($queryBuilder) || !is_string($queryBuilder)) {
Expand All @@ -80,9 +80,9 @@ public static function appendUrlWithQueryParameters(&$queryBuilder, $parameters)

/**
* Validates and processes the given Url
* @param string $url The given Url to process
* @param string $url The given Url to process
* @return string Pre-processed Url as string */
public static function cleanUrl($url)
public static function cleanUrl(string $url): string
{
//perform parameter validation
if (is_null($url) || !is_string($url)) {
Expand All @@ -106,12 +106,12 @@ public static function cleanUrl($url)

/**
* Deserialize a Json string
* @param string $json A valid Json string
* @param string $json A valid Json string
* @param mixed $instance Instance of an object to map the json into
* @param boolean $isArray Is the Json an object array?
* @param boolean $isArray Is the Json an object array?
* @return mixed Decoded Json
*/
public static function deserialize($json, $instance = null, $isArray = false)
public static function deserialize(string $json, $instance = null, bool $isArray = false)
{
if ($instance == null) {
return json_decode($json, true);
Expand All @@ -127,10 +127,10 @@ public static function deserialize($json, $instance = null, $isArray = false)

/**
* Check if an array isAssociative (has string keys)
* @param array $arr A valid array
* @param array $arr A valid array
* @return boolean True if the array is Associative, false if it is Indexed
*/
private static function isAssociative($arr)
private static function isAssociative(array $arr): bool
{
foreach ($arr as $key => $value) {
if (is_string($key)) {
Expand All @@ -143,10 +143,10 @@ private static function isAssociative($arr)

/**
* Prepare a model for form encoding
* @param JsonSerializable $model A valid instance of JsonSerializable
* @param JsonSerializable $model A valid instance of JsonSerializable
* @return array The model as a map of key value pairs
*/
public static function prepareFormFields($model)
public static function prepareFormFields(JsonSerializable $model)
{
if (!$model instanceof JsonSerializable) {
return $model;
Expand Down
4 changes: 2 additions & 2 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,10 @@ public function getBaseUrl()

/**
* Get the base uri for a given server in the current environment
* @param string $server Server name
* @param string $server Server name
* @return string Base URI
*/
public function getBaseUri($server = Servers::DEFAULT_)
public function getBaseUri(string $server = Servers::DEFAULT_)
{
return APIHelper::appendUrlWithTemplateParameters(
static::$environmentsMap[$this->environment][$server],
Expand Down
4 changes: 2 additions & 2 deletions src/Http/ApiResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class ApiResponse

/**
* Create a new instance of a HttpResponse
* @param int $statusCode Response code
* @param int $statusCode Response code
* @param array $headers Map of headers
* @param mixed $result The deserialized response
*/
public function __construct($statusCode, array $headers, $result)
public function __construct(int $statusCode, array $headers, $result)
{
$this->statusCode = $statusCode;
$this->headers = $headers;
Expand Down
12 changes: 6 additions & 6 deletions src/Http/HttpRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ class HttpRequest

/**
* Create a new HttpRequest
* @param string $httpMethod Http method
* @param string|null $httpMethod Http method
* @param array|null $headers Map of headers
* @param string $queryUrl Query url
* @param string|null $queryUrl Query url
* @param array|null $parameters Map of parameters sent
*/
public function __construct($httpMethod = null, array $headers = null, $queryUrl = null, array $parameters = null)
public function __construct(string $httpMethod = null, array $headers = null, string $queryUrl = null, array $parameters = null)
{
$this->httpMethod = $httpMethod;
$this->headers = $headers;
Expand All @@ -64,7 +64,7 @@ public function getHttpMethod()
* Set http method
* @param string $httpMethod Http Method as defined in HttpMethod class
*/
public function setHttpMethod($httpMethod)
public function setHttpMethod(string $httpMethod)
{
$this->httpMethod = $httpMethod;
}
Expand Down Expand Up @@ -100,7 +100,7 @@ public function getQueryUrl()
* Set query url
* @param string $queryUrl Query url
*/
public function setQueryUrl($queryUrl)
public function setQueryUrl(string $queryUrl)
{
$this->queryUrl = $queryUrl;
}
Expand All @@ -118,7 +118,7 @@ public function getParameters()
* Set parameters
* @param array $parameters Map of input parameters
*/
public function setParameters($parameters)
public function setParameters(array $parameters)
{
$this->parameters = $parameters;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Http/HttpResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class HttpResponse

/**
* Create a new instance of a HttpResponse
* @param int $statusCode Response code
* @param int $statusCode Response code
* @param array $headers Map of headers
* @param string $rawBody Raw response body
*/
public function __construct($statusCode, array $headers, $rawBody)
public function __construct(int $statusCode, array $headers, string $rawBody)
{
$this->statusCode = $statusCode;
$this->headers = $headers;
Expand Down
72 changes: 36 additions & 36 deletions src/Messaging/Controllers/APIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ public function __construct($config, $httpCallBack = null)
* Gets a list of your media files. No query parameters are supported.
*
* @param string $accountId User's account ID
* @param string $continuationToken (optional) Continuation token used to retrieve subsequent media.
* @param string|null $continuationToken (optional) Continuation token used to retrieve subsequent media.
* @return ApiResponse response from the API call
* @throws APIException Thrown if API call fails
*/
public function listMedia(
$accountId,
$continuationToken = null
string $accountId,
string $continuationToken = null
) {

//prepare query string for API call
Expand Down Expand Up @@ -128,8 +128,8 @@ public function listMedia(
* @throws APIException Thrown if API call fails
*/
public function getMedia(
$accountId,
$mediaId
string $accountId,
string $mediaId
) {

//prepare query string for API call
Expand Down Expand Up @@ -215,17 +215,17 @@ public function getMedia(
* @param string $mediaId The user supplied custom media ID
* @param string $body TODO: type description here
* @param string $contentType (optional) The media type of the entity-body
* @param string $cacheControl (optional) General-header field is used to specify directives that MUST be obeyed
* @param string|null $cacheControl (optional) General-header field is used to specify directives that MUST be obeyed
* by all caching mechanisms along the request/response chain.
* @return ApiResponse response from the API call
* @throws APIException Thrown if API call fails
*/
public function uploadMedia(
$accountId,
$mediaId,
$body,
$contentType = 'application/octet-stream',
$cacheControl = null
string $accountId,
string $mediaId,
string $body,
string $contentType = 'application/octet-stream',
string $cacheControl = null
) {

//prepare query string for API call
Expand Down Expand Up @@ -318,8 +318,8 @@ public function uploadMedia(
* @throws APIException Thrown if API call fails
*/
public function deleteMedia(
$accountId,
$mediaId
string $accountId,
string $mediaId
) {

//prepare query string for API call
Expand Down Expand Up @@ -399,35 +399,35 @@ public function deleteMedia(
/**
* Gets a list of messages based on query parameters.
*
* @param string $accountId User's account ID
* @param string $messageId (optional) The ID of the message to search for. Special characters need to be
* @param string $accountId User's account ID
* @param string|null $messageId (optional) The ID of the message to search for. Special characters need to be
* encoded using URL encoding
* @param string $sourceTn (optional) The phone number that sent the message
* @param string $destinationTn (optional) The phone number that received the message
* @param string $messageStatus (optional) The status of the message. One of RECEIVED, QUEUED, SENDING, SENT,
* @param string|null $sourceTn (optional) The phone number that sent the message
* @param string|null $destinationTn (optional) The phone number that received the message
* @param string|null $messageStatus (optional) The status of the message. One of RECEIVED, QUEUED, SENDING, SENT,
* FAILED, DELIVERED, ACCEPTED, UNDELIVERED
* @param integer $errorCode (optional) The error code of the message
* @param string $fromDateTime (optional) The start of the date range to search in ISO 8601 format. Uses the
* @param integer|null $errorCode (optional) The error code of the message
* @param string|null $fromDateTime (optional) The start of the date range to search in ISO 8601 format. Uses the
* message receive time. The date range to search in is currently 14 days.
* @param string $toDateTime (optional) The end of the date range to search in ISO 8601 format. Uses the
* @param string|null $toDateTime (optional) The end of the date range to search in ISO 8601 format. Uses the
* message receive time. The date range to search in is currently 14 days.
* @param string $pageToken (optional) A base64 encoded value used for pagination of results
* @param integer $limit (optional) The maximum records requested in search result. Default 100. The sum of
* @param string|null $pageToken (optional) A base64 encoded value used for pagination of results
* @param integer|null $limit (optional) The maximum records requested in search result. Default 100. The sum of
* limit and after cannot be more than 10000
* @return ApiResponse response from the API call
* @throws APIException Thrown if API call fails
*/
public function getMessages(
$accountId,
$messageId = null,
$sourceTn = null,
$destinationTn = null,
$messageStatus = null,
$errorCode = null,
$fromDateTime = null,
$toDateTime = null,
$pageToken = null,
$limit = null
string $accountId,
string $messageId = null,
string $sourceTn = null,
string $destinationTn = null,
string $messageStatus = null,
int $errorCode = null,
string $fromDateTime = null,
string $toDateTime = null,
string $pageToken = null,
int $limit = null
) {

//prepare query string for API call
Expand Down Expand Up @@ -524,14 +524,14 @@ public function getMessages(
/**
* Endpoint for sending text messages and picture messages using V2 messaging.
*
* @param string $accountId User's account ID
* @param string $accountId User's account ID
* @param Models\MessageRequest $body TODO: type description here
* @return ApiResponse response from the API call
* @throws APIException Thrown if API call fails
*/
public function createMessage(
$accountId,
$body
string $accountId,
Models\MessageRequest $body
) {

//prepare query string for API call
Expand Down
18 changes: 9 additions & 9 deletions src/MultiFactorAuth/Controllers/MFAController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ public function __construct($config, $httpCallBack = null)
* Multi-Factor authentication with Bandwidth Voice services. Allows for a user to send an MFA code via
* a phone call.
*
* @param string $accountId Bandwidth Account ID with Voice service enabled
* @param string $accountId Bandwidth Account ID with Voice service enabled
* @param Models\TwoFactorCodeRequestSchema $body TODO: type description here
* @return ApiResponse response from the API call
* @throws APIException Thrown if API call fails
*/
public function createVoiceTwoFactor(
$accountId,
$body
string $accountId,
Models\TwoFactorCodeRequestSchema $body
) {

//prepare query string for API call
Expand Down Expand Up @@ -128,14 +128,14 @@ public function createVoiceTwoFactor(
* Multi-Factor authentication with Bandwidth Messaging services. Allows a user to send an MFA code via
* a text message (SMS).
*
* @param string $accountId Bandwidth Account ID with Messaging service enabled
* @param string $accountId Bandwidth Account ID with Messaging service enabled
* @param Models\TwoFactorCodeRequestSchema $body TODO: type description here
* @return ApiResponse response from the API call
* @throws APIException Thrown if API call fails
*/
public function createMessagingTwoFactor(
$accountId,
$body
string $accountId,
Models\TwoFactorCodeRequestSchema $body
) {

//prepare query string for API call
Expand Down Expand Up @@ -221,14 +221,14 @@ public function createMessagingTwoFactor(
/**
* Allows a user to verify an MFA code.
*
* @param string $accountId Bandwidth Account ID with Two-Factor enabled
* @param string $accountId Bandwidth Account ID with Two-Factor enabled
* @param Models\TwoFactorVerifyRequestSchema $body TODO: type description here
* @return ApiResponse response from the API call
* @throws APIException Thrown if API call fails
*/
public function createVerifyTwoFactor(
$accountId,
$body
string $accountId,
Models\TwoFactorVerifyRequestSchema $body
) {

//prepare query string for API call
Expand Down
4 changes: 4 additions & 0 deletions src/MultiFactorAuth/Models/TwoFactorVerifyRequestSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class TwoFactorVerifyRequestSchema implements \JsonSerializable
* @var string $code public property
*/
public $code;
/**
* @var int
*/
public $digits;

/**
* Constructor to set initial or default values of member properties
Expand Down
10 changes: 5 additions & 5 deletions src/PhoneNumberLookup/Controllers/APIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public function __construct($config, $httpCallBack = null)
/**
* Create a TN Lookup Order.
*
* @param string $accountId The ID of the Bandwidth account that the user belongs to.
* @param string $accountId The ID of the Bandwidth account that the user belongs to.
* @param Models\OrderRequest $body TODO: type description here
* @return ApiResponse response from the API call
* @throws APIException Thrown if API call fails
*/
public function createLookupRequest(
$accountId,
$body
string $accountId,
Models\OrderRequest $body
) {

//prepare query string for API call
Expand Down Expand Up @@ -939,8 +939,8 @@ public function createLookupRequest(
* @throws APIException Thrown if API call fails
*/
public function getLookupRequestStatus(
$accountId,
$requestId
string $accountId,
string $requestId
) {

//prepare query string for API call
Expand Down
Loading

0 comments on commit d2d385d

Please sign in to comment.