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
13 changes: 9 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ jobs:

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
restore-keys: ${{ runner.os }}-php-

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run test suite
run: composer run-script test
run: composer run-script tests
52 changes: 26 additions & 26 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@

return (new PhpCsFixer\Config())
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'concat_space' => ['spacing' => 'one'],
'new_with_braces' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_phpdoc' => true,
'no_empty_comment' => true,
'no_leading_import_slash' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_unused_imports' => true,
'ordered_imports' => ['imports_order' => null, 'sort_algorithm' => 'alpha'],
'phpdoc_add_missing_param_annotation' => ['only_untyped' => true],
'phpdoc_align' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_order' => true,
'phpdoc_scalar' => true,
'phpdoc_to_comment' => true,
'psr_autoloading' => true,
'return_type_declaration' => ['space_before' => 'none'],
'single_blank_line_before_namespace' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline' => true,
'trim_array_spaces' => true,
'whitespace_after_comma_in_array' => true,
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'concat_space' => ['spacing' => 'one'],
'new_with_parentheses' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_phpdoc' => true,
'no_empty_comment' => true,
'no_leading_import_slash' => true,
'no_trailing_comma_in_singleline' => true,
'no_unused_imports' => true,
'ordered_imports' => ['imports_order' => null, 'sort_algorithm' => 'alpha'],
'phpdoc_add_missing_param_annotation' => ['only_untyped' => true],
'phpdoc_align' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_order' => true,
'phpdoc_scalar' => true,
'phpdoc_to_comment' => true,
'psr_autoloading' => true,
'return_type_declaration' => ['space_before' => 'none'],
'blank_lines_before_namespace' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline' => true,
'trim_array_spaces' => true,
'whitespace_after_comma_in_array' => true,
])
->setFinder($finder);
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM composer:2.2
19 changes: 0 additions & 19 deletions Makefile

This file was deleted.

