Skip to content

Commit

Permalink
coding style updates
Browse files Browse the repository at this point in the history
  • Loading branch information
deminy committed Dec 8, 2023
1 parent 6b4c499 commit c8046e7
Show file tree
Hide file tree
Showing 64 changed files with 780 additions and 805 deletions.
123 changes: 47 additions & 76 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,82 +11,53 @@
return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'@Symfony' => true,
'@DoctrineAnnotation' => true,
'@PhpCsFixer' => true,
'header_comment' => [
'comment_type' => 'PHPDoc',
'header' => $header,
'separate' => 'bottom',
'location' => 'after_open',
],
'array_syntax' => [
'syntax' => 'short'
],
'list_syntax' => [
'syntax' => 'short'
],
'concat_space' => [
'spacing' => 'one'
],
'blank_line_before_statement' => [
'statements' => [
'declare',
],
],
'blank_line_after_namespace' => true,
'general_phpdoc_annotation_remove' => [
'annotations' => [
'author'
],
],
'ordered_imports' => [
'imports_order' => [
'class',
'function',
'const',
],
'sort_algorithm' => 'alpha',
],
'single_line_comment_style' => [
'comment_types' => [
],
],
'yoda_style' => [
'always_move_variable' => false,
'equal' => false,
'identical' => false,
],
'phpdoc_align' => [
'align' => 'left',
],
'multiline_whitespace_before_semicolons' => [
'strategy' => 'no_multi_line',
],
'constant_case' => [
'case' => 'lower',
],
'class_attributes_separation' => true,
'combine_consecutive_unsets' => true,
'declare_strict_types' => true,
'linebreak_after_opening_tag' => true,
'lowercase_static_reference' => true,
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true, 'remove_inheritdoc' => false],
'no_useless_else' => true,
'no_unused_imports' => true,
'not_operator_with_successor_space' => false,
'not_operator_with_space' => false,
'ordered_class_elements' => true,
'php_unit_strict' => false,
'phpdoc_separation' => false,
'phpdoc_summary' => false,
'single_quote' => true,
'increment_style' => [],
'standardize_increment' => false,
'standardize_not_equals' => true,
'multiline_comment_opening_closing' => true,
'lambda_not_used_import' => false,
'@DoctrineAnnotation' => true,
'@PhpCsFixer' => true,
'@PSR2' => true,
'@Symfony' => true,
'align_multiline_comment' => ['comment_type' => 'all_multiline'],
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => ['operators' => ['=' => 'align', '=>' => 'align', ]],
'blank_line_after_namespace' => true,
'blank_line_before_statement' => ['statements' => ['declare']],
'class_attributes_separation' => true,
'concat_space' => ['spacing' => 'one'],
'constant_case' => ['case' => 'lower'],
'combine_consecutive_unsets' => true,
'declare_strict_types' => true,
'general_phpdoc_annotation_remove' => ['annotations' => ['author']],
'header_comment' => ['comment_type' => 'PHPDoc', 'header' => $header, 'location' => 'after_open', 'separate' => 'bottom'],
'increment_style' => ['style' => 'post'],
'lambda_not_used_import' => false,
'linebreak_after_opening_tag' => true,
'list_syntax' => ['syntax' => 'short'],
'lowercase_static_reference' => true,
'multiline_comment_opening_closing' => true,
'multiline_whitespace_before_semicolons' => ['strategy' => 'new_line_for_chained_calls'],
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true, 'allow_unused_params' => true, 'remove_inheritdoc' => false],
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'not_operator_with_space' => false,
'not_operator_with_successor_space' => false,
'nullable_type_declaration_for_default_null_value' => ['use_nullable_type_declaration' => true],
'php_unit_strict' => false,
'phpdoc_align' => ['align' => 'left'],
'phpdoc_annotation_without_dot' => false,
'phpdoc_no_empty_return' => false,
'phpdoc_types_order' => ['sort_algorithm' => 'none', 'null_adjustment' => 'always_last'],
'phpdoc_separation' => false,
'phpdoc_summary' => false,
'ordered_class_elements' => true,
'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'],
'ordered_types' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
'single_line_comment_style' => ['comment_types' => []],
'single_line_comment_spacing' => false,
'single_line_empty_body' => false,
'single_quote' => true,
'standardize_increment' => false,
'standardize_not_equals' => true,
'yoda_style' => ['always_move_variable' => false, 'equal' => false, 'identical' => false],
])
->setFinder(
PhpCsFixer\Finder::create()
Expand Down
2 changes: 1 addition & 1 deletion examples/coroutine/batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Coroutine::set(['hook_flags' => SWOOLE_HOOK_ALL]);

Coroutine\run(function () {
$use = microtime(true);
$use = microtime(true);
$results = batch([
'gethostbyname' => function () {
return gethostbyname('localhost');
Expand Down
5 changes: 3 additions & 2 deletions examples/fastcgi/greeter/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@

Coroutine\run(function () {
try {
$client = new Client('php-fpm', 9000);
$client = new Client('php-fpm', 9000);
$request = (new HttpRequest())
->withScriptFilename(__DIR__ . '/greeter.php')
->withMethod('POST')
->withBody(['who' => 'Swoole']);
->withBody(['who' => 'Swoole'])
;
$response = $client->execute($request);
echo "Result: {$response->getBody()}\n";
} catch (Client\Exception $exception) {
Expand Down
12 changes: 6 additions & 6 deletions examples/fastcgi/proxy/wordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
require dirname(__DIR__, 2) . '/bootstrap.php';

$documentRoot = '/var/www/html';
$server = new Server('0.0.0.0', 80, SWOOLE_BASE);
$server = new Server('0.0.0.0', 80, SWOOLE_BASE);
$server->set([
Constant::OPTION_WORKER_NUM => swoole_cpu_num() * 2,
Constant::OPTION_HTTP_PARSE_COOKIE => false,
Constant::OPTION_HTTP_PARSE_POST => false,
Constant::OPTION_DOCUMENT_ROOT => $documentRoot,
Constant::OPTION_ENABLE_STATIC_HANDLER => true,
Constant::OPTION_WORKER_NUM => swoole_cpu_num() * 2,
Constant::OPTION_HTTP_PARSE_COOKIE => false,
Constant::OPTION_HTTP_PARSE_POST => false,
Constant::OPTION_DOCUMENT_ROOT => $documentRoot,
Constant::OPTION_ENABLE_STATIC_HANDLER => true,
Constant::OPTION_STATIC_HANDLER_LOCATIONS => ['/wp-admin', '/wp-content', '/wp-includes'],
]);
$proxy = new Proxy('wordpress:9000', $documentRoot);
Expand Down
5 changes: 3 additions & 2 deletions examples/fastcgi/var/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

Coroutine\run(function () {
try {
$client = new Client('php-fpm', 9000);
$client = new Client('php-fpm', 9000);
$request = (new HttpRequest())
->withDocumentRoot(__DIR__)
->withScriptFilename(__DIR__ . '/var.php')
Expand All @@ -26,7 +26,8 @@
->withUri('/var?foo=bar&bar=char')
->withHeader('X-Foo', 'bar')
->withHeader('X-Bar', 'char')
->withBody(['foo' => 'bar', 'bar' => 'char']);
->withBody(['foo' => 'bar', 'bar' => 'char'])
;
$response = $client->execute($request);
echo "Result: \n{$response->getBody()}";
} catch (Client\Exception $exception) {
Expand Down
2 changes: 1 addition & 1 deletion examples/mysqli/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
);
for ($n = N; $n--;) {
Coroutine::create(function () use ($pool) {
$mysqli = $pool->get();
$mysqli = $pool->get();
$statement = $mysqli->prepare('SELECT ? + ?');
if (!$statement) {
throw new RuntimeException('Prepare failed');
Expand Down
2 changes: 1 addition & 1 deletion examples/mysqli/io_failure.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
for ($c = C; $c--;) {
Coroutine::create(function () use ($pool, &$success) {
while (true) {
$mysqli = $pool->get();
$mysqli = $pool->get();
$statement = $mysqli->prepare('SELECT ? + ?');
if (!$statement) {
throw new RuntimeException('Prepare failed');
Expand Down
6 changes: 3 additions & 3 deletions examples/pdo/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
);
for ($n = N; $n--;) {
Coroutine::create(function () use ($pool) {
$pdo = $pool->get();
$pdo = $pool->get();
$statement = $pdo->prepare('SELECT ? + ?');
if (!$statement) {
throw new RuntimeException('Prepare failed');
}
$a = mt_rand(1, 100);
$b = mt_rand(1, 100);
$a = mt_rand(1, 100);
$b = mt_rand(1, 100);
$result = $statement->execute([$a, $b]);
if (!$result) {
throw new RuntimeException('Execute failed');
Expand Down
4 changes: 2 additions & 2 deletions examples/pdo/io_failure.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@
Coroutine::create(function () use ($pool, &$success) {
/* @var $pdo PDO */
while (true) {
$pdo = $pool->get();
$pdo = $pool->get();
$statement = $pdo->prepare('SELECT 1 + 1');
$ret = $statement->execute();
$ret = $statement->execute();
if ($ret !== true) {
throw new RuntimeException('Execute failed');
}
Expand Down
2 changes: 1 addition & 1 deletion examples/redis/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
);
for ($n = N; $n--;) {
Coroutine::create(function () use ($pool) {
$redis = $pool->get();
$redis = $pool->get();
$result = $redis->set('foo', 'bar');
if (!$result) {
throw new RuntimeException('Set failed');
Expand Down
6 changes: 3 additions & 3 deletions src/__init__.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

declare(strict_types=1);
return [
'name' => 'swoole',
'name' => 'swoole',
'checkFileChange' => !getenv('SWOOLE_LIBRARY_DEV'),
'output' => getenv('SWOOLE_DIR') . '/ext-src/php_swoole_library.h',
'stripComments' => false,
'output' => getenv('SWOOLE_DIR') . '/ext-src/php_swoole_library.h',
'stripComments' => false,
/* Notice: Sort by dependency */
'files' => [
# <basic> #
Expand Down
9 changes: 4 additions & 5 deletions src/core/ArrayObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ public function last()
}

/**
* @return null|int|string
* @return int|string|null
*/
public function firstKey()
{
return array_key_first($this->array);
}

/**
* @return null|int|string
* @return int|string|null
*/
public function lastKey()
{
Expand Down Expand Up @@ -218,7 +218,7 @@ public function clear(): self

/**
* @param mixed $key
* @return null|mixed
* @return mixed|null
*/
#[\ReturnTypeWillChange]
public function offsetGet($key)
Expand Down Expand Up @@ -417,10 +417,9 @@ public function popBack()

/**
* @param mixed $offset
* @param int $length
* @return static
*/
public function slice($offset, int $length = null, bool $preserve_keys = false): self
public function slice($offset, ?int $length = null, bool $preserve_keys = false): self
{
return new static(array_slice($this->array, ...func_get_args()));
}
Expand Down
12 changes: 6 additions & 6 deletions src/core/ConnectionPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ class ConnectionPool
/** @var int */
protected $num;

/** @var null|string */
/** @var string|null */
protected $proxy;

public function __construct(callable $constructor, int $size = self::DEFAULT_SIZE, ?string $proxy = null)
{
$this->pool = new Channel($this->size = $size);
$this->pool = new Channel($this->size = $size);
$this->constructor = $constructor;
$this->num = 0;
$this->proxy = $proxy;
$this->num = 0;
$this->proxy = $proxy;
}

public function fill(): void
Expand Down Expand Up @@ -76,7 +76,7 @@ public function close(): void
{
$this->pool->close();
$this->pool = null;
$this->num = 0;
$this->num = 0;
}

protected function make(): void
Expand All @@ -87,7 +87,7 @@ protected function make(): void
$connection = new $this->proxy($this->constructor);
} else {
$constructor = $this->constructor;
$connection = $constructor();
$connection = $constructor();
}
} catch (\Throwable $throwable) {
$this->num--;
Expand Down
2 changes: 1 addition & 1 deletion src/core/Coroutine/Barrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static function wait(Barrier &$barrier, float $timeout = -1)
if ($barrier->cid !== -1) {
throw new Exception('The barrier is waiting, cannot wait again.');
}
$cid = Coroutine::getCid();
$cid = Coroutine::getCid();
$barrier->cid = $cid;
if ($timeout > 0 && ($timeout_ms = (int) ($timeout * 1000)) > 0) {
$barrier->timer = Timer::after($timeout_ms, function () use ($cid) {
Expand Down
Loading

0 comments on commit c8046e7

Please sign in to comment.