Skip to content

Commit

Permalink
fix(style): PHP-CS-Fixer changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ab-kily authored and actions-user committed Jan 13, 2022
1 parent f48ddf0 commit 416514d
Show file tree
Hide file tree
Showing 31 changed files with 387 additions and 280 deletions.
49 changes: 29 additions & 20 deletions src/Evotor/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

class Client
{

protected $api_key;
protected $app_key;

Expand All @@ -29,7 +28,8 @@ class Client

protected $is_called = false;

public function __construct($api_key,$app_key='',$options=[]) {
public function __construct($api_key, $app_key='', $options=[])
{
$this->api_key = $api_key;
$this->app_key = $app_key;
$this->client = new Guzzle(array_replace_recursive([
Expand All @@ -42,10 +42,11 @@ public function __construct($api_key,$app_key='',$options=[]) {
//'X-Authorization'=>$this->api,
'Authorization'=>'bearer '.$this->api_key,
],
],$options));
], $options));
}

public function _request($method,$uri,$data,$filter = null) {
public function _request($method, $uri, $data, $filter = null)
{
$resp = null;

$this->http_code = null;
Expand All @@ -56,10 +57,10 @@ public function _request($method,$uri,$data,$filter = null) {
$options = $data;

try {
$resp = $this->client->request($method,$uri,$options);
} catch(TransferException $e) {
if($e instanceof TransferException) {
if($e->hasResponse() && ($resp = $e->getResponse()) ) {
$resp = $this->client->request($method, $uri, $options);
} catch (TransferException $e) {
if ($e instanceof TransferException) {
if ($e->hasResponse() && ($resp = $e->getResponse())) {
$this->http_code = $resp->getStatusCode();
$this->http_message = $resp->getReasonPhrase();
} else {
Expand All @@ -71,50 +72,58 @@ public function _request($method,$uri,$data,$filter = null) {
$this->http_message = $e->getMessage();
return null;
}
} catch(\Exception $e) {
} catch (\Exception $e) {
$this->http_code = 0;
$this->http_message = 'Library error';
} finally {
$this->http_code = $resp->getStatusCode();
$this->http_message = $resp->getReasonPhrase();
}

$this->response = new Response($this,$resp,$filter);
$this->response = new Response($this, $resp, $filter);
$this->requested = [];

return $this->response;
}

public function getClient() {
public function getClient()
{
return $this->client;
}

public function __call($name,$arguments=[]) {
$op = OperationFactory::fromName($this,$name,$arguments);
public function __call($name, $arguments=[])
{
$op = OperationFactory::fromName($this, $name, $arguments);
return $op->run();
}

public function getHttpErrorMessage() {
public function getHttpErrorMessage()
{
return $this->http_message;
}

public function getHttpErrorCode() {
public function getHttpErrorCode()
{
return $this->http_code;
}

public function getErrorMessage() {
public function getErrorMessage()
{
return $this->error_message;
}

public function getErrorCode() {
public function getErrorCode()
{
return $this->error_code;
}

public function isOk() {
return strpos((string)$this->http_code,'2') === 0;
public function isOk()
{
return strpos((string)$this->http_code, '2') === 0;
}

public function getAppKey() {
public function getAppKey()
{
return $this->app_key;
}
}
4 changes: 3 additions & 1 deletion src/Evotor/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

namespace Kily\API\Evotor;

class Exception extends \Exception {}
class Exception extends \Exception
{
}
23 changes: 12 additions & 11 deletions src/Evotor/Operations/BulksOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,39 @@

use Kily\API\Evotor\Client;

class BulksOperation extends Operation {

const PATH = 'bulks';
class BulksOperation extends Operation
{
public const PATH = 'bulks';

protected $path = self::PATH;
protected $allowed_methods = ['get'];

protected $id;

public function run(Operation $prev = null) {
public function run(Operation $prev = null)
{
return $this;
}

protected function init($args) {
protected function init($args)
{
$id = $args[0] ?? null;
if($id) {
if ($id) {
$this->id($id);
}
}

public function id($id=false) {
if($id === false) {
public function id($id=false)
{
if ($id === false) {
return $this->id;
} else {
$this->id = $id;
if($id) {
if ($id) {
$this->path = self::PATH.'/'.$id;
} else {
$this->path = self::PATH;
}
}
}


}
32 changes: 18 additions & 14 deletions src/Evotor/Operations/DeviceOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@
use Kily\API\Evotor\Exception;
use Kily\API\Evotor\Operations\OperationFactory;

class DeviceOperation extends Operation {

const PATH = 'stores/{store_id}/devices/{device_id}';
class DeviceOperation extends Operation
{
public const PATH = 'stores/{store_id}/devices/{device_id}';

protected $path = self::PATH;
protected $allowed_methods = ['get'];
protected $id = null;

public function run(Operation $prev = null) {
public function run(Operation $prev = null)
{
return $this;
}

protected function init($args) {
if($this->prev_operation && ($this->prev_operation instanceof StoresOperation)) {
protected function init($args)
{
if ($this->prev_operation && ($this->prev_operation instanceof StoresOperation)) {
$id = $args[0] ?? null;
if($id) {
if ($id) {
$this->id($id);
} else {
throw new Exception('You must supply device id');
Expand All @@ -31,20 +33,22 @@ protected function init($args) {
}
}

public function id($id=false) {
if($id === false) {
public function id($id=false)
{
if ($id === false) {
return $this->id;
} else {
$this->id = $id;
if($id) {
$this->path = str_replace(['{store_id}','{device_id}'],[$this->prev_operation->id(),$id],self::PATH);
if ($id) {
$this->path = str_replace(['{store_id}','{device_id}'], [$this->prev_operation->id(),$id], self::PATH);
}
}
}

public function documents() {
if($this->id) {
$op = OperationFactory::fromName($this->client,'documents',[],$this);
public function documents()
{
if ($this->id) {
$op = OperationFactory::fromName($this->client, 'documents', [], $this);
return $op->run();
} else {
throw new Exception('You should define device id for using documents');
Expand Down
13 changes: 7 additions & 6 deletions src/Evotor/Operations/DevicesOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@

use Kily\API\Evotor\Client;

class DevicesOperation extends Operation {

const PATH = 'devices';
class DevicesOperation extends Operation
{
public const PATH = 'devices';

protected $path = self::PATH;
protected $allowed_methods = ['get'];

protected $id;

public function run(Operation $prev = null) {
public function run(Operation $prev = null)
{
return $this;
}

public function id($id=false) {
public function id($id=false)
{
throw new Exception('Employees operation does not support fetch by id');
}

}
34 changes: 18 additions & 16 deletions src/Evotor/Operations/DocumentsOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,46 @@
use Kily\API\Evotor\Client;
use Kily\API\Evotor\Exception;

class DocumentsOperation extends Operation {

const PATH = 'stores/{store_id}/documents';
class DocumentsOperation extends Operation
{
public const PATH = 'stores/{store_id}/documents';

protected $path = self::PATH;
protected $allowed_methods = ['get','post'];
protected $id = null;

public function run(Operation $prev = null) {
public function run(Operation $prev = null)
{
return $this;
}

protected function init($args) {
if($this->prev_operation) {
if($this->prev_operation instanceof StoresOperation) {
$this->path = str_replace('{store_id}',$this->prev_operation->id(),self::PATH);
} elseif($this->prev_operation instanceof DeviceOperation) {
protected function init($args)
{
if ($this->prev_operation) {
if ($this->prev_operation instanceof StoresOperation) {
$this->path = str_replace('{store_id}', $this->prev_operation->id(), self::PATH);
} elseif ($this->prev_operation instanceof DeviceOperation) {
$this->path = $this->prev_operation->getPath().'/documents';
}
} else {
throw new Exception('Unable to get prev operation');
}
}

public function id($id=false) {
if($id === false) {
public function id($id=false)
{
if ($id === false) {
return $this->id;
} else {
if($this->prev_operation instanceof DeviceOperation) {
if ($this->prev_operation instanceof DeviceOperation) {
throw new Exception('You should not use id when fetching device documents');
}
$this->id = $id;
if($id) {
$this->path = str_replace('{store_id}',$this->prev_operation->id(),self::PATH).'/'.$id;
if ($id) {
$this->path = str_replace('{store_id}', $this->prev_operation->id(), self::PATH).'/'.$id;
} else {
$this->path = str_replace('{store_id}',$this->prev_operation->id(),self::PATH);
$this->path = str_replace('{store_id}', $this->prev_operation->id(), self::PATH);
}
}
}

}
13 changes: 7 additions & 6 deletions src/Evotor/Operations/EmployeesOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@

use Kily\API\Evotor\Client;

class EmployeesOperation extends Operation {

const PATH = 'employees';
class EmployeesOperation extends Operation
{
public const PATH = 'employees';

protected $path = self::PATH;
protected $allowed_methods = ['get'];

protected $id;

public function run(Operation $prev = null) {
public function run(Operation $prev = null)
{
return $this;
}

public function id($id=false) {
public function id($id=false)
{
throw new Exception('Employees operation does not support fetch by id');
}

}
Loading

0 comments on commit 416514d

Please sign in to comment.