20 changes: 10 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.9",
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.13.8",
"phpunit/phpunit": "^11.0",
"rector/rector": "^2.0",
"squizlabs/php_codesniffer": "^3.7",
"mockery/mockery": "^1.5"
},
Expand All @@ -34,27 +34,27 @@
},
"autoload-dev": {
"psr-4": {
"Softonic\\GraphQL\\Test\\": "tests/"
"Softonic\\GraphQL\\": "tests/"
}
},
"bin": [
"bin/graphql-client"
],
"scripts": {
"test": [
"tests": [
"@checkstyle",
"@phpunit"
],
"phpunit": "phpunit --coverage-text",
"phpunit": "phpunit",
"checkstyle": [
"php-cs-fixer fix -v --diff --dry-run --allow-risky=yes",
"rector --dry-run"
"PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix -v --diff --dry-run --allow-risky=yes",
"rector process"
],
"fix-checkstyle": [
"fix-cs": [
"@php-cs-fixer",
"@rector"
],
"php-cs-fixer": "php-cs-fixer fix -v --diff --allow-risky=yes",
"rector": "rector"
"php-cs-fixer": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix -v --diff --allow-risky=yes",
"rector": "rector process"
}
}
48 changes: 45 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,49 @@
version: '3.8'

services:
composer:
php:
build:
context: .
dockerfile: Dockerfile
volumes:
- ./:/app
image: softonic/composer-rector:latest
- ./:/app

install:
build:
context: .
dockerfile: Dockerfile
volumes:
- ./:/app
command: composer install

update:
build:
context: .
dockerfile: Dockerfile
volumes:
- ./:/app
command: composer update

phpunit:
build:
context: .
dockerfile: Dockerfile
volumes:
- ./:/app
command: composer phpunit

tests:
build:
context: .
dockerfile: Dockerfile
volumes:
- ./:/app
command: composer run tests

fix-cs:
build:
context: .
dockerfile: Dockerfile
volumes:
- ./:/app
command: composer run fix-cs
30 changes: 9 additions & 21 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true">

<testsuites>
<testsuite name="Softonic GraphQL Client">
<directory>tests</directory>
</testsuite>
</testsuites>

<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
<report>
<clover outputFile="./build/clover.xml"/>
<html outputDirectory="./build/coverage"/>
<text outputFile="./build/coverage.txt" />
</report>
</coverage>

<logging>
<junit outputFile="./build/report.junit.xml"/>
</logging>
Expand Down
63 changes: 44 additions & 19 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,49 @@

declare(strict_types=1);

use Rector\Set\ValueObject\SetList;
use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector;
use Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector;
use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector;
use Rector\Config\RectorConfig;
use Rector\EarlyReturn\Rector\Return_\ReturnBinaryOrToEarlyReturnRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
use Rector\TypeDeclaration\Rector\ArrowFunction\AddArrowFunctionReturnTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector;

return static function (RectorConfig $containerConfigurator): void {
// get parameters
$parameters = $containerConfigurator->parameters();

// Define what rule sets will be applied
$containerConfigurator->import(SetList::DEAD_CODE);
$containerConfigurator->import(SetList::PHP_80);
$containerConfigurator->import(SetList::TYPE_DECLARATION_STRICT);
$containerConfigurator->import(SetList::TYPE_DECLARATION);
$containerConfigurator->import(SetList::EARLY_RETURN);
$containerConfigurator->import(SetList::PRIVATIZATION);

// get services (needed for register a single rule)
// $services = $containerConfigurator->services();

// register a single rule
// $services->set(TypedPropertyRector::class);
};
return RectorConfig::configure()
->withSkip(
[
// CodeQuality
CompleteDynamicPropertiesRector::class,
DisallowedEmptyRuleFixerRector::class,
// CodingStyle
CatchExceptionNameMatchingTypeRector::class,
EncapsedStringsToSprintfRector::class,
// EarlyReturn
ReturnBinaryOrToEarlyReturnRector::class,
// TypeDeclaration
AddArrowFunctionReturnTypeRector::class,
ReturnTypeFromStrictTypedCallRector::class,
]
)
->withAutoloadPaths([__DIR__ . '/vendor/autoload.php'])
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withImportNames()
->withPhpSets(php83: true)
->withSets(
[
PHPUnitSetList::PHPUNIT_100,
PHPUnitSetList::PHPUNIT_110,
]
)
->withPreparedSets(
deadCode: true,
codeQuality: true,
codingStyle: true,
typeDeclarations: true,
earlyReturn: true
);
28 changes: 9 additions & 19 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,35 @@

use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\TransferException;
use RuntimeException;
use Softonic\GraphQL\DataObjects\Mutation\MutationObject;
use UnexpectedValueException;

class Client
{
/**
* @var ClientInterface
*/
private $httpClient;

/**
* @var ResponseBuilder
*/
private $responseBuilder;

public function __construct(ClientInterface $httpClient, ResponseBuilder $responseBuilder)
public function __construct(private ClientInterface $httpClient, private ResponseBuilder $responseBuilder)
{
$this->httpClient = $httpClient;
$this->responseBuilder = $responseBuilder;
}

/**
* @throws \UnexpectedValueException When response body is not a valid json
* @throws \RuntimeException When there are transfer errors
* @throws UnexpectedValueException When response body is not a valid json
* @throws RuntimeException When there are transfer errors
*/
public function query(string $query, ?array $variables = null): Response
{
return $this->executeQuery($query, $variables);
}

/**
* @throws \UnexpectedValueException When response body is not a valid json
* @throws \RuntimeException When there are transfer errors
* @throws UnexpectedValueException When response body is not a valid json
* @throws RuntimeException When there are transfer errors
*/
public function mutate(string $query, MutationObject $mutation): Response
{
return $this->executeQuery($query, $mutation);
}

private function executeQuery(string $query, $variables): Response
private function executeQuery(string $query, array|null|MutationObject $variables): Response
{
$body = ['query' => $query];
if (!is_null($variables)) {
Expand All @@ -59,7 +49,7 @@ private function executeQuery(string $query, $variables): Response
try {
$response = $this->httpClient->request('POST', '', $options);
} catch (TransferException $e) {
throw new \RuntimeException('Network Error.' . $e->getMessage(), 0, $e);
throw new RuntimeException('Network Error.' . $e->getMessage(), 0, $e);
}

return $this->responseBuilder->build($response);
Expand Down
Loading