Skip to content

Commit

Permalink
Chore: PHP CS Fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
ollyollyollyltd committed Feb 13, 2023
1 parent d0338ca commit 4d09874
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 75 deletions.
7 changes: 4 additions & 3 deletions src/apicore/client.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

namespace n1ghteyes\apicore;
use n1ghteyes\apicore\structure\apicore;

class client extends apiCore {
use n1ghteyes\apicore\structure\apicore;

class client extends apiCore
{
public function __construct()
{
parent::__construct();
Expand All @@ -14,4 +15,4 @@ public function __toString()
{
return (string)$this->request;
}
}
}
23 changes: 12 additions & 11 deletions src/apicore/interfaces/coreInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

namespace n1ghteyes\apicore\interfaces;

interface coreInterface {
interface coreInterface
{
/**
* coreInterface constructor.
*/
function __construct();
public function __construct();

/**
* Function to set the request schema. By default assumes http
* @param string $schema
* @return mixed
*/
function setSchema($schema = 'http');
public function setSchema($schema = 'http');


/**
Expand All @@ -22,48 +23,48 @@ function setSchema($schema = 'http');
* @param $port
* @return mixed
*/
function setServer($address, $port);
public function setServer($address, $port);

/**
* Function to set the version and if it should be used as part of the api request path
* @param string $version
* @param bool $flag
* @return mixed
*/
function setVersion($version, $flag = TRUE);
public function setVersion($version, $flag = true);

/**
* Function to set the method used in the request
* @param $method
* @return mixed
*/
function setHTTPMethod($method);
public function setHTTPMethod($method);

/**
* Function to set the type of data being sent and received
* @param $format
* @return mixed
*/
function setBodyFormat($format);
public function setBodyFormat($format);

/**
* Set auto Auth information, if it is needed.
* @return mixed
*/
function auth($user, $pass, $type = 'basic');
public function auth($user, $pass, $type = 'basic');

/**
* PHP Magic function. Should be used to set the HTTP method of a request
* @param string $name
* @return mixed
*/
function __get($name);
public function __get($name);

/**
* Implements magic PHP __call method. Turns undeclared method calls into api endpoint requests
* @param $name
* @param $arguments
* @return mixed
*/
function __call($name, $arguments);
}
public function __call($name, $arguments);
}
5 changes: 3 additions & 2 deletions src/apicore/interfaces/loggingInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace n1ghteyes\apicore\interfaces;

interface loggingInterface {
interface loggingInterface
{
public function addMethod($method);
public function addRequestURL($method);
public function addRequestArgs($method);
Expand All @@ -12,4 +13,4 @@ public function setRequestTime($time);
public function setResponseTime($time);
public function addRawResponse($rawResponse);
public function addResponseStatusCode($status);
}
}
59 changes: 36 additions & 23 deletions src/apicore/structure/apicore.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace n1ghteyes\apicore\structure;

use n1ghteyes\apicore\interfaces\coreInterface;
Expand All @@ -16,16 +17,16 @@
/**
* Class apiCore
*/
abstract class apiCore implements coreInterface{

abstract class apiCore implements coreInterface
{
protected $request;
protected $version;
private $httpMethod = 'GET';
private $bodyFormat = 'body';
private $lastResult;
private $args = array();
private $rawResponse = FALSE;
private $processedResponse = FALSE;
private $rawResponse = false;
private $processedResponse = false;
private $errors = array();
/** @var loggingInterface */
protected $logger;
Expand All @@ -41,7 +42,8 @@ public function __construct()
$this->setBodyFormat();
}

public function addLogger(loggingInterface $logger){
public function addLogger(loggingInterface $logger)
{
$this->logger = $logger;
}

Expand Down Expand Up @@ -73,7 +75,8 @@ public function setServer($address, $port = 443)
* @param $path
* @return $this
*/
public function setBasePath($path){
public function setBasePath($path)
{
$this->request->setBasePath($path);
return $this;
}
Expand All @@ -84,7 +87,7 @@ public function setBasePath($path){
* @param bool $flag
* @return self
*/
public function setVersion($version, $flag = TRUE)
public function setVersion($version, $flag = true)
{
$this->version = $version;
$this->request->setVersion($version, $flag);
Expand All @@ -96,8 +99,9 @@ public function setVersion($version, $flag = TRUE)
* @param $format
* @return mixed
*/
public function setBodyFormat($format = 'body'){
switch($format){
public function setBodyFormat($format = 'body')
{
switch($format) {
case 'form':
$this->bodyFormat = 'form_params';
break;
Expand All @@ -112,7 +116,8 @@ public function setBodyFormat($format = 'body'){
* Get the current version provided to the API
* @return mixed
*/
public function getVersion(){
public function getVersion()
{
return $this->version;
}

Expand Down Expand Up @@ -178,7 +183,8 @@ public function __get($name)
* @param array $arguments
* @return mixed
*/
public function makeDirectRequest(string $name = '', array $arguments = []){
public function makeDirectRequest(string $name = '', array $arguments = [])
{
return $this->__call($name, $arguments);
}

Expand All @@ -203,7 +209,7 @@ public function __call($name, $arguments)
$response = response::getInstance();
$response::verbUsed($this->httpMethod); //set the verb used for the request,
//do we have a logging class? If so, add data to it.
if(isset($this->logger)){
if (isset($this->logger)) {
$this->logger->addMethod($this->httpMethod);
$this->logger->addRequestURL((string)$this->request);
$this->logger->addRequestArgs(json_encode($this->args));
Expand All @@ -214,13 +220,13 @@ public function __call($name, $arguments)
$result = $client->request($this->httpMethod, (string)$this->request, $this->args);
//$this->processResult($result);
$response::processResult($result);
} catch (GuzzleHttp\Exception\GuzzleException $e){
} catch (GuzzleHttp\Exception\GuzzleException $e) {
$response::addError($e->getCode(), $e->getMessage());
}

if(isset($this->logger)){
if (isset($this->logger)) {
$this->logger->setResponseTime(time());
if(!empty($error = $response::getError())){
if (!empty($error = $response::getError())) {
$this->logger->addRawResponse($error['message']);
$this->logger->addResponseStatusCode($error['code']);
} else {
Expand All @@ -241,41 +247,47 @@ public function __call($name, $arguments)
* Function to get the last result returned by an API call.
* @return mixed
*/
public function getLastResult(){
public function getLastResult()
{
return $this->lastResult;
}

/**
* Function to return the last endpoint we called.
* @return mixed
*/
public function getLastCall(){
public function getLastCall()
{
return $this->request->getEndpoint();
}

/**
* Getter for the errors array
* @return array
*/
public function getErrors(){
public function getErrors()
{
return $this->errors;
}

/**
* Function to reset the path in the api request
*/
public function resetPath(){
public function resetPath()
{
$this->request->resetPath();
}

public function addCurlOpts($opts){
public function addCurlOpts($opts)
{
$this->args['config']['curl'] = array_merge($this->args['config']['curl'], $opts);
}

/**
* Function to set some default cURL arguments, such as SSL version.
*/
private function setDefaultCurlOpts(){
private function setDefaultCurlOpts()
{
$this->args['config'] =
array(
'curl' => array(
Expand All @@ -289,8 +301,9 @@ private function setDefaultCurlOpts(){
* @param array $args
* @return self
*/
private function processArgs($args){
if(!empty($args)) {
private function processArgs($args)
{
if (!empty($args)) {
switch ($this->httpMethod) {
case 'DELETE':
case 'GET':
Expand Down
Loading

0 comments on commit 4d09874

Please sign in to comment.