Skip to content

Commit

Permalink
Merge pull request #292 from TomA-R/phpstan_issues
Browse files Browse the repository at this point in the history
Fix various codestyle issues
  • Loading branch information
TomA-R authored May 18, 2023
2 parents b1e8767 + 183bdf9 commit 257ce41
Show file tree
Hide file tree
Showing 17 changed files with 211 additions and 732 deletions.
711 changes: 3 additions & 708 deletions .phpstan/baseline.neon

Large diffs are not rendered by default.

31 changes: 23 additions & 8 deletions src/Bigcommerce/Api/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Client
/**
* Connection instance
*
* @var Connection
* @var Connection|false
*/
private static $connection;

Expand All @@ -59,12 +59,19 @@ class Client
* @var string
*/
public static $api_path;
/** @var string The OAuth client ID */
private static $client_id;
/** @var string The store hash */
private static $store_hash;
/** @var string The OAuth Auth-Token */
private static $auth_token;
/** @var string */
private static $client_secret;
/** @var string URL pathname prefix for the V2 API */
private static $stores_prefix = '/stores/%s/v2';
/** @var string The BigCommerce store management API host */
private static $api_url = 'https://api.bigcommerce.com';
/** @var string The BigCommerce merchant login URL */
private static $login_url = 'https://login.bigcommerce.com';

/**
Expand All @@ -73,7 +80,7 @@ class Client
*
* Accepts OAuth and (for now!) Basic Auth credentials
*
* @param array $settings
* @param array<string, string> $settings
* @return void
*/
public static function configure($settings)
Expand All @@ -94,7 +101,8 @@ public static function configure($settings)
* - auth_token
* - store_hash
*
* @param array $settings
* @param array<string, string> $settings
* @return void
* @throws \Exception
*/
public static function configureOAuth($settings)
Expand All @@ -111,7 +119,7 @@ public static function configureOAuth($settings)
self::$auth_token = $settings['auth_token'];
self::$store_hash = $settings['store_hash'];

self::$client_secret = isset($settings['client_secret']) ? $settings['client_secret'] : null;
self::$client_secret = $settings['client_secret'] ?? null;

