diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
new file mode 100644
index 0000000..a884008
--- /dev/null
+++ b/.github/workflows/main.yml
@@ -0,0 +1,58 @@
+name: build
+
+on:
+ push:
+ branches:
+ - master
+ pull_request:
+ types:
+ - opened
+ - reopened
+ - edited
+ - synchronize
+
+env:
+ COVERAGE: '1'
+ default_php_version: '8.2'
+ php_extensions: 'pcov, json'
+
+jobs:
+ vars:
+ runs-on: 'ubuntu-latest'
+ outputs:
+ default_php_version: ${{ env.default_php_version }}
+ php_extensions: ${{ env.php_extensions }}
+ steps:
+ - run: echo "Exposing env vars"
+
+ lint:
+ name: 'Lint code'
+ needs: vars
+ uses: 'tochka-developers/actions/.github/workflows/lint.yml@v1'
+ with:
+ php-version: ${{ needs.vars.outputs.default_php_version }}
+ php-extensions: ${{ needs.vars.outputs.php_extensions }}
+
+ composer-audit:
+ name: 'Composer Audit'
+ needs: vars
+ uses: 'tochka-developers/actions/.github/workflows/composer-audit.yml@v1'
+ with:
+ php-version: ${{ needs.vars.outputs.default_php_version }}
+ php-extensions: ${{ needs.vars.outputs.php_extensions }}
+
+ tests:
+ name: 'Tests'
+ needs: vars
+ strategy:
+ fail-fast: false
+ matrix:
+ php-versions: [ '8.2', '8.3', '8.4', '8.5' ]
+ uses: 'tochka-developers/actions/.github/workflows/tests.yml@v1'
+ with:
+ php-version: ${{ matrix.php-versions }}
+ php-extensions: ${{ needs.vars.outputs.php_extensions }}
+
+ coverage:
+ needs: tests
+ uses: 'tochka-developers/actions/.github/workflows/coveralls.yml@v1'
diff --git a/composer.json b/composer.json
index 41632bd..2a0a6e6 100755
--- a/composer.json
+++ b/composer.json
@@ -14,15 +14,15 @@
"laravel"
],
"require": {
- "php": "8.1.*|8.2.*|8.3.*|8.4.*",
+ "php": "8.1.*|8.2.*|8.3.*|8.4.*|8.5.*",
"ext-json": "*",
- "illuminate/log": "^9.0|^10.0|^11.0|^12.0",
- "illuminate/cache": "^9.0|^10.0|^11.0|^12.0",
- "illuminate/config": "^9.0|^10.0|^11.0|^12.0",
- "illuminate/container": "^9.0|^10.0|^11.0|^12.0",
- "illuminate/console": "^9.0|^10.0|^11.0|^12.0",
- "illuminate/support": "^9.0|^10.0|^11.0|^12.0",
- "illuminate/pipeline": "^9.0|^10.0|^11.0|^12.0",
+ "illuminate/log": "^9.0|^10.0|^11.0|^12.0|^13.0",
+ "illuminate/cache": "^9.0|^10.0|^11.0|^12.0|^13.0",
+ "illuminate/config": "^9.0|^10.0|^11.0|^12.0|^13.0",
+ "illuminate/container": "^9.0|^10.0|^11.0|^12.0|^13.0",
+ "illuminate/console": "^9.0|^10.0|^11.0|^12.0|^13.0",
+ "illuminate/support": "^9.0|^10.0|^11.0|^12.0|^13.0",
+ "illuminate/pipeline": "^9.0|^10.0|^11.0|^12.0|^13.0",
"tochka-developers/jsonrpc-annotations": "^1.3",
"tochka-developers/jsonrpc-standard": "^1.4",
"php-http/discovery": "^1.15",
@@ -36,7 +36,7 @@
"laravel/pint": "^1.4",
"mockery/mockery": "^1.0",
"php-http/mock-client": "^1.5",
- "orchestra/testbench": "^7.1|^8.0|^9.0|^10.0",
+ "orchestra/testbench": "^7.1|^8.0|^9.0|^10.0|^11.0",
"phpunit/phpunit": "^9.6|^10.5|^11.5",
"timacdonald/log-fake": "^2.0",
"vimeo/psalm": "^5.6|^6.0"
@@ -59,9 +59,9 @@
}
},
"scripts": {
- "lint": "php8.1 vendor/bin/pint --test",
- "lint-fix": "php8.1 vendor/bin/pint",
- "analyze": "php8.1 vendor/bin/psalm --php-version=8.1 --no-cache",
+ "lint": "php vendor/bin/pint --test",
+ "lint-fix": "php vendor/bin/pint",
+ "analyze": "php vendor/bin/psalm --php-version=8.1 --no-cache",
"pint": "vendor/bin/pint",
"psalm": "vendor/bin/psalm --output-format=phpstorm --no-cache"
},
diff --git a/phpunit.xml b/phpunit.xml
index 004d12b..c324206 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -1,33 +1,15 @@
-
-
- ./src
-
-
- ./src/Providers
- ./src/Exceptions
- ./src/Contracts
- ./src/ClientGenerator
- ./src/DocBlock
- ./src/Types
- ./src/Console
- ./src/JsonRpcClientServiceProvider.php
-
-
-
-
- ./tests
-
-
+ xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
+ bootstrap="vendor/autoload.php">
+
+
+ ./tests
+
+
+
+
+ ./src
+
+
diff --git a/pint.json b/pint.json
new file mode 100644
index 0000000..f9ec356
--- /dev/null
+++ b/pint.json
@@ -0,0 +1,3 @@
+{
+ "preset": "per"
+}
diff --git a/src/Client.php b/src/Client.php
index ab51053..8ed15dd 100755
--- a/src/Client.php
+++ b/src/Client.php
@@ -54,8 +54,8 @@ public function __construct(ClientConfig $config, QueryPreparer $queryPreparer,
*/
public function __call($method, $params)
{
- if (method_exists($this, '_'.$method)) {
- return $this->{'_'.$method}(...$params);
+ if (method_exists($this, '_' . $method)) {
+ return $this->{'_' . $method}(...$params);
}
return $this->_call($method, $params);
@@ -159,8 +159,8 @@ protected function _execute(): array
return ($request->getResult() instanceof Result)
? $request->getJsonRpcRequest()
: null;
- }, $this->requests)
- )
+ }, $this->requests),
+ ),
);
try {
@@ -201,7 +201,7 @@ private function sendRequests(array $requests): array
return array_values(
array_map(static function (Result $item) {
return $item->get();
- }, $this->results)
+ }, $this->results),
);
}
diff --git a/src/Client/HttpClient.php b/src/Client/HttpClient.php
index dd39bdb..90539a3 100644
--- a/src/Client/HttpClient.php
+++ b/src/Client/HttpClient.php
@@ -21,7 +21,7 @@ class HttpClient implements TransportClient
public function __construct($options = [])
{
$this->options = $options;
- $this->client = new Client;
+ $this->client = new Client();
}
/**
diff --git a/src/ClientConfig.php b/src/ClientConfig.php
index 8c0dfb9..7f9fc98 100755
--- a/src/ClientConfig.php
+++ b/src/ClientConfig.php
@@ -38,7 +38,7 @@ public function __construct(string $clientName, string $serviceName, array $clie
$this->serviceName = $serviceName;
if (! isset($clientConfig['url'], $clientConfig['clientClass'])) {
- throw new JsonRpcClientException(0, 'Connection configuration mismatch for: '.$serviceName);
+ throw new JsonRpcClientException(0, 'Connection configuration mismatch for: ' . $serviceName);
}
$this->url = $clientConfig['url'];
diff --git a/src/ClientGenerator/AbstractClass.php b/src/ClientGenerator/AbstractClass.php
index 32ab873..4f4ac09 100644
--- a/src/ClientGenerator/AbstractClass.php
+++ b/src/ClientGenerator/AbstractClass.php
@@ -39,11 +39,11 @@ protected function getUses(): string
{
return implode("\n", array_map(function ($value) {
if (isset($value['aliasName'])) {
- return 'use '.$value['className'].' as '.$value['aliasName'].';';
+ return 'use ' . $value['className'] . ' as ' . $value['aliasName'] . ';';
}
- return 'use '.$value['className'].';';
- }, $this->uses))."\n";
+ return 'use ' . $value['className'] . ';';
+ }, $this->uses)) . "\n";
}
public function addUse(AbstractClass $class): void
@@ -104,9 +104,9 @@ protected function addSubClass(AbstractClass $class): void
public function getFullClassName(?string $namespacePostfix = null): string
{
- $result = $this->classNamespace.'\\'.$this->className;
+ $result = $this->classNamespace . '\\' . $this->className;
if ($namespacePostfix !== null) {
- $result .= '\\'.$namespacePostfix;
+ $result .= '\\' . $namespacePostfix;
}
return $result;
diff --git a/src/ClientGenerator/ClientClass.php b/src/ClientGenerator/ClientClass.php
index cb0ba90..f4dca2d 100644
--- a/src/ClientGenerator/ClientClass.php
+++ b/src/ClientGenerator/ClientClass.php
@@ -94,7 +94,7 @@ protected function makeSource()
$ln = mb_strlen($method->groupName);
$delimiter = str_pad('', $ln + 20, '=');
$source[] = $delimiter;
- $source[] = str_pad('', 10).$method->groupName;
+ $source[] = str_pad('', 10) . $method->groupName;
$source[] = $delimiter;
}
}
diff --git a/src/ClientGenerator/ClientGenerator.php b/src/ClientGenerator/ClientGenerator.php
index 09abd72..1312127 100644
--- a/src/ClientGenerator/ClientGenerator.php
+++ b/src/ClientGenerator/ClientGenerator.php
@@ -65,7 +65,7 @@ public function generate(): void
protected function getUri(): string
{
- return $this->config->url.'?smd';
+ return $this->config->url . '?smd';
}
/**
@@ -82,10 +82,10 @@ private function getNamespaceDirectory($namespace)
$undefinedNamespaceFragments = [];
while ($namespaceFragments) {
- $possibleNamespace = implode('\\', $namespaceFragments).'\\';
+ $possibleNamespace = implode('\\', $namespaceFragments) . '\\';
if (array_key_exists($possibleNamespace, $composerNamespaces)) {
- $path = app()->basePath().DIRECTORY_SEPARATOR.$composerNamespaces[$possibleNamespace].implode('/', array_reverse($undefinedNamespaceFragments));
+ $path = app()->basePath() . DIRECTORY_SEPARATOR . $composerNamespaces[$possibleNamespace] . implode('/', array_reverse($undefinedNamespaceFragments));
return $this->getAbsolutePath($path);
}
@@ -101,7 +101,7 @@ private function getNamespaceDirectory($namespace)
*/
private function getDefinedNamespaces(): array
{
- $composerJsonPath = app()->basePath().DIRECTORY_SEPARATOR.'composer.json';
+ $composerJsonPath = app()->basePath() . DIRECTORY_SEPARATOR . 'composer.json';
$composerConfig = json_decode(file_get_contents($composerJsonPath));
return (array) $composerConfig->autoload->{'psr-4'};
@@ -130,10 +130,10 @@ protected function getClassPath($classNamespace, $className): string
}
if (! file_exists($directory) && ! mkdir($directory, 0775, true) && ! is_dir($directory)) {
- throw new RuntimeException('Can not create folder "'.$directory.'" to save class.');
+ throw new RuntimeException('Can not create folder "' . $directory . '" to save class.');
}
- return $directory.DIRECTORY_SEPARATOR.$className.'.php';
+ return $directory . DIRECTORY_SEPARATOR . $className . '.php';
}
protected function clearNamespace(string $namespace): void
@@ -147,7 +147,7 @@ protected function clearNamespace(string $namespace): void
private function deleteDirectory(string $directory): void
{
- $files = glob($directory.'/*');
+ $files = glob($directory . '/*');
foreach ($files as $file) {
if (\is_file($file)) {
@@ -178,6 +178,6 @@ private function getAbsolutePath(string $path): string
}
}
- return ($firstSlash ? DIRECTORY_SEPARATOR : '').implode(DIRECTORY_SEPARATOR, $absolutes);
+ return ($firstSlash ? DIRECTORY_SEPARATOR : '') . implode(DIRECTORY_SEPARATOR, $absolutes);
}
}
diff --git a/src/ClientGenerator/EnumClass.php b/src/ClientGenerator/EnumClass.php
index aca2e0d..5585de3 100644
--- a/src/ClientGenerator/EnumClass.php
+++ b/src/ClientGenerator/EnumClass.php
@@ -23,7 +23,7 @@ public function __construct(AbstractClass $parentClass, string $className, strin
parent::__construct($parentClass, $className, $classNamespace);
if ($alias) {
- $this->aliasName = $parentClass->className.'_'.$className;
+ $this->aliasName = $parentClass->className . '_' . $className;
}
$this->values = $values;
$this->type = $type;
@@ -40,7 +40,7 @@ public static function fromObject(AbstractClass $baseClass, SmdEnumObject $objec
public static function fromProperty(AbstractClass $baseClass, SmdParameter $parameter, bool $alias = false)
{
- $className = studly_case($parameter->name).'Enum';
+ $className = studly_case($parameter->name) . 'Enum';
$type = implode('|', $parameter->types);
@@ -91,10 +91,10 @@ protected function makeSource()
protected function getConstants()
{
return implode("\n", array_map(function ($value) {
- $phpDoc = ' /** @var '.$this->type.(isset($value['description']) ? ' '.$value['description'] : '').' */';
- $constant = ' public const '.$value['name'].' = '.var_export($value['value'], true).';';
+ $phpDoc = ' /** @var ' . $this->type . (isset($value['description']) ? ' ' . $value['description'] : '') . ' */';
+ $constant = ' public const ' . $value['name'] . ' = ' . var_export($value['value'], true) . ';';
- return $phpDoc."\n".$constant;
+ return $phpDoc . "\n" . $constant;
}, $this->constants));
}
diff --git a/src/ClientGenerator/ParametersTrait.php b/src/ClientGenerator/ParametersTrait.php
index ff7e333..befec92 100644
--- a/src/ClientGenerator/ParametersTrait.php
+++ b/src/ClientGenerator/ParametersTrait.php
@@ -15,9 +15,9 @@ public function getParameterInfo(SmdParameter $parameter, bool $withAlias = fals
if ($this->extendedStubs) {
$type = $this->getObjectParameter($parameter, $withAlias);
- $type .= (! empty($parameter->array) ? '[]' : '').'|object'.(! empty($parameter->array) ? '[]' : '').'|array';
+ $type .= (! empty($parameter->array) ? '[]' : '') . '|object' . (! empty($parameter->array) ? '[]' : '') . '|array';
} else {
- $type = 'object'.(! empty($parameter->array) ? '[]' : '').'|array';
+ $type = 'object' . (! empty($parameter->array) ? '[]' : '') . '|array';
}
} elseif (! empty($parameter->typeAdditional)) {
@@ -27,7 +27,7 @@ public function getParameterInfo(SmdParameter $parameter, bool $withAlias = fals
if ($this->extendedStubs) {
$type = $this->getEnumParameter($parameter, $withAlias);
- $type .= (! empty($parameter->array) ? '[]' : '').'|'.$this->getTypes($parameter);
+ $type .= (! empty($parameter->array) ? '[]' : '') . '|' . $this->getTypes($parameter);
} else {
$type = $this->getTypes($parameter);
}
@@ -42,14 +42,14 @@ public function getParameterInfo(SmdParameter $parameter, bool $withAlias = fals
$type .= ! empty($parameter->array) ? '[]' : '';
if ($class instanceof EnumClass) {
- $type .= '|'.$class->type.(! empty($parameter->array) ? '[]' : '');
+ $type .= '|' . $class->type . (! empty($parameter->array) ? '[]' : '');
} else {
- $type .= '|object'.(! empty($parameter->array) ? '[]' : '').'|array';
+ $type .= '|object' . (! empty($parameter->array) ? '[]' : '') . '|array';
}
}
} else {
- $type = 'object'.(! empty($parameter->array) ? '[]' : '').'|array';
+ $type = 'object' . (! empty($parameter->array) ? '[]' : '') . '|array';
}
} elseif (! empty($parameter->types)) {
// если указано несколько типов
@@ -89,7 +89,7 @@ public function getReturnInfo(SmdParameter $parameter, bool $withAlias = false):
$type .= (! empty($parameter->array) ? '[]' : '');
} else {
- $type = 'object'.(! empty($parameter->array) ? '[]' : '').'|array';
+ $type = 'object' . (! empty($parameter->array) ? '[]' : '') . '|array';
}
} elseif (! empty($parameter->typeAdditional)) {
@@ -112,12 +112,12 @@ public function getReturnInfo(SmdParameter $parameter, bool $withAlias = false):
$type .= ! empty($parameter->array) ? '[]' : '';
if ($class instanceof EnumClass) {
- $type = $class->type.(! empty($parameter->array) ? '[]' : '');
+ $type = $class->type . (! empty($parameter->array) ? '[]' : '');
}
}
} else {
- $type = 'object'.(! empty($parameter->array) ? '[]' : '').'|array';
+ $type = 'object' . (! empty($parameter->array) ? '[]' : '') . '|array';
}
} elseif (! empty($parameter->types)) {
// если указано несколько типов
@@ -139,7 +139,7 @@ protected function getTypes(SmdParameter $parameter): string
if (! empty($parameter->array)) {
$types = array_map(function ($value) {
- return $value.'[]';
+ return $value . '[]';
}, $parameter->types);
}
diff --git a/src/ClientGenerator/ServiceClass.php b/src/ClientGenerator/ServiceClass.php
index cc281c7..6b7a631 100644
--- a/src/ClientGenerator/ServiceClass.php
+++ b/src/ClientGenerator/ServiceClass.php
@@ -31,7 +31,7 @@ public function getMethodDescription(array $source): array
foreach ($this->method->parameters as $parameter) {
[$name, $type, $default] = $this->getParameterInfo($parameter, true);
- $parameters[] = ($type !== null ? $type.' ' : '').'$'.$name.($default !== null ? ' = '.$default : '');
+ $parameters[] = ($type !== null ? $type . ' ' : '') . '$' . $name . ($default !== null ? ' = ' . $default : '');
}
$parameters = implode(', ', $parameters);
diff --git a/src/ClientGenerator/SubClass.php b/src/ClientGenerator/SubClass.php
index 05edd24..c875a7f 100644
--- a/src/ClientGenerator/SubClass.php
+++ b/src/ClientGenerator/SubClass.php
@@ -21,7 +21,7 @@ public function __construct(AbstractClass $parentClass, string $className, strin
parent::__construct($parentClass, $className, $classNamespace);
if ($alias) {
- $this->aliasName = $parentClass->className.'_'.$className;
+ $this->aliasName = $parentClass->className . '_' . $className;
}
$this->parameters = $parameters;
@@ -33,7 +33,7 @@ public static function fromProperty(AbstractClass $baseClass, SmdParameter $para
if (! empty($parameter->typeAdditional)) {
$className = $parameter->typeAdditional;
} else {
- $className = studly_case($parameter->name).$postfix;
+ $className = studly_case($parameter->name) . $postfix;
}
$instance = new self($baseClass, $className, $baseClass->getFullClassName(), $parameter->parameters, $alias);
@@ -84,10 +84,10 @@ protected function makeSource()
protected function getProperties()
{
return implode("\n", array_map(function ($value) {
- $phpDoc = ' /** @var '.$value['type'].(isset($value['description']) ? ' '.$value['description'] : '').' */';
- $property = ' public $'.$value['name'].(isset($value['default']) ? ' = '.$value['default'] : '').';';
+ $phpDoc = ' /** @var ' . $value['type'] . (isset($value['description']) ? ' ' . $value['description'] : '') . ' */';
+ $property = ' public $' . $value['name'] . (isset($value['default']) ? ' = ' . $value['default'] : '') . ';';
- return $phpDoc."\n".$property;
+ return $phpDoc . "\n" . $property;
}, $this->properties));
}
diff --git a/src/Console/GenerateClient.php b/src/Console/GenerateClient.php
index 3a4172d..3752c97 100755
--- a/src/Console/GenerateClient.php
+++ b/src/Console/GenerateClient.php
@@ -36,7 +36,7 @@ public function handle(): void
*/
protected function generate(string $connection): void
{
- $this->info('Generate client class for connection: '.$connection);
+ $this->info('Generate client class for connection: ' . $connection);
$services = config('jsonrpc-client.connections', []);
$clientName = config('jsonrpc-client.clientName', []);
diff --git a/src/DocBlock/Method.php b/src/DocBlock/Method.php
index 3766fb7..00738b1 100644
--- a/src/DocBlock/Method.php
+++ b/src/DocBlock/Method.php
@@ -16,11 +16,11 @@
*/
class Method extends BaseTag implements Tag
{
- protected const REGEXP_METHOD = /** @lang text */
- '/((?static)? +)?(?([a-z\[\]\_]+)[ ]+)?(?[a-z0-9\_]+)\((?[^\)]*)\)[ \n]*(?.+)?/is';
+ protected const REGEXP_METHOD /** @lang text */
+ = '/((?static)? +)?(?([a-z\[\]\_]+)[ ]+)?(?[a-z0-9\_]+)\((?[^\)]*)\)[ \n]*(?.+)?/is';
- protected const REGEXP_ARGUMENT = /** @lang text */
- '/(?(\??[\\a-z\[\]\_|]+)[ ]+)?\$(?[a-z0-9\_]+)(\s*=\s*)?(?(\S*))/is';
+ protected const REGEXP_ARGUMENT /** @lang text */
+ = '/(?(\??[\\a-z\[\]\_|]+)[ ]+)?\$(?[a-z0-9\_]+)(\s*=\s*)?(?(\S*))/is';
protected const TAG_NAME = 'method';
@@ -36,12 +36,13 @@ class Method extends BaseTag implements Tag
/** @var Type */
protected $returnType;
- public function __construct(string $methodName,
+ public function __construct(
+ string $methodName,
array $arguments = [],
?Type $returnType = null,
bool $static = false,
- ?Description $description = null)
- {
+ ?Description $description = null,
+ ) {
Assert::stringNotEmpty($methodName);
$this->name = self::TAG_NAME;
@@ -59,7 +60,7 @@ public static function create(
$body,
?TypeResolver $typeResolver = null,
?DescriptionFactory $descriptionFactory = null,
- ?TypeContext $context = null
+ ?TypeContext $context = null,
) {
Assert::stringNotEmpty($body);
Assert::allNotNull([$typeResolver, $descriptionFactory]);
@@ -92,7 +93,7 @@ public static function create(
// if T $value = null, make T|null $value
if (($matches['default'] ?? null) === 'null' && $matches['type'] ?? false) {
if (strpos($matches['type'], '?') === false && strpos($matches['type'], 'null') === false) {
- $matches['type'] = trim($matches['type']).'|null';
+ $matches['type'] = trim($matches['type']) . '|null';
}
}
@@ -150,13 +151,13 @@ public function __toString(): string
{
$arguments = [];
foreach ($this->arguments as $argument) {
- $arguments[] = $argument['type'].' $'.$argument['name'];
+ $arguments[] = $argument['type'] . ' $' . $argument['name'];
}
return trim(($this->isStatic() ? 'static ' : '')
- .$this->returnType.' '
- .$this->methodName
- .'('.implode(', ', $arguments).')'
- .($this->description ? ' '.$this->description->render() : ''));
+ . $this->returnType . ' '
+ . $this->methodName
+ . '(' . implode(', ', $arguments) . ')'
+ . ($this->description ? ' ' . $this->description->render() : ''));
}
}
diff --git a/src/Exceptions/JsonRpcClientException.php b/src/Exceptions/JsonRpcClientException.php
index 003576b..22fc71a 100644
--- a/src/Exceptions/JsonRpcClientException.php
+++ b/src/Exceptions/JsonRpcClientException.php
@@ -21,7 +21,7 @@ class JsonRpcClientException extends \Exception
public function __construct(int $code = 0, ?string $message = null, ?Throwable $previous = null)
{
if ($message === null) {
- $message = self::MESSAGES[$code] ?? 'Unknown error. Code '.$code;
+ $message = self::MESSAGES[$code] ?? 'Unknown error. Code ' . $code;
}
parent::__construct($message, $code, $previous);
diff --git a/src/Exceptions/ResponseException.php b/src/Exceptions/ResponseException.php
index ddeb966..cae794d 100644
--- a/src/Exceptions/ResponseException.php
+++ b/src/Exceptions/ResponseException.php
@@ -12,7 +12,7 @@ class ResponseException extends JsonRpcClientException
public function __construct(JsonRpcError $responseError, ?Throwable $previous = null)
{
$code = $responseError->code ?? 0;
- $message = $responseError->message ?? JsonRpcError::MESSAGES[$code] ?? 'Unknown error. Code '.$code;
+ $message = $responseError->message ?? JsonRpcError::MESSAGES[$code] ?? 'Unknown error. Code ' . $code;
$this->data = $responseError->data ?? null;
parent::__construct($code, $message, $previous);
diff --git a/src/JsonRpcClientServiceProvider.php b/src/JsonRpcClientServiceProvider.php
index cab036f..5f53ff8 100755
--- a/src/JsonRpcClientServiceProvider.php
+++ b/src/JsonRpcClientServiceProvider.php
@@ -22,7 +22,7 @@ public function boot(): void
}
$this->publishes([
- __DIR__.'/../config/jsonrpc-client.php' => base_path('config/jsonrpc-client.php'),
+ __DIR__ . '/../config/jsonrpc-client.php' => base_path('config/jsonrpc-client.php'),
], 'config');
}
@@ -33,7 +33,7 @@ public function register()
$defaultTimeout = config('jsonrpc-client.defaultTimeout', null);
$this->app->singleton(MiddlewareRegistryInterface::class, function () use ($services, $clientName) {
- $middlewareRegistry = new MiddlewareRegistry;
+ $middlewareRegistry = new MiddlewareRegistry();
foreach ($services as $alias => $serviceConfig) {
$config = new ClientConfig($clientName, $alias, $serviceConfig);
$middlewareRegistry->setMiddleware($alias, $config->middleware, $config->onceExecutedMiddleware);
diff --git a/src/Middleware/AuthBasicMiddleware.php b/src/Middleware/AuthBasicMiddleware.php
index bd7d2ff..7819289 100644
--- a/src/Middleware/AuthBasicMiddleware.php
+++ b/src/Middleware/AuthBasicMiddleware.php
@@ -23,7 +23,7 @@ public function handle(
TransportClient $client,
$username = '',
$password = '',
- $scheme = 'basic'
+ $scheme = 'basic',
) {
if (! $client instanceof HttpClient) {
return $next($requests);
diff --git a/src/Middleware/AuthTokenMiddleware.php b/src/Middleware/AuthTokenMiddleware.php
index 73d7c93..d9d9f45 100644
--- a/src/Middleware/AuthTokenMiddleware.php
+++ b/src/Middleware/AuthTokenMiddleware.php
@@ -20,7 +20,7 @@ public function handle(
\Closure $next,
TransportClient $client,
$value,
- $name = 'X-Access-Key'
+ $name = 'X-Access-Key',
) {
if (! $client instanceof HttpClient) {
return $next($requests);
diff --git a/src/Middleware/MiddlewarePipeline.php b/src/Middleware/MiddlewarePipeline.php
index 07b3455..abf0737 100644
--- a/src/Middleware/MiddlewarePipeline.php
+++ b/src/Middleware/MiddlewarePipeline.php
@@ -92,7 +92,7 @@ protected function parseAssociatedParams(array $pipe): array
$type = $reflectionParameters[$i]->getType();
if ($type === null || $type->isBuiltin()) {
if (! $reflectionParameters[$i]->isOptional()) {
- throw new JsonRpcClientException(0, 'Error while handling middleware: unknown parameter '.$reflectionParamName);
+ throw new JsonRpcClientException(0, 'Error while handling middleware: unknown parameter ' . $reflectionParamName);
}
// получим значение аргумента по умолчанию
diff --git a/src/QueryPreparers/DefaultQueryPreparer.php b/src/QueryPreparers/DefaultQueryPreparer.php
index 927994c..dd028e6 100644
--- a/src/QueryPreparers/DefaultQueryPreparer.php
+++ b/src/QueryPreparers/DefaultQueryPreparer.php
@@ -35,7 +35,7 @@ protected function mapMethods(ClientConfig $config): void
try {
$reflection = new \ReflectionClass($clientFacade);
} catch (\ReflectionException $e) {
- throw new JsonRpcClientException(0, 'Cannot parse proxy class DocBlock: '.$e->getMessage());
+ throw new JsonRpcClientException(0, 'Cannot parse proxy class DocBlock: ' . $e->getMessage());
}
$docs = $reflection->getDocComment();
@@ -61,7 +61,7 @@ protected function checkType($value, array $argument, string $method): void
$typesArray[] = $item;
}
} elseif ($type instanceof Nullable) {
- $typesArray[] = new Null_;
+ $typesArray[] = new Null_();
$typesArray[] = $type->getActualType();
} else {
$typesArray[] = $type;
@@ -83,9 +83,11 @@ protected function checkType($value, array $argument, string $method): void
}
}
- $messageType = 'expected '.(string) $type.' got '.gettype($value).' in method '.$method;
- throw new JsonRpcClientException(0,
- 'Error while mapping jsonrpc client method parameter: '.$argumentName.', '.$messageType);
+ $messageType = 'expected ' . (string) $type . ' got ' . gettype($value) . ' in method ' . $method;
+ throw new JsonRpcClientException(
+ 0,
+ 'Error while mapping jsonrpc client method parameter: ' . $argumentName . ', ' . $messageType,
+ );
}
/**
diff --git a/src/Request.php b/src/Request.php
index c2a52a5..2e5712d 100644
--- a/src/Request.php
+++ b/src/Request.php
@@ -21,7 +21,7 @@ class Request
public function __construct(JsonRpcRequest $request)
{
$this->jsonRpcRequest = $request;
- $this->result = new Result;
+ $this->result = new Result();
}
/**
diff --git a/tests/EmptyResultTest.php b/tests/EmptyResultTest.php
index fa5cad6..b24034b 100644
--- a/tests/EmptyResultTest.php
+++ b/tests/EmptyResultTest.php
@@ -12,7 +12,7 @@ class EmptyResultTest extends TestCase
*/
public function test_to_string(): void
{
- $instance = new Result;
+ $instance = new Result();
$this->assertEquals('The response has not yet been initialized', (string) $instance);
}
diff --git a/tests/QueryPreparers/ArrayParametersPreparerTest.php b/tests/QueryPreparers/ArrayParametersPreparerTest.php
index 341418e..8eaff29 100644
--- a/tests/QueryPreparers/ArrayParametersPreparerTest.php
+++ b/tests/QueryPreparers/ArrayParametersPreparerTest.php
@@ -14,7 +14,7 @@ class ArrayParametersPreparerTest extends TestCase
public function test_prepare()
{
$clientConfig = new ClientConfig('clientName', 'serviceName', ['url' => 'url', 'clientClass' => 'clientClass']);
- $preparer = new ArrayParametersPreparer;
+ $preparer = new ArrayParametersPreparer();
$jsonRpcRequest = $preparer->prepare('method', ['param1' => 'value1', 'param2' => 'value2'], $clientConfig);
$this->assertNotNull($jsonRpcRequest->id);
$this->assertSame('method', $jsonRpcRequest->method);
diff --git a/tests/QueryPreparers/DefaultQueryPreparerTest.php b/tests/QueryPreparers/DefaultQueryPreparerTest.php
index 0b7700c..99c1b20 100644
--- a/tests/QueryPreparers/DefaultQueryPreparerTest.php
+++ b/tests/QueryPreparers/DefaultQueryPreparerTest.php
@@ -38,44 +38,44 @@ protected function makeConfig(): ClientConfig
public static function providerCastCompoundTypeTo()
{
return [
- 'type int got int' => [1, self::wrapType(new Integer), false],
- 'type string got string' => ['1', self::wrapType(new String_), false],
- 'type null got null' => [null, self::wrapType(new Null_), false],
- 'type bool got bool' => [true, self::wrapType(new Boolean), false],
- 'type float got float' => [0.5, self::wrapType(new Float_), false],
- 'type object got object' => [new \stdClass, self::wrapType(new Object_), false],
- 'type array got array' => [[], self::wrapType(new Array_), false],
- 'type \stdClass got \stdClass' => [new \stdClass, self::wrapType(new Object_), false],
+ 'type int got int' => [1, self::wrapType(new Integer()), false],
+ 'type string got string' => ['1', self::wrapType(new String_()), false],
+ 'type null got null' => [null, self::wrapType(new Null_()), false],
+ 'type bool got bool' => [true, self::wrapType(new Boolean()), false],
+ 'type float got float' => [0.5, self::wrapType(new Float_()), false],
+ 'type object got object' => [new \stdClass(), self::wrapType(new Object_()), false],
+ 'type array got array' => [[], self::wrapType(new Array_()), false],
+ 'type \stdClass got \stdClass' => [new \stdClass(), self::wrapType(new Object_()), false],
// compound
- 'type int|null got int' => [1, self::wrapType(new Compound([new Integer, new Null_])), false],
+ 'type int|null got int' => [1, self::wrapType(new Compound([new Integer(), new Null_()])), false],
'type int|null got null' => [
null,
- self::wrapType(new Compound([new Integer, new Null_])),
+ self::wrapType(new Compound([new Integer(), new Null_()])),
false,
],
- 'type string|null got string' => ['1', self::wrapType(new Compound([new String_, new Null_])), false],
+ 'type string|null got string' => ['1', self::wrapType(new Compound([new String_(), new Null_()])), false],
'type string|null got null' => [
null,
- self::wrapType(new Compound([new String_, new Null_])),
+ self::wrapType(new Compound([new String_(), new Null_()])),
false,
],
- 'type array|\\stdClass got array' => [[], self::wrapType(new Compound([new Array_, new Object_])), false],
+ 'type array|\\stdClass got array' => [[], self::wrapType(new Compound([new Array_(), new Object_()])), false],
// errors
- 'type int|null got string' => ['1', self::wrapType(new Compound([new Integer, new Null_])), true],
- 'type int|float got string' => ['1', self::wrapType(new Compound([new Integer, new Float_])), true],
- 'type int got string' => ['1', self::wrapType(new Integer), true],
- 'type object got array' => [[], self::wrapType(new Object_), true],
- 'type array got object' => [new \stdClass, self::wrapType(new Array_), true],
+ 'type int|null got string' => ['1', self::wrapType(new Compound([new Integer(), new Null_()])), true],
+ 'type int|float got string' => ['1', self::wrapType(new Compound([new Integer(), new Float_()])), true],
+ 'type int got string' => ['1', self::wrapType(new Integer()), true],
+ 'type object got array' => [[], self::wrapType(new Object_()), true],
+ 'type array got object' => [new \stdClass(), self::wrapType(new Array_()), true],
'type int|bool|null got array' => [
[],
- self::wrapType(new Compound([new Integer, new Boolean, new Null_])),
+ self::wrapType(new Compound([new Integer(), new Boolean(), new Null_()])),
true,
],
// nullable
- 'type nullable' => [1, self::wrapType(new Nullable(new Integer)), false],
- 'type nullable null' => [null, self::wrapType(new Nullable(new Integer)), false],
- 'type nullable bad type' => ['string', self::wrapType(new Nullable(new Integer)), true],
- 'mixed' => ['chot', self::wrapType(new Mixed_), false],
+ 'type nullable' => [1, self::wrapType(new Nullable(new Integer())), false],
+ 'type nullable null' => [null, self::wrapType(new Nullable(new Integer())), false],
+ 'type nullable bad type' => ['string', self::wrapType(new Nullable(new Integer())), true],
+ 'mixed' => ['chot', self::wrapType(new Mixed_()), false],
];
}
@@ -94,7 +94,7 @@ public function test_check_type($value, $type, bool $expectException)
if ($expectException) {
$this->expectException(JsonRpcClientException::class);
}
- $preparer = new DefaultQueryPreparer;
+ $preparer = new DefaultQueryPreparer();
$this->callMethod($preparer, 'checkType', [$value, $type, 'method']);
$this->assertTrue(true);
}
@@ -106,7 +106,7 @@ public function test_check_type($value, $type, bool $expectException)
public function test_map_methods_class_not_found()
{
$this->expectException(JsonRpcClientException::class);
- $preparer = new DefaultQueryPreparer;
+ $preparer = new DefaultQueryPreparer();
$this->callMethod($preparer, 'mapMethods', [
new ClientConfig('name', 'service', [
'clientClass' => '',
@@ -138,7 +138,7 @@ public static function providerMapMethods(): array
*/
public function test_map_methods(string $methodName, array $types)
{
- $preparer = new DefaultQueryPreparer;
+ $preparer = new DefaultQueryPreparer();
$this->callMethod($preparer, 'mapMethods', [$this->makeConfig()]);
/** @var Method $resultMethod */
$resultMethod = $this->getProperty($preparer, 'methods')[$methodName];
@@ -157,7 +157,7 @@ public function test_map_methods(string $methodName, array $types)
public function test_prepare_method_not_found()
{
$this->expectException(JsonRpcClientException::class);
- $preparer = new DefaultQueryPreparer;
+ $preparer = new DefaultQueryPreparer();
$this->setProperty($preparer, 'methods', ['one' => '']);
$preparer->prepare('name', [], $this->makeConfig());
}
@@ -170,11 +170,11 @@ public function test_prepare_method_not_found()
*/
public function test_prepare()
{
- $preparer = new DefaultQueryPreparer;
+ $preparer = new DefaultQueryPreparer();
$this->setProperty($preparer, 'methods', [
'one' => new Method('one', [
- ['name' => 'first', 'type' => new Integer],
- ['name' => 'second', 'type' => new String_],
+ ['name' => 'first', 'type' => new Integer()],
+ ['name' => 'second', 'type' => new String_()],
]),
]);
$jsonRpcRequest = $preparer->prepare('one', [5, '6'], $this->makeConfig());
@@ -191,7 +191,7 @@ public function test_prepare()
*/
public function test_prepare_map_methods_if_not_mapped()
{
- $preparer = new DefaultQueryPreparer;
+ $preparer = new DefaultQueryPreparer();
$preparer->prepare('name_intMethod', [5, '6'], $this->makeConfig());
$this->assertNotEmpty($this->getProperty($preparer, 'methods'));
}