Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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'
24 changes: 12 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand All @@ -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"
},
Expand Down
42 changes: 12 additions & 30 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<directory suffix=".php">./src/Providers</directory>
<directory suffix=".php">./src/Exceptions</directory>
<directory suffix=".php">./src/Contracts</directory>
<directory suffix=".php">./src/ClientGenerator</directory>
<directory suffix=".php">./src/DocBlock</directory>
<directory suffix=".php">./src/Types</directory>
<directory suffix=".php">./src/Console</directory>
<file>./src/JsonRpcClientServiceProvider.php</file>
</exclude>
</coverage>
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="Unit">
<directory>./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>./src</directory>
</include>
</source>
</phpunit>
3 changes: 3 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"preset": "per"
}
10 changes: 5 additions & 5 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -159,8 +159,8 @@ protected function _execute(): array
return ($request->getResult() instanceof Result)
? $request->getJsonRpcRequest()
: null;
}, $this->requests)
)
}, $this->requests),
),
);

try {
Expand Down Expand Up @@ -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),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Client/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class HttpClient implements TransportClient
public function __construct($options = [])
{
$this->options = $options;
$this->client = new Client;
$this->client = new Client();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ClientConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
10 changes: 5 additions & 5 deletions src/ClientGenerator/AbstractClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/ClientGenerator/ClientClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/ClientGenerator/ClientGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function generate(): void

protected function getUri(): string
{
return $this->config->url.'?smd';
return $this->config->url . '?smd';
}

/**
Expand All @@ -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);
}
Expand All @@ -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'};
Expand Down Expand Up @@ -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
Expand All @@ -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)) {
Expand Down Expand Up @@ -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);
}
}
10 changes: 5 additions & 5 deletions src/ClientGenerator/EnumClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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));
}

Expand Down
Loading
Loading