From 16ea8a8c45bb34740fdc3fa1b038058564190021 Mon Sep 17 00:00:00 2001 From: coro Date: Sat, 11 May 2019 22:51:21 +0200 Subject: [PATCH] Code Sniffer valided --- src/Api/Api.php | 17 +-- src/Api/Authenticator.php | 4 +- src/Api/Request.php | 44 +++--- src/Api/Response.php | 7 +- src/Api/exceptions.php | 28 +++- src/Buffer.php | 13 +- src/Compress.php | 7 +- src/Customers.php | 108 ++++++--------- src/DIContainer.php | 42 ++---- src/Database/IDatabase.php | 2 +- src/Database/Result.php | 15 +- src/Escape.php | 7 +- src/Headers.php | 31 ++--- src/Helpers.php | 27 ++-- src/Hook/Channel/DefaultChannel.php | 8 +- src/Hook/Channel/Sms.php | 16 +-- src/Hook/Hook.php | 17 ++- src/Hook/Settings.php | 24 ++-- src/Hook/Variables.php | 34 ++--- src/ICustomers.php | 4 +- src/ILocale.php | 14 +- src/IO/ConnectionFactory.php | 26 ++-- src/IO/FSock.php | 30 ++-- src/IO/HttpHeaders.php | 30 ++-- src/IO/Key.php | 33 +++-- src/IO/Request.php | 25 ++-- src/IO/Response.php | 115 ++++++---------- src/IO/cUrl.php | 29 ++-- src/IO/exceptions.php | 28 +++- src/ISettings.php | 2 +- src/Iterator.php | 20 +-- src/Json.php | 21 +-- src/Key.php | 14 +- src/LocaleIntl.php | 43 +++--- src/LocaleSimple.php | 16 +-- src/ProxyActions.php | 101 ++++++++------ src/Settings.php | 206 ++++++++++++---------------- src/Strict.php | 14 +- src/Synchronize.php | 87 +++++++----- src/Translator.php | 21 ++- src/_extension.php | 5 +- src/debug.php | 8 +- src/exceptions.php | 36 ++++- tests/bootstrap.php | 11 +- 44 files changed, 671 insertions(+), 719 deletions(-) diff --git a/src/Api/Api.php b/src/Api/Api.php index 1e7c234..96785c2 100644 --- a/src/Api/Api.php +++ b/src/Api/Api.php @@ -15,19 +15,20 @@ abstract class Api extends Extensions\Strict /** @var Extensions\ISettings */ protected $settings; - public function __construct($action, Extensions\Api\IRequest $data, Extensions\Database\IDatabase $database, Extensions\ISettings $settings) - { + public function __construct( + $action, + Extensions\Api\IRequest $data, + Extensions\Database\IDatabase $database, + Extensions\ISettings $settings + ) { $this->database = $database; $this->settings = $settings; $method = 'action'.ucfirst($action); - if(method_exists($this, $method)) - { - call_user_func_array(array($this, $method), array($data)); - } - else - { + if (method_exists($this, $method)) { + call_user_func_array([$this, $method], [$data]); + } else { throw new ConnectionException('Not Found', 404); } } diff --git a/src/Api/Authenticator.php b/src/Api/Authenticator.php index 70bff73..b19fc6d 100644 --- a/src/Api/Authenticator.php +++ b/src/Api/Authenticator.php @@ -19,8 +19,8 @@ public function __construct(Extensions\ISettings $settings) public function authenticate($application_id, $application_token) { - if($this->settings->load("static:application_id") === $application_id && $this->settings->load("static:application_token") === $application_token) - { + if ($this->settings->load("static:application_id") === $application_id && + $this->settings->load("static:application_token") === $application_token) { return true; } throw new ConnectionException('Unauthorized', 401); diff --git a/src/Api/Request.php b/src/Api/Request.php index c772adb..46f892f 100644 --- a/src/Api/Request.php +++ b/src/Api/Request.php @@ -2,24 +2,25 @@ namespace BulkGate\Extensions\Api; use BulkGate\Extensions; +use stdClass; /** * @author Lukáš Piják 2018 TOPefekt s.r.o. * @link https://www.bulkgate.com/ */ -class Request extends \stdClass implements IRequest +class Request extends stdClass implements IRequest { /** @var array */ - private $data = array(); + private $data = []; /** @var Extensions\Headers */ private $headers; public function __construct(Extensions\Headers $headers) { - if(!isset($_SERVER['REQUEST_METHOD']) || (isset($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) !== 'post')) - { - throw new ConnectionException("Method Not Allowed", 405); + if (!isset($_SERVER['REQUEST_METHOD']) || (isset($_SERVER['REQUEST_METHOD']) && + strtolower($_SERVER['REQUEST_METHOD']) !== 'post')) { + throw new ConnectionException('Method Not Allowed', 405); } $this->headers = $headers; @@ -28,38 +29,29 @@ public function __construct(Extensions\Headers $headers) $data = file_get_contents('php://input'); - if(is_string($data)) - { - if($content_type === 'application/json') - { - try - { + if (is_string($data)) { + if ($content_type === 'application/json') { + try { $this->data = Extensions\Json::decode($data, Extensions\Json::FORCE_ARRAY); - } - catch (Extensions\JsonException $e) - { + } catch (Extensions\JsonException $e) { throw new ConnectionException('Bad Request', 400); } - } - elseif($content_type === 'application/zip') - { - $this->data = Extensions\Json::decode(Extensions\Compress::decompress($data), Extensions\Json::FORCE_ARRAY); - } - else - { + } elseif ($content_type === 'application/zip') { + $this->data = Extensions\Json::decode( + Extensions\Compress::decompress($data), + Extensions\Json::FORCE_ARRAY + ); + } else { throw new ConnectionException('Bad Request', 400); } - } - else - { + } else { throw new ConnectionException('Bad Request', 400); } } public function __get($name) { - if(isset($this->data[$name])) - { + if (isset($this->data[$name])) { return $this->data[$name]; } return null; diff --git a/src/Api/Response.php b/src/Api/Response.php index 30e3b7c..652c0fc 100644 --- a/src/Api/Response.php +++ b/src/Api/Response.php @@ -35,12 +35,9 @@ public function send() { header("Content-Type: {$this->contentType}; charset=utf-8"); - if($this->contentType === 'application/zip') - { + if ($this->contentType === 'application/zip') { echo BulkGate\Extensions\Compress::compress(BulkGate\Extensions\Json::encode($this->payload)); - } - else - { + } else { echo BulkGate\Extensions\Json::encode($this->payload); } } diff --git a/src/Api/exceptions.php b/src/Api/exceptions.php index 6c4437f..1863250 100644 --- a/src/Api/exceptions.php +++ b/src/Api/exceptions.php @@ -7,10 +7,30 @@ * @author Lukáš Piják 2018 TOPefekt s.r.o. * @link https://www.bulkgate.com/ */ -class ConnectionException extends Extensions\Exception {} +class ConnectionException extends Extensions\Exception +{ +} -class InvalidRequestException extends ConnectionException {} +/** + * Class InvalidRequestException + * @package BulkGate\Extensions\Api + */ +class InvalidRequestException extends ConnectionException +{ +} -class UnknownActionException extends ConnectionException {} +/** + * Class UnknownActionException + * @package BulkGate\Extensions\Api + */ +class UnknownActionException extends ConnectionException +{ +} -class MethodNotAllowedException extends ConnectionException {} +/** + * Class MethodNotAllowedException + * @package BulkGate\Extensions\Api + */ +class MethodNotAllowedException extends ConnectionException +{ +} diff --git a/src/Buffer.php b/src/Buffer.php index 50518d2..aadaff0 100644 --- a/src/Buffer.php +++ b/src/Buffer.php @@ -1,19 +1,21 @@ buffer = $array; $this->default_value = $default_value; @@ -21,8 +23,7 @@ public function __construct(array $array = array(), $default_value = null) public function __get($name) { - if(isset($this->buffer[$name])) - { + if (isset($this->buffer[$name])) { return $this->buffer[$name]; } return $this->default_value; diff --git a/src/Compress.php b/src/Compress.php index f2138e2..9bff7a6 100644 --- a/src/Compress.php +++ b/src/Compress.php @@ -9,15 +9,14 @@ */ class Compress { - static public function compress($data, $encoding_mode = 9) + public static function compress($data, $encoding_mode = 9) { return base64_encode(gzencode(serialize($data), $encoding_mode)); } - static public function decompress($data) + public static function decompress($data) { - if($data) - { + if ($data) { return unserialize(gzinflate(substr(base64_decode($data), 10, -8))); } return false; diff --git a/src/Customers.php b/src/Customers.php index 62ca05d..1ac95ca 100644 --- a/src/Customers.php +++ b/src/Customers.php @@ -18,13 +18,11 @@ abstract class Customers extends Extensions\Strict implements Extensions\ICustom /** @var string */ protected $table_user_key = 'customer_id'; - public function __construct(Extensions\Database\IDatabase $db) { $this->db = $db; } - /** * @param array $customers * @param null|int $limit @@ -32,52 +30,46 @@ public function __construct(Extensions\Database\IDatabase $db) */ abstract protected function loadCustomers(array $customers, $limit = null); - /** * @param array $filters * @return array */ abstract protected function filter(array $filters); - /** * @return int */ abstract protected function getTotal(); - /** * @param array $customers * @return int */ abstract protected function getFilteredTotal(array $customers); - - public function loadCount(array $filter = array()) + public function loadCount(array $filter = []) { - $customers = array(); + $customers = []; $filtered_count = $total = $this->getTotal(); - if(count($filter) > 0) - { + if (count($filter) > 0) { list($customers, $filtered) = $this->filter($filter); - if($filtered) - { + if ($filtered) { $filtered_count = $this->getFilteredTotal($customers); } } - return array('total' => $total, 'count' => $filtered_count, 'limit' => $filtered_count !== 0 ? $this->loadCustomers((array) $customers, 10) : array()); + return ['total' => $total, 'count' => $filtered_count, 'limit' => $filtered_count !== 0 + ? $this->loadCustomers((array) $customers, 10) : []]; } - public function load(array $filter = array()) + public function load(array $filter = []) { - $customers = array(); + $customers = []; - if(count($filter) > 0) - { + if (count($filter) > 0) { list($customers, $_) = $this->filter($filter); } @@ -86,44 +78,32 @@ public function load(array $filter = array()) protected function getSql(array $filter, $key_value = 'meta_value', $table = '') { - $sql = array(); - - strlen($table) > 0 && $table = '`'.$this->db->table($table).'`.'; - - if(isset($filter['type']) && isset($filter['values'])) - { - foreach ($filter['values'] as $value) - { - if(in_array($filter['type'], array('enum', 'string', 'float'), true)) - { - if($value[0] === 'prefix') - { - $sql[] = $this->db->prepare($table."`".$key_value."` LIKE %s", array($value[1].'%')); - } - elseif($value[0] === 'sufix') - { - $sql[] = $this->db->prepare($table."`".$key_value."` LIKE %s", array('%'.$value[1])); + $sql = []; + + $table !== '' && $table = '`'.$this->db->table($table).'`.'; + + if (isset($filter['type']) && isset($filter['values'])) { + foreach ($filter['values'] as $value) { + if (in_array($filter['type'], ['enum', 'string', 'float'], true)) { + if ($value[0] === 'prefix') { + $sql[] = $this->db->prepare($table . '`' . $key_value . '` LIKE %s', [$value[1] . '%']); + } elseif ($value[0] === 'sufix') { + $sql[] = $this->db->prepare($table . '`' . $key_value . '` LIKE %s', ['%' . $value[1]]); + } elseif ($value[0] === 'substring') { + $sql[] = $this->db->prepare($table . '`' . $key_value . '` LIKE %s', ['%' . $value[1] . '%']); + } elseif ($value[0] === 'empty') { + $sql[] = "`" . $key_value . '` IS NULL OR TRIM(`' . $key_value . "`) = ''"; + } elseif ($value[0] === 'filled') { + $sql[] = "`" . $key_value . '` IS NOT NULL AND (`' . $key_value . "`) != ''"; + } else { + $sql[] = $this->db->prepare($table . '`' . $key_value . '` ' . $this->getRelation($value[0]) + . ' %s', [$value[1]]); } - elseif($value[0] === 'substring') - { - $sql[] = $this->db->prepare($table."`".$key_value."` LIKE %s", array('%'.$value[1].'%')); - } - elseif($value[0] === 'empty') - { - $sql[] = "`".$key_value."` IS NULL OR TRIM(`".$key_value."`) = ''"; - } - elseif($value[0] === 'filled') - { - $sql[] = "`".$key_value."` IS NOT NULL AND (`".$key_value."`) != ''"; - } - else - { - $sql[] = $this->db->prepare($table."`".$key_value."` ".$this->getRelation($value[0])." %s", array($value[1])); - } - } - elseif($filter['type'] === "date-range") - { - $sql[] = $this->db->prepare($table."`".$key_value."` BETWEEN %s AND %s", array($value[1], $value[2])); + } elseif ($filter['type'] === 'date-range') { + $sql[] = $this->db->prepare( + $table . '`' . $key_value . '` BETWEEN %s AND %s', + [$value[1], $value[2]] + ); } } } @@ -133,32 +113,28 @@ protected function getSql(array $filter, $key_value = 'meta_value', $table = '') protected function getRelation($relation) { - $relation_list = array( + $relation_list = [ 'is' => '=', 'not' => '!=', 'gt' => '>', 'lt' => '<' - ); + ]; return isset($relation_list[$relation]) ? $relation_list[$relation] : '='; } protected function getCustomers(Extensions\Database\Result $result, array $customers) { - $output = array(); + $output = []; - if($result->getNumRows() > 0) - { - foreach($result as $row) - { - $output[] = (int) $row->{$this->table_user_key}; + if ($result->getNumRows() > 0) { + foreach ($result as $row) { + $output[] = (int)$row->{$this->table_user_key}; } - } - else - { + } else { $this->empty = true; } - return $this->empty ? array() : count($customers) > 0 ? array_intersect($customers, $output) : $output; + return $this->empty ? [] : count($customers) > 0 ? array_intersect($customers, $output) : $output; } } diff --git a/src/DIContainer.php b/src/DIContainer.php index 8193c97..5b7a9e2 100644 --- a/src/DIContainer.php +++ b/src/DIContainer.php @@ -16,27 +16,23 @@ abstract class DIContainer extends Strict { /** @var array */ - protected $services = array(); - + protected $services = []; /** * @return Database\IDatabase */ abstract protected function createDatabase(); - /** * @return IModule */ abstract protected function createModule(); - /** * @return ICustomers */ abstract protected function createCustomers(); - /** * @return Settings */ @@ -45,7 +41,6 @@ protected function createSettings() return new Settings($this->getService('database')); } - /** * @return IO\IConnection */ @@ -59,7 +54,6 @@ protected function createConnection() return $factory->create($module->url(), $module->product()); } - /** * @return Translator */ @@ -68,7 +62,6 @@ protected function createTranslator() return new Translator($this->getService('settings')); } - /** * @return Synchronize */ @@ -77,16 +70,21 @@ protected function createSynchronize() return new Synchronize($this->getService('settings'), $this->getService('connection')); } - /** * @return ProxyActions */ protected function createProxy() { - return new ProxyActions($this->getService('connection'), $this->getService('module'), $this->getService('synchronize'), $this->getService('settings'), $this->getService('translator'), $this->getService('customers')); + return new ProxyActions( + $this->getService('connection'), + $this->getService('module'), + $this->getService('synchronize'), + $this->getService('settings'), + $this->getService('translator'), + $this->getService('customers') + ); } - /** * @param $name * @return mixed @@ -96,34 +94,24 @@ public function getService($name) { $name = ucfirst($name); - if(isset($this->services[$name])) - { + if (isset($this->services[$name])) { return $this->services[$name]; } - else - { - if(method_exists($this, 'create'.$name)) - { - return $this->services[$name] = call_user_func(array($this, 'create'.$name)); - } - else - { - throw new ServiceNotFoundException("Dependency injection container - Service $name not found"); - } + if (method_exists($this, 'create' . $name)) { + return $this->services[$name] = $this->{'create' . $name}(); } + throw new ServiceNotFoundException("Dependency injection container - Service $name not found"); } - /** * @param string $name * @param array $args * @return mixed * @throws ServiceNotFoundException */ - public function __call($name, array $args = array()) + public function __call($name, array $args = []) { - if(preg_match("~^get(?[A-Z][a-zA-Z0-9_]*)~", $name, $match)) - { + if (preg_match("~^get(?[A-Z][a-zA-Z0-9_]*)~", $name, $match)) { return $this->getService($match['name']); } diff --git a/src/Database/IDatabase.php b/src/Database/IDatabase.php index 4b4c239..3493985 100644 --- a/src/Database/IDatabase.php +++ b/src/Database/IDatabase.php @@ -18,7 +18,7 @@ public function execute($sql); * @param array $params * @return string */ - public function prepare($sql, array $params = array()); + public function prepare($sql, array $params = []); /** * @return mixed diff --git a/src/Database/Result.php b/src/Database/Result.php index 9afefb7..64dbee7 100644 --- a/src/Database/Result.php +++ b/src/Database/Result.php @@ -7,21 +7,18 @@ * @author Lukáš Piják 2018 TOPefekt s.r.o. * @link https://www.bulkgate.com/ */ -class Result extends Extensions\Iterator implements \Iterator +class Result extends Extensions\Iterator { /** @var array|mixed */ - protected $row = array(); + protected $row = []; public function __construct(array $rows) { - foreach($rows as $key => $value) - { - if(is_array($value)) - { + parent::__construct([]); + foreach ($rows as $key => $value) { + if (is_array($value)) { $this->array[$key] = new Extensions\Buffer($value); - } - else - { + } else { $this->array[$key] = $value; } } diff --git a/src/Escape.php b/src/Escape.php index 23b30a3..1af4d67 100644 --- a/src/Escape.php +++ b/src/Escape.php @@ -15,8 +15,8 @@ public static function html($s) public static function js($s) { return str_replace( - array("\xe2\x80\xa8", "\xe2\x80\xa9", ']]>', '', 'headers)) - { + if (empty($this->headers)) { $this->init(); } $name = strtolower($name); - if($name !== null) - { + if ($name !== null) { return isset($this->headers[$name]) ? $this->headers[$name] : $default; } return $this->headers; @@ -35,23 +33,14 @@ public function get($name = null, $default = null) private function init() { - if (function_exists('apache_request_headers')) - { + if (function_exists('apache_request_headers')) { $this->headers = array_change_key_case(apache_request_headers(), CASE_LOWER); - } - else - { - foreach($_SERVER as $key => $value) - { - if(strncmp($key, 'HTTP_', 5) === 0) - { - $this->headers[ - strtolower( - strtr( - substr($key, 5), '_', '-' - ) - ) - ] = $value; + } else { + foreach ($_SERVER as $key => $value) { + if (strncmp($key, 'HTTP_', 5) === 0) { + $this->headers[strtolower( + strtr(substr($key, 5), '_', '-') + )] = $value; } } } diff --git a/src/Helpers.php b/src/Helpers.php index df8cf3d..6a07f4a 100644 --- a/src/Helpers.php +++ b/src/Helpers.php @@ -1,6 +1,8 @@ load('static:out_of_stock', false); - $list = $list !== false ? unserialize($list) : array(); + $list = $list !== false ? unserialize($list) : []; - if(is_array($list)) - { - foreach($list as $key => $time) - { - if($time < time()) - { - unset($list[(string) $key]); + if (is_array($list)) { + foreach ($list as $key => $time) { + if ($time < time()) { + unset($list[(string)$key]); } } + } else { + $list = []; } - else - { - $list = array(); - } - - if(!isset($list[(string) $product_id])) - { - $list[(string) $product_id] = time() + 86400; + if (!isset($list[(string)$product_id])) { + $list[(string)$product_id] = (new DateTime('now + 1 day'))->getTimestamp(); $result = true; } diff --git a/src/Hook/Channel/DefaultChannel.php b/src/Hook/Channel/DefaultChannel.php index 92f8bc1..2ab2303 100644 --- a/src/Hook/Channel/DefaultChannel.php +++ b/src/Hook/Channel/DefaultChannel.php @@ -2,12 +2,13 @@ namespace BulkGate\Extensions\Hook\Channel; use BulkGate; +use stdClass; /** * @author Lukáš Piják 2018 TOPefekt s.r.o. * @link https://www.bulkgate.com/ */ -class DefaultChannel extends \stdClass implements IChannel +class DefaultChannel extends stdClass implements IChannel { /** @var bool */ public $active = false; @@ -19,12 +20,11 @@ class DefaultChannel extends \stdClass implements IChannel public $customer = false; /** @var array */ - public $admins = array(); + public $admins = []; public function __construct(array $data) { - foreach($data as $key => $value) - { + foreach ($data as $key => $value) { $this->{$key} = $value; } } diff --git a/src/Hook/Channel/Sms.php b/src/Hook/Channel/Sms.php index 6343ea8..a8e0b77 100644 --- a/src/Hook/Channel/Sms.php +++ b/src/Hook/Channel/Sms.php @@ -31,18 +31,14 @@ class Sms extends BulkGate\Extensions\Strict implements IChannel private $customer = false; /** @var array */ - private $admins = array(); + private $admins = []; public function __construct(array $data) { - foreach($data as $key => $value) - { - try - { + foreach ($data as $key => $value) { + try { $this->{$key} = $value; - } - catch (BulkGate\Extensions\StrictException $e) - { + } catch (BulkGate\Extensions\StrictException $e) { } } } @@ -54,7 +50,7 @@ public function isActive() public function toArray() { - return array( + return [ 'active' => (bool) $this->active, 'template' => (string) $this->template, 'unicode' => (bool) $this->unicode, @@ -63,6 +59,6 @@ public function toArray() 'senderValue' => (string) $this->senderValue, 'customer' => (bool) $this->customer, 'admins' => (array) $this->admins - ); + ]; } } diff --git a/src/Hook/Hook.php b/src/Hook/Hook.php index 1bbb90a..096d3df 100644 --- a/src/Hook/Hook.php +++ b/src/Hook/Hook.php @@ -27,8 +27,14 @@ class Hook extends BulkGate\Extensions\Strict /** @var ILoad */ private $load; - public function __construct($url, $language_iso, $shop_id, BulkGate\Extensions\IO\IConnection $connection, BulkGate\Extensions\ISettings $settings, ILoad $load) - { + public function __construct( + $url, + $language_iso, + $shop_id, + BulkGate\Extensions\IO\IConnection $connection, + BulkGate\Extensions\ISettings $settings, + ILoad $load + ) { $this->url = $url; $this->language_iso = $settings->load('main:language_mutation', false) ? (string) $language_iso : 'default'; $this->shop_id = (int) $shop_id; @@ -39,11 +45,10 @@ public function __construct($url, $language_iso, $shop_id, BulkGate\Extensions\I public function run($name, Variables $variables) { - $customer = new Settings((array) $this->settings->load($this->getKey($name, 'customer'), array())); - $admin = new Settings((array) $this->settings->load($this->getKey($name, 'admin'), array())); + $customer = new Settings((array) $this->settings->load($this->getKey($name, 'customer'), [])); + $admin = new Settings((array) $this->settings->load($this->getKey($name, 'admin'), [])); - if(count($customer->toArray()) > 0 || count($admin->toArray()) > 0) - { + if (count($customer->toArray()) > 0 || count($admin->toArray()) > 0) { $this->load->load($variables); return $this->connection->run(new BulkGate\Extensions\IO\Request($this->url, array( diff --git a/src/Hook/Settings.php b/src/Hook/Settings.php index 88d6208..b9cbe30 100644 --- a/src/Hook/Settings.php +++ b/src/Hook/Settings.php @@ -11,18 +11,16 @@ class Settings extends BulkGate\Extensions\Iterator { public function __construct(array $data) { - $settings = array(); + $settings = []; - foreach($data as $type => $channel) - { - switch ($type) - { + foreach ($data as $type => $channel) { + switch ($type) { case 'sms': - $settings[$type] = new BulkGate\Extensions\Hook\Channel\Sms((array) $channel); - break; + $settings[$type] = new BulkGate\Extensions\Hook\Channel\Sms((array)$channel); + break; default: - $settings[$type] = new BulkGate\Extensions\Hook\Channel\DefaultChannel((array) $channel); - break; + $settings[$type] = new BulkGate\Extensions\Hook\Channel\DefaultChannel((array)$channel); + break; } } @@ -31,13 +29,11 @@ public function __construct(array $data) public function toArray() { - $output = array(); + $output = []; /** @var BulkGate\Extensions\Hook\Channel\IChannel $item */ - foreach($this->array as $key => $item) - { - if($item->isActive()) - { + foreach ($this->array as $key => $item) { + if ($item->isActive()) { $output[$key] = $item->toArray(); } } diff --git a/src/Hook/Variables.php b/src/Hook/Variables.php index 908b049..3cbf42a 100644 --- a/src/Hook/Variables.php +++ b/src/Hook/Variables.php @@ -10,30 +10,24 @@ class Variables extends Strict { /** @var array */ - private $variables = array(); + private $variables; - public function __construct(array $variables = array()) + public function __construct(array $variables = []) { $this->variables = $variables; } public function set($key, $value, $alternative = '', $rewrite = true) { - if(!isset($this->variables[$key]) || $rewrite) - { - if(is_scalar($value) && strlen(trim((string) $value)) > 0) - { + if (!isset($this->variables[$key]) || $rewrite) { + if (is_scalar($value) && strlen(trim((string)$value)) > 0) { $this->variables[$key] = $value; } - if(!isset($this->variables[$key])) - { - if(is_scalar($alternative) && strlen(trim((string) $alternative)) > 0) - { - $this->variables[$key] = (string) $alternative; - } - else - { + if (!isset($this->variables[$key])) { + if (is_scalar($alternative) && strlen(trim((string)$alternative)) > 0) { + $this->variables[$key] = (string)$alternative; + } else { $this->variables[$key] = ''; } } @@ -44,8 +38,7 @@ public function set($key, $value, $alternative = '', $rewrite = true) public function get($key, $default = false) { - if(isset($this->variables[$key])) - { + if (isset($this->variables[$key])) { return $this->variables[$key]; } return $default; @@ -53,20 +46,19 @@ public function get($key, $default = false) public function toArray() { - return (array) $this->variables; + return $this->variables; } public function __toString() { $output = '$php = array('.PHP_EOL; - foreach ($this->variables as $key => $variable) - { - $output .= "\t".'\''.$key.'\' => \''.$variable.'\','.PHP_EOL; + foreach ($this->variables as $key => $variable) { + $output .= "\t" . '\'' . $key . '\' => \'' . $variable . '\',' . PHP_EOL; } $output .= ');'; return $output; } -} \ No newline at end of file +} diff --git a/src/ICustomers.php b/src/ICustomers.php index d22d542..bcfddc2 100644 --- a/src/ICustomers.php +++ b/src/ICustomers.php @@ -11,11 +11,11 @@ interface ICustomers * @param array $filter * @return array */ - public function loadCount(array $filter = array()); + public function loadCount(array $filter = []); /** * @param array $filter * @return array */ - public function load(array $filter = array()); + public function load(array $filter = []); } diff --git a/src/ILocale.php b/src/ILocale.php index 49547f9..f4a214b 100644 --- a/src/ILocale.php +++ b/src/ILocale.php @@ -1,6 +1,8 @@ io === null) - { - if(extension_loaded('curl')) - { - $this->io = new cUrl($this->settings->load("static:application_id"), $this->settings->load("static:application_token"), $url, $product, $this->settings->load('main:language', 'en')); - } - else - { - $this->io = new FSock($this->settings->load("static:application_id"), $this->settings->load("static:application_token"), $url, $product, $this->settings->load('main:language', 'en')); + if ($this->io === null) { + if (extension_loaded('curl')) { + $this->io = new cUrl( + $this->settings->load('static:application_id'), + $this->settings->load('static:application_token'), + $url, + $product, + $this->settings->load('main:language', 'en') + ); + } else { + $this->io = new FSock( + $this->settings->load('static:application_id'), + $this->settings->load('static:application_token'), + $url, + $product, + $this->settings->load('main:language', 'en') + ); } } return $this->io; diff --git a/src/IO/FSock.php b/src/IO/FSock.php index f70b036..c1c0e6e 100644 --- a/src/IO/FSock.php +++ b/src/IO/FSock.php @@ -32,8 +32,13 @@ class FSock extends Extensions\Strict implements IConnection * @param $application_product * @param $application_language */ - public function __construct($application_id, $application_token, $application_url, $application_product, $application_language) - { + public function __construct( + $application_id, + $application_token, + $application_url, + $application_product, + $application_language + ) { $this->application_id = $application_id; $this->application_token = $application_token; $this->application_url = $application_url; @@ -48,25 +53,24 @@ public function __construct($application_id, $application_token, $application_ur */ public function run(Request $request) { - $connection = @fopen($request->getUrl(), 'r', false, stream_context_create(array( - 'http' => array( + $connection = @fopen($request->getUrl(), 'r', false, stream_context_create([ + 'http' => [ 'method' => 'POST', - 'header' => array( + 'header' => [ 'Content-type: ' . $request->getContentType(), 'X-BulkGate-Application-ID: ' . (string) $this->application_id, 'X-BulkGate-Application-Token: ' . (string) $this->application_token, 'X-BulkGate-Application-Url: ' . (string) $this->application_url, 'X-BulkGate-Application-Product: '. (string) $this->application_product, 'X-BulkGate-Application-Language: '. (string) $this->application_language - ), + ], 'content' => $request->getData(), 'ignore_errors' => true, 'timeout' => $request->getTimeout() - ) - ))); + ] + ])); - if ($connection) - { + if ($connection) { $meta = stream_get_meta_data($connection); $header = new HttpHeaders(implode("\r\n", $meta['wrapper_data'])); @@ -77,6 +81,10 @@ public function run(Request $request) return new Response($result, $header->getContentType()); } - return new Response(array('data' => array(), 'exception' => 'ConnectionException', 'error' => array('Server ('.$request->getUrl().') is unavailable. Try contact your hosting provider.'))); + return new Response([ + 'data' => [], + 'exception' => 'ConnectionException', + 'error' => ['Server ('.$request->getUrl().') is unavailable. Try contact your hosting provider.'] + ]); } } diff --git a/src/IO/HttpHeaders.php b/src/IO/HttpHeaders.php index 7fe0297..78c68cd 100644 --- a/src/IO/HttpHeaders.php +++ b/src/IO/HttpHeaders.php @@ -10,7 +10,7 @@ class HttpHeaders extends BulkGate\Extensions\Strict { /** @var array */ - private $headers = array(); + private $headers = []; public function __construct($raw_header) { @@ -26,8 +26,7 @@ public function getHeader($name, $default = null) { $name = strtolower($name); - if(isset($this->headers[$name])) - { + if (isset($this->headers[$name])) { return $this->headers[$name]; } return $default; @@ -37,12 +36,10 @@ public function getContentType() { $content_type = $this->getHeader('content-type'); - if($content_type !== null) - { + if ($content_type !== null) { preg_match('~^(?[a-zA-Z]*/[a-zA-Z]*)~', trim($content_type), $type); - if(isset($type['type'])) - { + if (isset($type['type'])) { return $type['type']; } } @@ -60,23 +57,16 @@ public function getHeaders() */ private function parseHeaders($raw_header) { - if(!is_array($raw_header)) - { + if (!is_array($raw_header)) { $raw_header = explode("\r\n\r\n", $raw_header); } - foreach($raw_header as $index => $request) - { - foreach (explode("\r\n", $request) as $i => $line) - { - if(strlen($line) > 0) - { - if ((int)$i === 0) - { + foreach ($raw_header as $index => $request) { + foreach (explode("\r\n", $request) as $i => $line) { + if (strlen($line) > 0) { + if ((int)$i === 0) { $this->headers['http_code'] = $line; - } - else - { + } else { list ($key, $value) = explode(':', $line); $this->headers[strtolower($key)] = trim($value); } diff --git a/src/IO/Key.php b/src/IO/Key.php index a4e7d68..7176067 100644 --- a/src/IO/Key.php +++ b/src/IO/Key.php @@ -7,31 +7,34 @@ */ class Key { - const DEFAULT_REDUCER = "_generic"; + const DEFAULT_REDUCER = '_generic'; - const DEFAULT_CONTAINER = "server"; + const DEFAULT_CONTAINER = 'server'; - const DEFAULT_VARIABLE = "_empty"; + const DEFAULT_VARIABLE = '_empty'; - static public function decode($key) + public static function decode($key) { - if(preg_match("~^(?[a-zA-Z0-9_-]*):(?[a-zA-Z0-9_-]*):(?[a-zA-Z0-9_-]*)$~", $key, $match)) - { - return array($match["reducer"] ?: self::DEFAULT_REDUCER, $match["container"] ?: self::DEFAULT_CONTAINER, $match["name"] ?: self::DEFAULT_VARIABLE); + if (preg_match( + '~^(?[a-zA-Z0-9_-]*):(?[a-zA-Z0-9_-]*):(?[a-zA-Z0-9_-]*)$~', + $key, + $match + )) { + return [$match['reducer'] ?: self::DEFAULT_REDUCER, $match['container'] ?: + self::DEFAULT_CONTAINER, $match['name'] ?: self::DEFAULT_VARIABLE]; } - else if(preg_match("~^(?[a-zA-Z0-9_-]*):(?[a-zA-Z0-9_-]*)$~", $key, $match)) - { - return array(self::DEFAULT_REDUCER, $match["container"] ?: self::DEFAULT_CONTAINER, $match["name"] ?: self::DEFAULT_VARIABLE); + if (preg_match('~^(?[a-zA-Z0-9_-]*):(?[a-zA-Z0-9_-]*)$~', $key, $match)) { + return [self::DEFAULT_REDUCER, $match['container'] ?: self::DEFAULT_CONTAINER, $match['name'] ?: + self::DEFAULT_VARIABLE]; } - else if(preg_match("~^(?[a-zA-Z0-9_-]*)$~", $key, $match)) - { - return array(self::DEFAULT_REDUCER, self::DEFAULT_CONTAINER, $match["name"] ?: self::DEFAULT_VARIABLE); + if (preg_match('~^(?[a-zA-Z0-9_-]*)$~', $key, $match)) { + return [self::DEFAULT_REDUCER, self::DEFAULT_CONTAINER, $match['name'] ?: self::DEFAULT_VARIABLE]; } throw new InvalidResultException; } - static public function encode($name, $container, $reducer) + public static function encode($name, $container, $reducer) { - return $reducer . ":" . $container . ":" . $name; + return $reducer . ':' . $container . ':' . $name; } } diff --git a/src/IO/Request.php b/src/IO/Request.php index ce00748..567b565 100644 --- a/src/IO/Request.php +++ b/src/IO/Request.php @@ -17,7 +17,7 @@ class Request extends BulkGate\Extensions\Strict private $url; /** @var array */ - private $data = array(); + private $data = []; /** @var string */ private $content_type; @@ -25,16 +25,16 @@ class Request extends BulkGate\Extensions\Strict /** @var int */ private $timeout; - public function __construct($url, array $data = array(), $compress = false, $timeout = 20) + public function __construct($url, array $data = [], $compress = false, $timeout = 20) { $this->setUrl($url); $this->setData($data, $compress); $this->timeout = max(3 /** min timeout */, (int) $timeout); } - public function setData(array $data = array(), $compress = false) + public function setData(array $data = [], $compress = false) { - $this->data = (array) $data; + $this->data = $data; $this->content_type = $compress ? self::CONTENT_TYPE_ZIP : self::CONTENT_TYPE_JSON; return $this; @@ -49,26 +49,19 @@ public function setUrl($url) public function getData() { - try - { - if($this->content_type === self::CONTENT_TYPE_ZIP) - { + try { + if ($this->content_type === self::CONTENT_TYPE_ZIP) { return BulkGate\Extensions\Compress::compress(BulkGate\Extensions\Json::encode($this->data)); } - else - { - return BulkGate\Extensions\Json::encode($this->data); - } - } - catch (BulkGate\Extensions\JsonException $e) - { + return BulkGate\Extensions\Json::encode($this->data); + } catch (BulkGate\Extensions\JsonException $e) { throw new InvalidRequestException; } } public function getUrl() { - return (string) $this->url; + return $this->url; } public function getContentType() diff --git a/src/IO/Response.php b/src/IO/Response.php index 8054f94..b3af4e0 100644 --- a/src/IO/Response.php +++ b/src/IO/Response.php @@ -1,68 +1,51 @@ load((array) $result); + if (is_array($result)) { + $this->load((array)$result); } + } catch (BulkGate\Extensions\JsonException $e) { + throw new InvalidResultException('Json parse error: ' . $data); } - catch (BulkGate\Extensions\JsonException $e) - { - throw new InvalidResultException('Json parse error: '. $data); - } - } - elseif($content_type === 'application/zip') - { + } elseif ($content_type === 'application/zip') { $result = Json::decode(BulkGate\Extensions\Compress::decompress($data)); - if(is_array($result) || $result instanceof \stdClass) - { - $this->load((array) $result); + if (is_array($result) || $result instanceof stdClass) { + $this->load((array)$result); } + } else { + throw new InvalidResultException('Invalid content type' . $data); } - else - { - throw new InvalidResultException('Invalid content type'. $data); - } - } - elseif(is_array($data)) - { + } elseif (is_array($data)) { $this->load($data); - } - else - { + } else { throw new InvalidResultException('Input not string (JSON)'); } } public function load(array $array) { - if(isset($array['signal']) && $array['signal'] === 'authenticate') - { + if (isset($array['signal']) && $array['signal'] === 'authenticate') { throw new AuthenticateException; - } - else - { - foreach($array as $key => $value) - { + } else { + foreach ($array as $key => $value) { $this->{$key} = $value; } } @@ -72,27 +55,17 @@ public function get($key) { $path = Key::decode($key); - return array_reduce($path, function($prev, $now) - { - if($now === Key::DEFAULT_VARIABLE) - { + return array_reduce($path, function ($prev, $now) { + if ($now === Key::DEFAULT_VARIABLE) { return $prev; - } - else - { - if($prev) - { - if(is_array($prev)) - { + } else { + if ($prev) { + if (is_array($prev)) { return isset($prev[$now]) ? $prev[$now] : null; - } - else - { + } else { return isset($prev->$now) ? $prev->$now : null; } - } - else - { + } else { return null; } } @@ -101,20 +74,19 @@ public function get($key) public function remove($key) { - if(isset($this->data)) - { + if (isset($this->data)) { list($reducer, $container, $variable) = Key::decode($key); - if(isset($this->data->{$reducer}) && isset($this->data->{$reducer}->{$container}) && isset($this->data->{$reducer}->{$container}->{$variable})) - { + if (isset( + $this->data->{$reducer}, + $this->data->{$reducer}->{$container}, + $this->data->{$reducer}->{$container}->{$variable} + ) + ) { unset($this->data->{$reducer}->{$container}->{$variable}); - } - else if(isset($this->data->{$reducer}) && isset($this->data->{$reducer}->{$container})) - { + } elseif (isset($this->data->{$reducer}, $this->data->{$reducer}->{$container})) { unset($this->data->{$reducer}->{$container}); - } - else if(isset($this->data->{$reducer})) - { + } elseif (isset($this->data->{$reducer})) { unset($this->data->{$reducer}); } } @@ -122,18 +94,15 @@ public function remove($key) public function set($key, $value) { - if(isset($this->data)) - { + if (isset($this->data)) { list($reducer, $container, $variable) = Key::decode($key); - if(!isset($this->data[$reducer])) - { - $this->data[$reducer] = array(); + if (!isset($this->data[$reducer])) { + $this->data[$reducer] = []; } - if(!isset($this->data[$reducer][$container])) - { - $this->data[$reducer][$container] = array(); + if (!isset($this->data[$reducer][$container])) { + $this->data[$reducer][$container] = []; } $this->data[$reducer][$container][$variable] = $value; diff --git a/src/IO/cUrl.php b/src/IO/cUrl.php index 0b254aa..6f587d0 100644 --- a/src/IO/cUrl.php +++ b/src/IO/cUrl.php @@ -32,8 +32,13 @@ class cUrl extends BulkGate\Extensions\Strict implements IConnection * @param $application_product * @param $application_language */ - public function __construct($application_id, $application_token, $application_url, $application_product, $application_language) - { + public function __construct( + $application_id, + $application_token, + $application_url, + $application_product, + $application_language + ) { $this->application_id = $application_id; $this->application_token = $application_token; $this->application_url = $application_url; @@ -50,26 +55,26 @@ public function run(Request $request) { $curl = curl_init(); - curl_setopt_array($curl, array( + curl_setopt_array($curl, [ CURLOPT_URL => $request->getUrl(), CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => $request->getTimeout(), - CURLOPT_SSL_VERIFYPEER => false, +// CURLOPT_SSL_VERIFYPEER => false, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HEADER => true, CURLINFO_HEADER_OUT => true, CURLOPT_POSTFIELDS => $request->getData(), - CURLOPT_HTTPHEADER => array( + CURLOPT_HTTPHEADER => [ 'Content-type: ' . $request->getContentType(), 'X-BulkGate-Application-ID: ' . (string) $this->application_id, 'X-BulkGate-Application-Token: ' . (string) $this->application_token, 'X-BulkGate-Application-Url: ' . (string) $this->application_url, 'X-BulkGate-Application-Product: '. (string) $this->application_product, 'X-BulkGate-Application-Language: '. (string) $this->application_language - ), - )); + ], + ]); /*curl_setopt($curl, CURLOPT_TIMEOUT_MS, 100); curl_setopt($curl, CURLOPT_NOSIGNAL, 1);*/ @@ -79,14 +84,18 @@ public function run(Request $request) $header = new HttpHeaders(substr($response, 0, $header_size)); $json = substr($response, $header_size); - if($json) - { + if ($json) { curl_close($curl); return new Response($json, $header->getContentType()); } $error = curl_error($curl); curl_close($curl); - return new Response(array('data' => array(), 'error' => array('Server ('.$request->getUrl().') is unavailable. Try contact your hosting provider. Reason: '. $error))); + return new Response([ + 'data' => [], + 'error' => [ + 'Server ('.$request->getUrl().') is unavailable. Try contact your hosting provider. Reason: '. $error + ] + ]); } } diff --git a/src/IO/exceptions.php b/src/IO/exceptions.php index c0b5cef..dc27a3f 100644 --- a/src/IO/exceptions.php +++ b/src/IO/exceptions.php @@ -7,10 +7,30 @@ * @author Lukáš Piják 2018 TOPefekt s.r.o. * @link https://www.bulkgate.com/ */ -class ConnectionException extends Extensions\Exception {} +class ConnectionException extends Extensions\Exception +{ +} -class InvalidRequestException extends ConnectionException {} +/** + * Class InvalidRequestException + * @package BulkGate\Extensions\IO + */ +class InvalidRequestException extends ConnectionException +{ +} -class InvalidResultException extends ConnectionException {} +/** + * Class InvalidResultException + * @package BulkGate\Extensions\IO + */ +class InvalidResultException extends ConnectionException +{ +} -class AuthenticateException extends ConnectionException {} +/** + * Class AuthenticateException + * @package BulkGate\Extensions\IO + */ +class AuthenticateException extends ConnectionException +{ +} diff --git a/src/ISettings.php b/src/ISettings.php index 4262e83..14ae88c 100644 --- a/src/ISettings.php +++ b/src/ISettings.php @@ -19,7 +19,7 @@ public function load($settings_key, $default = false); * @param mixed|$value * @param array $meta */ - public function set($settings_key, $value, array $meta = array()); + public function set($settings_key, $value, array $meta = []); /** * @param string|null $settings_key diff --git a/src/Iterator.php b/src/Iterator.php index 8d93c12..d9a95be 100644 --- a/src/Iterator.php +++ b/src/Iterator.php @@ -10,7 +10,7 @@ class Iterator extends Extensions\Strict implements \Iterator { /** @var array */ - protected $array = array(); + protected $array = []; /** @var int */ private $position = 0; @@ -21,47 +21,47 @@ public function __construct(array $rows) $this->position = 0; } - function get($key) + public function get($key) { return isset($this->array[$key]) ? $this->array[$key] : null; } - function set($key, $value) + public function set($key, $value) { return $this->array[$key] = $value; } - function rewind() + public function rewind() { reset($this->array); } - function current() + public function current() { return current($this->array); } - function key() + public function key() { return key($this->array); } - function next() + public function next() { next($this->array); } - function valid() + public function valid() { return key($this->array) !== null; } - function count() + public function count() { return count($this->array); } - function add($value) + public function add($value) { $this->array[] = $value; } diff --git a/src/Json.php b/src/Json.php index 086cbbe..bd9a90f 100644 --- a/src/Json.php +++ b/src/Json.php @@ -18,8 +18,9 @@ class Json public static function encode($value, $options = 0) { $flags = JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES - | ($options & self::PRETTY ? JSON_PRETTY_PRINT : 0) - | (defined('JSON_PRESERVE_ZERO_FRACTION') ? JSON_PRESERVE_ZERO_FRACTION : 0); // since PHP 5.6.6 & PECL JSON-C 1.3.7 + | (($options & self::PRETTY) ? JSON_PRETTY_PRINT : 0) + | (defined('JSON_PRESERVE_ZERO_FRACTION') ? JSON_PRESERVE_ZERO_FRACTION : 0); + // since PHP 5.6.6 & PECL JSON-C 1.3.7 $json = json_encode($value, $flags); if ($error = json_last_error()) { @@ -27,7 +28,7 @@ public static function encode($value, $options = 0) } if (PHP_VERSION_ID < 70100) { - $json = str_replace(array("\xe2\x80\xa8", "\xe2\x80\xa9"), array('\u2028', '\u2029'), $json); + $json = str_replace(["\xe2\x80\xa8", "\xe2\x80\xa9"], ['\u2028', '\u2029'], $json); } return $json; @@ -35,7 +36,7 @@ public static function encode($value, $options = 0) public static function decode($json, $options = 0) { - $json = str_replace(array("\f", "\n", "\r", "\t"), array("\\f", "\\n", "\\r", "\\t"), $json); + $json = str_replace(["\f", "\n", "\r", "\t"], ["\\f", "\\n", "\\r", "\\t"], $json); $forceArray = (bool) ($options & self::FORCE_ARRAY); $flags = JSON_BIGINT_AS_STRING; @@ -44,11 +45,15 @@ public static function decode($json, $options = 0) $json = (string) $json; if ($json === '') { throw new JsonException('Syntax error'); - } elseif (!$forceArray && preg_match('#(?<=[^\\\\]")\\\\u0000(?:[^"\\\\]|\\\\.)*+"\s*+:#', $json)) { - throw new JsonException('The decoded property name is invalid'); // fatal error when object key starts with \u0000 - } elseif (defined('JSON_C_VERSION') && !preg_match('##u', $json)) { + } + if (!$forceArray && preg_match('#(?<=[^\\\\]")\\\\u0000(?:[^"\\\\]|\\\\.)*+"\s*+:#', $json)) { + throw new JsonException('The decoded property name is invalid'); + // fatal error when object key starts with \u0000 + } + if (defined('JSON_C_VERSION') && !preg_match('##u', $json)) { throw new JsonException('Invalid UTF-8 sequence', 5); - } elseif (defined('JSON_C_VERSION') && PHP_INT_SIZE === 8) { + } + if (defined('JSON_C_VERSION') && PHP_INT_SIZE === 8) { $flags &= ~JSON_BIGINT_AS_STRING; // not implemented in PECL JSON-C 1.3.2 for 64bit systems } } diff --git a/src/Key.php b/src/Key.php index 39885a2..bb2ec56 100644 --- a/src/Key.php +++ b/src/Key.php @@ -9,20 +9,18 @@ class Key { const DEFAULT_SCOPE = 'main'; - static public function decode($key) + public static function decode($key) { - if(preg_match('~^(?[a-zA-Z0-9_\-;]*):(?[a-zA-Z0-9_\-;]*)$~', $key, $match)) - { - return array($match['scope'] ?: self::DEFAULT_SCOPE, $match['key'] ?: null); + if (preg_match('~^(?[a-zA-Z0-9_\-;]*):(?[a-zA-Z0-9_\-;]*)$~', $key, $match)) { + return [$match['scope'] ?: self::DEFAULT_SCOPE, $match['key'] ?: null]; } - else if(preg_match('~^(?[a-zA-Z0-9_\-;]*)$~', $key, $match)) - { - return array(self::DEFAULT_SCOPE, $match['key'] ?: null); + if (preg_match('~^(?[a-zA-Z0-9_\-;]*)$~', $key, $match)) { + return [self::DEFAULT_SCOPE, $match['key'] ?: null]; } throw new InvalidKeyException; } - static public function encode($scope, $key, $delimiter = ':') + public static function encode($scope, $key, $delimiter = ':') { return $scope . $delimiter . $key; } diff --git a/src/LocaleIntl.php b/src/LocaleIntl.php index 453d2d0..eaeb950 100644 --- a/src/LocaleIntl.php +++ b/src/LocaleIntl.php @@ -1,7 +1,11 @@ number_formatter = new NumberFormatter($locale, NumberFormatter::DECIMAL); $this->currency_formatter = new NumberFormatter($locale, NumberFormatter::CURRENCY); - $this->datetime_formatter = new IntlDateFormatter($locale, + $this->datetime_formatter = new IntlDateFormatter( + $locale, IntlDateFormatter::MEDIUM, IntlDateFormatter::MEDIUM, $timeZone ? $timeZone->getName() : null ); - $this->date_formatter = new IntlDateFormatter($locale, + $this->date_formatter = new IntlDateFormatter( + $locale, IntlDateFormatter::MEDIUM, IntlDateFormatter::NONE ); - $this->time_formatter = new IntlDateFormatter($locale, + $this->time_formatter = new IntlDateFormatter( + $locale, IntlDateFormatter::NONE, IntlDateFormatter::MEDIUM, $timeZone ? $timeZone->getName() : null ); - } - else - { + } else { throw new ServiceNotFoundException('PHP extension INTL not installed'); } } - public function price($price, $currency = null) { - if($currency === null) - { + if ($currency === null) { return $this->float($price); } - if($p = $this->currency_formatter->formatCurrency($price, strtoupper($currency))) - { + if ($p = $this->currency_formatter->formatCurrency($price, strtoupper($currency))) { return $p; } return $this->float($price).$currency; } - public function float($number) { return $this->number_formatter->format($number, NumberFormatter::TYPE_DOUBLE); } - public function int($number) { return $this->number_formatter->format($number, NumberFormatter::TYPE_INT64); } - - public function datetime(\DateTime $dateTime) + public function datetime(DateTime $dateTime) { return $this->datetime_formatter->format($dateTime); } - - public function date(\DateTime $date) + public function date(DateTime $date) { return $this->date_formatter->format($date); } - - public function time(\DateTime $date) + public function time(DateTime $date) { return $this->time_formatter->format($date); } diff --git a/src/LocaleSimple.php b/src/LocaleSimple.php index 94b46b8..e5c1aea 100644 --- a/src/LocaleSimple.php +++ b/src/LocaleSimple.php @@ -2,6 +2,7 @@ namespace BulkGate\Extensions; use BulkGate; +use DateTime; /** * @author Lukáš Piják 2018 TOPefekt s.r.o. @@ -21,43 +22,36 @@ public function __construct($date_format = "d/m/Y", $time_format = "H:i:s") $this->time_format = $time_format; } - public function price($price, $currency = null) { - if($currency === null) - { + if ($currency === null) { return $this->float($price); } return $this->float($price).' '.$currency; } - public function float($number) { return (string) number_format((float) $number, 2); } - public function int($number) { return (string) (int) $number; } - - public function datetime(\DateTime $date_time) + public function datetime(DateTime $date_time) { return $date_time->format($this->date_format.' '.$this->time_format); } - - public function date(\DateTime $date) + public function date(DateTime $date) { return $date->format($this->date_format); } - - public function time(\DateTime $date) + public function time(DateTime $date) { return $date->format($this->time_format); } diff --git a/src/ProxyActions.php b/src/ProxyActions.php index 63f1df1..3f38e57 100644 --- a/src/ProxyActions.php +++ b/src/ProxyActions.php @@ -1,6 +1,7 @@ connection = $connection; $this->module = $module; $this->synchronize = $synchronize; @@ -43,9 +50,8 @@ public function login(array $data) $login = (array) $response->get('::login'); - if(isset($login['application_id']) && isset($login['application_token'])) - { - $this->settings->set('static:application_id', $login['application_id'], array('type' => 'int')); + if (isset($login['application_id']) && isset($login['application_token'])) { + $this->settings->set('static:application_id', $login['application_id'], ['type' => 'int']); $this->settings->set('static:application_token', $login['application_token']); $this->settings->set('static:synchronize', 0); return isset($login['application_token_temp']) ? $login['application_token_temp'] : 'guest'; @@ -64,9 +70,8 @@ public function register(array $data) $register = (array) $response->get('::register'); - if(isset($register['application_id']) && isset($register['application_token'])) - { - $this->settings->set('static:application_id', $register['application_id'], array('type' => 'int')); + if (isset($register['application_id']) && isset($register['application_token'])) { + $this->settings->set('static:application_id', $register['application_id'], ['type' => 'int']); $this->settings->set('static:application_token', $register['application_token']); $this->settings->set('static:synchronize', 0); return isset($register['application_token_temp']) ? $register['application_token_temp'] : 'guest'; @@ -76,12 +81,9 @@ public function register(array $data) public function authenticate() { - try - { + try { return $this->connection->run(new IO\Request($this->module->getUrl('/widget/authenticate'))); - } - catch (IO\AuthenticateException $e) - { + } catch (IO\AuthenticateException $e) { $this->settings->delete('static:application_token'); throw $e; } @@ -89,20 +91,17 @@ public function authenticate() public function saveSettings(array $settings) { - if(isset($settings['delete_db'])) - { - $this->settings->set('main:delete_db', $settings['delete_db'], array('type' => 'int')); + if (isset($settings['delete_db'])) { + $this->settings->set('main:delete_db', $settings['delete_db'], ['type' => 'int']); } - if(isset($settings['language'])) - { + if (isset($settings['language'])) { $this->translator->setLanguage($settings['language']); } - if(isset($settings['language_mutation'])) - { - $this->settings->set('main:language_mutation', $settings['language_mutation'], array('type' => 'int')); - $this->settings->set('static:synchronize', 0, array('type' => 'int')); + if (isset($settings['language_mutation'])) { + $this->settings->set('main:language_mutation', $settings['language_mutation'], ['type' => 'int']); + $this->settings->set('static:synchronize', 0, ['type' => 'int']); } } @@ -110,10 +109,10 @@ public function saveCustomerNotifications(array $data) { $self = $this; - return $this->synchronize->synchronize(function($module_settings) use ($self, $data) - { - return $self->connection->run(new IO\Request($self->module->getUrl('/module/hook/customer'), - array_merge(array("__synchronize" => $module_settings), $data), + return $this->synchronize->synchronize(function ($module_settings) use ($self, $data) { + return $self->connection->run(new IO\Request( + $self->module->getUrl('/module/hook/customer'), + array_merge(["__synchronize" => $module_settings], $data), true )); }); @@ -123,28 +122,42 @@ public function saveAdminNotifications(array $data) { $self = $this; - return $this->synchronize->synchronize(function($module_settings) use ($self, $data) - { - return $self->connection->run(new IO\Request($self->module->getUrl('/module/hook/admin'), - array_merge(array("__synchronize" => $module_settings), $data), + return $this->synchronize->synchronize(function ($module_settings) use ($self, $data) { + return $self->connection->run(new IO\Request( + $self->module->getUrl('/module/hook/admin'), + array_merge(["__synchronize" => $module_settings], $data), true )); }); } - public function loadCustomersCount($application_id, $id, $type = 'load', array $data = array()) + public function loadCustomersCount($application_id, $id, $type = 'load', array $data = []) { - switch ($type) - { + switch ($type) { case 'addFilter': - $response = $this->connection->run(new IO\Request($this->module->getUrl('/module/sms-campaign/add-filter/'.(int)$id), $data, false, 60)); + $response = $this->connection->run(new IO\Request( + $this->module->getUrl('/module/sms-campaign/add-filter/' . (int)$id), + $data, + false, + 60 + )); break; case 'removeFilter': - $response = $this->connection->run(new IO\Request($this->module->getUrl('/module/sms-campaign/remove-filter/'.(int)$id), $data, false, 60)); + $response = $this->connection->run(new IO\Request( + $this->module->getUrl('/module/sms-campaign/remove-filter/' . (int)$id), + $data, + false, + 60 + )); break; case 'load': default: - $response = $this->connection->run(new IO\Request($this->module->getUrl('/module/sms-campaign/load/'.(int)$id), array(), false, 60)); + $response = $this->connection->run(new IO\Request( + $this->module->getUrl('/module/sms-campaign/load/' . (int)$id), + [], + false, + 60 + )); break; } @@ -153,7 +166,7 @@ public function loadCustomersCount($application_id, $id, $type = 'load', array $ $response->set('campaign::module_recipients', $this->customers->loadCount( isset($campaign['filter_module']) && isset($campaign['filter_module'][$application_id]) ? $campaign['filter_module'][$application_id] : - array() + [] )); return $response; @@ -165,12 +178,14 @@ public function saveModuleCustomers($application_id, $campaign_id) $campaign = $response->get('campaign::campaign'); - return $this->connection->run(new IO\Request($this->module->getUrl('/module/sms-campaign/save/'.(int) $campaign_id), array( - 'customers' => $this->customers->load( + return $this->connection->run(new IO\Request( + $this->module->getUrl('/module/sms-campaign/save/'.(int) $campaign_id), + ['customers' => $this->customers->load( isset($campaign['filter_module']) && isset($campaign['filter_module'][$application_id]) ? - $campaign['filter_module'][$application_id] : - array() - ) - ), true, 120)); + $campaign['filter_module'][$application_id] : [] + )], + true, + 120 + )); } } diff --git a/src/Settings.php b/src/Settings.php index 2973aac..32de57f 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -2,6 +2,7 @@ namespace BulkGate\Extensions; use BulkGate; +use DateTime; /** * @author Lukáš Piják 2018 TOPefekt s.r.o. @@ -10,7 +11,7 @@ class Settings extends Strict implements ISettings { /** @var array */ - public $data = array(); + public $data = []; /** @var BulkGate\Extensions\Database\IDatabase */ private $db; @@ -24,76 +25,59 @@ public function load($settings_key, $default = false) { list($scope, $key) = BulkGate\Extensions\Key::decode($settings_key); - if(isset($this->data[$scope])) - { - if(isset($this->data[$scope][$key])) - { + if (isset($this->data[$scope])) { + if (isset($this->data[$scope][$key])) { return $this->data[$scope][$key]; } - else if(isset($this->data[$scope]) && !isset($this->data[$scope][$key]) && $key !== null) - { + if (!isset($this->data[$scope][$key]) && $key !== null) { return $default; } - else - { - return $this->data[$scope]; - } + return $this->data[$scope]; } - else - { - $result = $this->db->execute( - $this->db->prepare( - 'SELECT * FROM `'.$this->db->table('bulkgate_module').'` WHERE `scope` = %s AND `synchronize_flag` != "delete" ORDER BY `order`', - array( - $scope - ) - ) - ); + $result = $this->db->execute( + $this->db->prepare( + 'SELECT * FROM `' . $this->db->table('bulkgate_module') . + '` WHERE `scope` = %s AND `synchronize_flag` != "delete" ORDER BY `order`', + [ + $scope + ] + ) + ); - if($result->getNumRows() > 0) - { - foreach ($result as $item) - { - switch($item->type) - { - case "text": - $this->data[$scope][$item->key] = (string) $item->value; + if ($result->getNumRows() > 0) { + foreach ($result as $item) { + switch ($item->type) { + case "text": + $this->data[$scope][$item->key] = (string)$item->value; break; - case "int": - $this->data[$scope][$item->key] = (int) $item->value; + case "int": + $this->data[$scope][$item->key] = (int)$item->value; break; - case "float": - $this->data[$scope][$item->key] = (float) $item->value; + case "float": + $this->data[$scope][$item->key] = (float)$item->value; break; - case "bool": - $this->data[$scope][$item->key] = (bool) $item->value; + case "bool": + $this->data[$scope][$item->key] = (bool)$item->value; break; - case "json": - try - { - $this->data[$scope][$item->key] = BulkGate\Extensions\Json::decode($item->value); - } - catch (BulkGate\Extensions\JsonException $e) - { - $this->data[$scope][$item->key] = null; - } + case "json": + try { + $this->data[$scope][$item->key] = BulkGate\Extensions\Json::decode($item->value); + } catch (BulkGate\Extensions\JsonException $e) { + $this->data[$scope][$item->key] = null; + } break; - } } } - else - { - $this->data[$scope] = false; - } - return $this->load($settings_key); + } else { + $this->data[$scope] = false; } + return $this->load($settings_key); } - public function set($settings_key, $value, array $meta = array()) + public function set($settings_key, $value, array $meta = []) { - if(!isset($meta['datetime'])) - { + if (!isset($meta['datetime'])) { $meta['datetime'] = time(); } @@ -101,69 +85,67 @@ public function set($settings_key, $value, array $meta = array()) $result = $this->db->execute( $this->db->prepare( - 'SELECT * FROM `'.$this->db->table('bulkgate_module').'` WHERE `scope` = %s AND `key` = %s', - array( + 'SELECT * FROM `' . $this->db->table('bulkgate_module') . '` WHERE `scope` = %s AND `key` = %s', + [ $scope, $key - ) + ] ) ); - if($result->getNumRows() > 0) - { + if ($result->getNumRows() > 0) { $this->db->execute( $this->db->prepare( - 'UPDATE `'.$this->db->table('bulkgate_module').'` SET value = %s, `datetime` = %s '.$this->parseMeta($meta).' WHERE `scope` = %s AND `key` = %s', - array( + 'UPDATE `' . $this->db->table('bulkgate_module') . '` SET value = %s, `datetime` = %s ' . + $this->parseMeta($meta) . ' WHERE `scope` = %s AND `key` = %s', + [ $value, $meta['datetime'], $scope, $key - ) - )); - } - else - { + ] + ) + ); + } else { $this->db->execute( - $this->db->prepare(' - INSERT INTO `'.$this->db->table('bulkgate_module').'` SET - `scope`= %s, - `key`= %s, - `value`= %s'.$this->parseMeta($meta).' - ', array( - $scope, $key, $value - )) + $this->db->prepare( + 'INSERT INTO `' . $this->db->table('bulkgate_module') . '` SET + `scope`= %s, + `key`= %s, + `value`= %s' . $this->parseMeta($meta).' + ', + [ + $scope, $key, $value + ] + ) ); } } public function delete($settings_key = null) { - if($settings_key === null) - { + if ($settings_key === null) { $this->db->execute(' - DELETE FROM `'.$this->db->table('bulkgate_module').'` WHERE `synchronize_flag` = "delete" + DELETE FROM `' . $this->db->table('bulkgate_module') . '` WHERE `synchronize_flag` = "delete" '); - } - else - { + } else { list($scope, $key) = BulkGate\Extensions\Key::decode($settings_key); $this->db->execute( $this->db->prepare(' - DELETE FROM `'.$this->db->table('bulkgate_module').'` WHERE `scope` = %s AND `key` = %s - ', array( + DELETE FROM `' . $this->db->table('bulkgate_module') . '` WHERE `scope` = %s AND `key` = %s + ', [ $scope, $key - )) + ]) ); } } public function synchronize() { - $output = array(); + $output = []; - $result = $this->db->execute('SELECT * FROM `'.$this->db->table('bulkgate_module').'` WHERE `scope` != "static"')->getRows(); + $result = $this->db->execute('SELECT * FROM `'.$this->db->table('bulkgate_module'). + '` WHERE `scope` != "static"')->getRows(); - foreach($result as $row) - { - $output[$row->scope.':'.$row->key] = $row; + foreach ($result as $row) { + $output[$row->scope . ':' . $row->key] = $row; } return $output; @@ -183,37 +165,34 @@ public function install() PRIMARY KEY (`scope`,`key`) ) DEFAULT CHARSET=utf8; "); - $this->set('static:synchronize', 0, array('type' => 'int')); + $this->set('static:synchronize', 0, ['type' => 'int']); } public function uninstall() { - if ($this->load('main:delete_db', false)) - { + if ($this->load('main:delete_db', false)) { $this->db->execute("DROP TABLE IF EXISTS `" . $this->db->table('bulkgate_module') . "`"); } } private function parseMeta(array $meta) { - $output = array(); + $output = []; - foreach($meta as $key => $item) - { - switch ($key) - { + foreach ($meta as $key => $item) { + switch ($key) { case 'type': - $output[] = $this->db->prepare('`type`= %s', array($this->checkType($item))); - break; + $output[] = $this->db->prepare('`type`= %s', [$this->checkType($item)]); + break; case 'datetime': - $output[] = $this->db->prepare('`datetime`= %s', array($this->formatDate($item))); - break; + $output[] = $this->db->prepare('`datetime`= %s', [$this->formatDate($item)]); + break; case 'order': - $output[] = $this->db->prepare('`order`= %s', array((int) $item)); - break; + $output[] = $this->db->prepare('`order`= %s', [(int)$item]); + break; case 'synchronize_flag': - $output[] = $this->db->prepare('`synchronize_flag`= %s', array($this->checkFlag($item))); - break; + $output[] = $this->db->prepare('`synchronize_flag`= %s', [$this->checkFlag($item)]); + break; } } return count($output) > 0 ? ','.implode(',', $output) : ''; @@ -221,38 +200,31 @@ private function parseMeta(array $meta) private function formatDate($date) { - if($date instanceof \DateTime) - { + if ($date instanceof DateTime) { return $date->getTimestamp(); - } - else if(is_string($date)) - { + } elseif (is_string($date)) { return strtotime($date); - } - else if(is_int($date)) - { + } elseif (is_int($date)) { return $date; } return time(); } - private $types = array('text','int','float','bool','json'); + private $types = ['text', 'int', 'float', 'bool', 'json']; private function checkType($type, $default = 'text') { - if(in_array((string) $type, $this->types)) - { + if (in_array((string)$type, $this->types, true)) { return $type; } return $default; } - private $flags = array('none','add','change','delete'); + private $flags = ['none', 'add', 'change', 'delete']; private function checkFlag($flag, $default = 'none') { - if(in_array((string) $flag, $this->flags)) - { + if (in_array((string)$flag, $this->flags, true)) { return $flag; } return $default; diff --git a/src/Strict.php b/src/Strict.php index 8d8c502..9ff0125 100644 --- a/src/Strict.php +++ b/src/Strict.php @@ -16,14 +16,12 @@ public function __get($name) { $class = get_class($this); - if(property_exists($class, $name)) - { + if (property_exists($class, $name)) { return $this->$name; } throw new StrictException("Cannot read an undeclared property $class::\$$name."); } - /** * @param $name * @param $value @@ -33,14 +31,12 @@ public function __set($name, $value) { $class = get_class($this); - if(property_exists($class, $name)) - { + if (property_exists($class, $name)) { $this->$name = $value; } throw new StrictException("Cannot write an undeclared property $class::\$$name."); } - /** * @param string $name * @return bool @@ -49,14 +45,12 @@ public function __isset($name) { $class = get_class($this); - if(property_exists($class, $name)) - { + if (property_exists($class, $name)) { return isset($this->$name); } return false; } - /** * @param string $name * @throws StrictException @@ -66,7 +60,6 @@ public function __unset($name) throw new StrictException('You can\'t unset undeclared property '.__CLASS__.'::$'.$name); } - /** * @param string $name * @param array $arguments @@ -77,7 +70,6 @@ public function __call($name, array $arguments) throw new StrictException('You can\'t call undeclared method '.__CLASS__.'::$'.$name); } - /** * @param string $name * @param array $arguments diff --git a/src/Synchronize.php b/src/Synchronize.php index 939a11b..8eedb63 100644 --- a/src/Synchronize.php +++ b/src/Synchronize.php @@ -24,61 +24,80 @@ public function __construct(ISettings $settings, IO\IConnection $connection) public function run($url, $now = false) { - try - { - if ($now || $this->settings->load('static:synchronize', 0) < time() && $this->settings->load('static:application_id', false)) - { + try { + if ($now || ($this->settings->load('static:synchronize', 0) < time() && + $this->settings->load('static:application_id', false))) { $self = $this; $this->synchronize(function ($module_settings) use ($url, $self) { - return $self->connection->run(new IO\Request($url, array('__synchronize' => $module_settings), true, (int) $self->settings->load('main:synchronize_timeout', 6))); + return $self->connection->run(new IO\Request( + $url, + ['__synchronize' => $module_settings], + true, + (int)$self->settings->load('main:synchronize_timeout', 6) + )); }); } - } - catch (AuthenticateException $e) - { + } catch (AuthenticateException $e) { $this->settings->delete('static:application_token'); } } public function synchronize($callback) { - if (is_callable($callback)) - { + if (is_callable($callback)) { $module_settings = $this->settings->synchronize(); $server_settings = call_user_func($callback, $module_settings); - if((isset($server_settings->exception) && $server_settings->exception) || (isset($server_setting->error) && !empty($server_settings->error))) - { + if ((isset($server_settings->exception) && $server_settings->exception) || + (isset($server_setting->error) && !empty($server_settings->error))) { return $server_settings; } - else - { - if ($server_settings instanceof Response) - { - foreach ((array) $server_settings->get(':synchronize:') as $server_setting) - { - $key = $this->getKey($server_setting->scope, $server_setting->key); + if ($server_settings instanceof Response) { + foreach ((array)$server_settings->get(':synchronize:') as $server_setting) { + $key = $this->getKey($server_setting->scope, $server_setting->key); - if (isset($module_settings[$key])) - { - $server_setting->datetime = isset($server_setting->datetime) ? (int)$server_setting->datetime : 0; - $module_settings[$key]->datetime = isset($module_settings[$key]->datetime) ? (int)$module_settings[$key]->datetime : 0; + if (isset($module_settings[$key])) { + $server_setting->datetime = isset($server_setting->datetime) ? + (int)$server_setting->datetime : 0; + $module_settings[$key]->datetime = isset($module_settings[$key]->datetime) ? + (int)$module_settings[$key]->datetime : 0; - if ($server_setting->datetime >= $module_settings[$key]->datetime) - { - $this->settings->set($key, $server_setting->value, array('type' => isset($server_setting->type) ? $server_setting->type : 'text', 'datetime' => $server_setting->datetime, 'synchronize_flag' => $server_setting->synchronize_flag, 'order' => isset($server_setting->order) ? $server_setting->order : 0,)); - } - } - else - { - $this->settings->set($key, $server_setting->value, array('type' => isset($server_setting->type) ? $server_setting->type : 'text', 'datetime' => isset($server_setting->datetime) ? $server_setting->datetime : 0, 'order' => isset($server_setting->order) ? $server_setting->order : 0, 'synchronize_flag' => isset($server_setting->synchronize_flag) ? $server_setting->synchronize_flag : 'none')); + if ($server_setting->datetime >= $module_settings[$key]->datetime) { + $this->settings->set( + $key, + $server_setting->value, + [ + 'type' => isset($server_setting->type) ? $server_setting->type : 'text', + 'datetime' => $server_setting->datetime, + 'synchronize_flag' => $server_setting->synchronize_flag, + 'order' => isset($server_setting->order) ? $server_setting->order : 0, + ] + ); } + } else { + $this->settings->set( + $key, + $server_setting->value, + [ + 'type' => isset($server_setting->type) ? $server_setting->type : 'text', + 'datetime' => isset($server_setting->datetime) ? $server_setting->datetime : 0, + 'order' => isset($server_setting->order) ? $server_setting->order : 0, + 'synchronize_flag' => isset($server_setting->synchronize_flag) ? + $server_setting->synchronize_flag : 'none' + ] + ); } + } - $this->settings->delete(); + $this->settings->delete(); - $this->settings->set('static:synchronize', time() + $this->settings->load('main:synchronize_interval', 21600 /* 6 hours */)); - } + $this->settings->set( + 'static:synchronize', + time() + $this->settings->load( + 'main:synchronize_interval', + 21600 /* 6 hours */ + ) + ); } $server_settings->remove(':synchronize:'); diff --git a/src/Translator.php b/src/Translator.php index 03d12fe..947abbb 100644 --- a/src/Translator.php +++ b/src/Translator.php @@ -14,7 +14,7 @@ class Translator extends Strict private $iso = null; /** @var array */ - private $translates = array(); + private $translates = []; public function __construct(ISettings $settings) { @@ -25,12 +25,10 @@ public function init($iso = null) { $this->iso = $iso ? $iso : $this->settings->load('main:language', 'en'); - if($this->iso) - { - $translates = (array) $this->settings->load('translates:'.$this->iso); + if ($this->iso) { + $translates = (array)$this->settings->load('translates:' . $this->iso); - if($translates && is_array($translates)) - { + if ($translates && is_array($translates)) { $this->translates = $translates; } } @@ -38,23 +36,20 @@ public function init($iso = null) public function setLanguage($iso) { - $this->settings->set('main:language', $iso, array('type' => 'string')); + $this->settings->set('main:language', $iso, ['type' => 'string']); } public function translate($key, $default = null) { - if($this->iso === null) - { + if ($this->iso === null) { $this->init(); } - if(isset($this->translates[$key])) - { + if (isset($this->translates[$key])) { return $this->translates[$key]; } - if($default === null) - { + if ($default === null) { return ucfirst(str_replace('_', ' ', $key)); } diff --git a/src/_extension.php b/src/_extension.php index 6f22007..a6445ed 100644 --- a/src/_extension.php +++ b/src/_extension.php @@ -58,7 +58,6 @@ require_once __DIR__.'/Api/Response.php'; require_once __DIR__.'/Api/Api.php'; -if(file_exists(__DIR__.'/Hook/IExtension.php')) -{ - require_once __DIR__.'/Hook/IExtension.php'; +if (file_exists(__DIR__ . '/Hook/IExtension.php')) { + require_once __DIR__ . '/Hook/IExtension.php'; } diff --git a/src/debug.php b/src/debug.php index 27577e4..bac87c9 100644 --- a/src/debug.php +++ b/src/debug.php @@ -5,12 +5,10 @@ * @link https://www.bulkgate.com/ */ -if(isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST'] === 'localhost') -{ - if(file_exists(__DIR__.'/../../../../../Tracy/tracy.php')) - { +if (isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST'] === 'localhost') { + if (file_exists(__DIR__ . '/../../../../../Tracy/tracy.php')) { error_reporting(1); - require_once __DIR__.'/../../../../../Tracy/tracy.php'; + require_once __DIR__ . '/../../../../../Tracy/tracy.php'; Tracy\Debugger::$strictMode = true; Tracy\Debugger::$maxDepth = 10; Tracy\Debugger::enable(); diff --git a/src/exceptions.php b/src/exceptions.php index 957b76e..7ac777a 100644 --- a/src/exceptions.php +++ b/src/exceptions.php @@ -5,12 +5,38 @@ * @author Lukáš Piják 2018 TOPefekt s.r.o. * @link https://www.bulkgate.com/ */ -class Exception extends \Exception {} +class Exception extends \Exception +{ +} -class StrictException extends Exception {} +/** + * Class StrictException + * @package BulkGate\Extensions + */ +class StrictException extends Exception +{ +} -class JsonException extends Exception {} +/** + * Class JsonException + * @package BulkGate\Extensions + */ +class JsonException extends Exception +{ +} -class InvalidKeyException extends Exception {} +/** + * Class InvalidKeyException + * @package BulkGate\Extensions + */ +class InvalidKeyException extends Exception +{ +} -class ServiceNotFoundException extends Exception {} +/** + * Class ServiceNotFoundException + * @package BulkGate\Extensions + */ +class ServiceNotFoundException extends Exception +{ +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 26edfda..6d32c14 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -4,13 +4,10 @@ * @link https://www.bulkgate.com/ */ -if(file_exists(__DIR__.'/Tester/bootstrap.php')) -{ - require_once __DIR__.'/Tester/bootstrap.php'; +if (file_exists(__DIR__ . '/Tester/bootstrap.php')) { + require_once __DIR__ . '/Tester/bootstrap.php'; Tester\Environment::setup(); -} -else -{ +} else { exit("Nette tester not found"); -} \ No newline at end of file +}