Add cs rules

This commit is contained in:
Daniil Gentili 2023-08-29 15:28:35 +02:00
parent 87186112b7
commit e063efcdf5
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
5 changed files with 38 additions and 7 deletions

1
examples/reqwest/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.php_cs.cache

View File

@ -0,0 +1,23 @@
<?php
$config = new class extends Amp\CodeStyle\Config {
public function getRules(): array
{
return array_merge(parent::getRules(), [
'void_return' => true,
'array_indentation' => true,
'ternary_to_null_coalescing' => true,
'assign_null_coalescing_to_coalesce_equal' => true,
]);
}
};
$config->getFinder()
->in(__DIR__ . '/lib')
->append([__DIR__ . '/test.php']);
$cacheDir = getenv('TRAVIS') ? getenv('HOME') . '/.php-cs-fixer' : __DIR__;
$config->setCacheFile($cacheDir . '/.php_cs.cache');
return $config;

View File

@ -3,9 +3,15 @@
"revolt/event-loop": "^1.0",
"amphp/amp": "^3.0"
},
"require-dev": {
"amphp/php-cs-fixer-config": "v2.x-dev"
},
"autoload": {
"psr-4": {
"Reqwest\\": "lib"
}
},
"scripts": {
"cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 php -d pcre.jit=0 vendor/bin/php-cs-fixer fix -v --diff"
}
}

View File

@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Reqwest;
@ -14,9 +14,9 @@ final class Client
return;
}
$f = fopen("php://fd/" . \Client::init(), "r+");
stream_set_blocking($f, false);
self::$id = EventLoop::onReadable($f, fn() => \Client::wakeup());
$f = \fopen("php://fd/".\Client::init(), 'r+');
\stream_set_blocking($f, false);
self::$id = EventLoop::onReadable($f, fn () => \Client::wakeup());
}
public static function reference(): void

View File

@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
use Reqwest\Client;
@ -9,7 +9,8 @@ require 'vendor/autoload.php';
Client::init();
function test(int $delay): void {
function test(int $delay): void
{
$url = "https://httpbin.org/delay/$delay";
$t = time();
echo "Making async reqwest to $url that will return after $delay seconds...".PHP_EOL;
@ -23,4 +24,4 @@ $futures []= async(test(...), 5);
$futures []= async(test(...), 5);
$futures []= async(test(...), 5);
await($futures);
await($futures);