self::$api_path = self::$api_url . sprintf(self::$stores_prefix, self::$store_hash);
self::$connection = false;
Expand All @@ -126,7 +134,8 @@ public static function configureOAuth($settings)
* - username
* - api_key
*
* @param array $settings
* @param array<string, string> $settings
* @return void
* @throws \Exception
*/
public static function configureBasicAuth(array $settings)
Expand Down Expand Up @@ -156,6 +165,7 @@ public static function configureBasicAuth(array $settings)
* Note that network faults will always cause an exception to be thrown.
*
* @param bool $option sets the value of this flag
* @return void
*/
public static function failOnError($option = true)
{
Expand All @@ -164,6 +174,7 @@ public static function failOnError($option = true)

/**
* Return XML strings from the API instead of building objects.
* @return void
*/
public static function useXml()
{
Expand All @@ -173,6 +184,7 @@ public static function useXml()
/**
* Return JSON objects from the API instead of XML Strings.
* This is the default behavior.
* @return void
*/
public static function useJson()
{
Expand All @@ -183,6 +195,7 @@ public static function useJson()
* Switch SSL certificate verification on requests.
*
* @param bool $option sets the value of this flag
* @return void
*/
public static function verifyPeer($option = false)
{
Expand All @@ -194,6 +207,7 @@ public static function verifyPeer($option = false)
*
* @param string $host host server
* @param int|bool $port port number to use, or false
* @return void
*/
public static function useProxy($host, $port = false)
{
Expand Down Expand Up @@ -244,7 +258,8 @@ public static function getConnection()
/**
* Set the HTTP connection object. DANGER: This can screw up your Client!
*
* @param Connection $connection The connection to use
* @param Connection|null $connection The connection to use
* @return void
*/
public static function setConnection(Connection $connection = null)
{
Expand Down Expand Up @@ -343,8 +358,8 @@ public static function deleteResource($path)
* Internal method to wrap items in a collection to resource classes.
*
* @param string $resource name of the resource class
* @param array $object object collection
* @return array
* @param mixed $object object collection
* @return Resource[]
*/
private static function mapCollection($resource, $object)
{
Expand Down
34 changes: 26 additions & 8 deletions src/Bigcommerce/Api/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Bigcommerce\Api;

use CurlHandle;

/**
* HTTP connection.
*/
Expand All @@ -21,17 +23,17 @@ class Connection
const MEDIA_TYPE_WWW = 'application/x-www-form-urlencoded';

/**
* @var resource cURL resource
* @var CurlHandle cURL resource
*/
private $curl;

/**
* @var array Hash of HTTP request headers.
* @var array<string, string> Hash of HTTP request headers.
*/
private $headers = [];

/**
* @var array Hash of headers from HTTP response
* @var array<string, string> Hash of headers from HTTP response
*/
private $responseHeaders = [];

Expand Down Expand Up @@ -78,11 +80,13 @@ class Connection

/**
* Determines whether the response body should be returned as a raw string.
* @var bool
*/
private $rawResponse = false;

/**
* Determines the default content type to use with requests and responses.
* @var string
*/
private $contentType;

Expand Down Expand Up @@ -134,6 +138,7 @@ public function useXml($option = true)
* as urlencoded form data.
*
* @param bool $option the new state of this feature
* @return void
*/
public function useUrlEncoded($option = true)
{
Expand All @@ -156,6 +161,7 @@ public function useUrlEncoded($option = true)
* as this fails fast, making the HTTP body and headers inaccessible.</em></p>
*
* @param bool $option the new state of this feature
* @return void
*/
public function failOnError($option = true)
{
Expand All @@ -167,6 +173,7 @@ public function failOnError($option = true)
*
* @param string $username
* @param string $password
* @return void
*/
public function authenticateBasic($username, $password)
{
Expand All @@ -178,6 +185,7 @@ public function authenticateBasic($username, $password)
*
* @param string $clientId
* @param string $authToken
* @return void
*/
public function authenticateOauth($clientId, $authToken)
{
Expand All @@ -190,6 +198,7 @@ public function authenticateOauth($clientId, $authToken)
* request takes longer than this to respond.
*
* @param int $timeout number of seconds to wait on a response
* @return void
*/
public function setTimeout($timeout)
{
Expand All @@ -202,6 +211,7 @@ public function setTimeout($timeout)
*
* @param string $server
* @param int|bool $port optional port number
* @return void
*/
public function useProxy($server, $port = false)
{
Expand All @@ -214,7 +224,8 @@ public function useProxy($server, $port = false)

/**
* @todo may need to handle CURLOPT_SSL_VERIFYHOST and CURLOPT_CAINFO as well
* @param boolean
* @param bool $option Whether to verify the peer's SSL certificate
* @return void
*/
public function verifyPeer($option = false)
{
Expand All @@ -226,6 +237,7 @@ public function verifyPeer($option = false)
*
* @param string $header
* @param string $value
* @return void
*/
public function addHeader($header, $value)
{
Expand All @@ -236,6 +248,7 @@ public function addHeader($header, $value)
* Remove a header from the request.
*
* @param string $header
* @return void
*/
public function removeHeader($header)
{
Expand All @@ -245,7 +258,7 @@ public function removeHeader($header)
/**
* Return the request headers
*
* @return array
* @return array<string, string>
*/
public function getRequestHeaders()
{
Expand All @@ -256,6 +269,7 @@ public function getRequestHeaders()
* Get the MIME type that should be used for this request.
*
* Defaults to application/json
* @return string
*/
private function getContentType()
{
Expand All @@ -265,6 +279,7 @@ private function getContentType()
/**
* Clear previously cached request data and prepare for
* making a fresh request.
* @return void
*/
private function initializeRequest()
{
Expand Down Expand Up @@ -324,6 +339,7 @@ private function handleResponse()
/**
* Return an representation of an error returned by the last request, or false
* if the last request was not an error.
* @return false|string
*/
public function getLastError()
{
Expand All @@ -336,6 +352,7 @@ public function getLastError()
*
* Only 301 and 302 redirects are handled. Redirects from POST and PUT requests will
* be converted into GET requests, as per the HTTP spec.
* @return void
*/
private function followRedirectPath()
{
Expand Down Expand Up @@ -367,7 +384,7 @@ private function followRedirectPath()
* Make an HTTP GET request to the specified endpoint.
*
* @param string $url URL to retrieve
* @param array|bool $query Optional array of query string parameters
* @param array<string, string>|bool $query Optional array of query string parameters
*
* @return mixed
*/
Expand Down Expand Up @@ -498,7 +515,7 @@ public function delete($url)
/**
* Method that appears unused, but is in fact called by curl
*
* @param resource $curl
* @param CurlHandle $curl
* @param string $body
* @return int
*/
Expand All @@ -511,7 +528,7 @@ private function parseBody($curl, $body)
/**
* Method that appears unused, but is in fact called by curl
*
* @param resource $curl
* @param CurlHandle $curl
* @param string $headers
* @return int
*/
Expand Down Expand Up @@ -580,6 +597,7 @@ public function getHeader($header)

/**
* Return the full list of response headers
* @return array<string, string>
*/
public function getHeaders()
{
Expand Down
Loading

0 comments on commit 257ce41

Please sign in to comment.