Skip to content

Commit

Permalink
chore: allow php-cs-fixer major version 3
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-davis committed Aug 27, 2024
1 parent e0e1ccb commit 7d78ce1
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 53 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ jobs:
matrix:
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
coverage: ['pcov']
code-style: ['yes']
code-analysis: ['no']
include:
- php-versions: '7.1'
coverage: 'none'
code-style: 'yes'
code-analysis: 'yes'
- php-versions: '8.4'
coverage: 'pcov'
code-style: 'yes'
code-analysis: 'yes'
steps:
- name: Checkout
Expand Down Expand Up @@ -51,7 +54,7 @@ jobs:
run: composer install --no-progress --prefer-dist --optimize-autoloader

- name: Code Analysis (PHP CS-Fixer)
if: matrix.code-analysis == 'yes'
if: matrix.code-style == 'yes'
run: PHP_CS_FIXER_IGNORE_ENV=true php vendor/bin/php-cs-fixer fix --dry-run --diff

- name: Code Analysis (PHPStan)
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ composer.lock
tests/cov
tests/.phpunit.result.cache
.php_cs.cache
.php-cs-fixer.cache
17 changes: 17 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

$finder = PhpCsFixer\Finder::create()
->exclude('vendor')
->in(__DIR__);

$config = new PhpCsFixer\Config();
$config->setRules([
'@PSR1' => true,
'@Symfony' => true,
'nullable_type_declaration' => [
'syntax' => 'question_mark',
],
'nullable_type_declaration_for_default_null_value' => true,
]);
$config->setFinder($finder);
return $config;
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
}
},
"require-dev": {
"friendsofphp/php-cs-fixer": "~2.17.1",
"friendsofphp/php-cs-fixer": "~2.17.1||^3.63",
"phpstan/phpstan": "^0.12",
"phpunit/phpunit" : "^7.5 || ^8.5 || ^9.6"
},
Expand All @@ -55,7 +55,7 @@
"phpstan analyse lib tests"
],
"cs-fixer": [
"php-cs-fixer fix"
"PHP_CS_FIXER_IGNORE_ENV=true php-cs-fixer fix"
],
"phpunit": [
"phpunit --configuration tests/phpunit.xml"
Expand Down
10 changes: 6 additions & 4 deletions examples/curl.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env php
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

/*
* The following example demonstrates doing asynchronous HTTP requests with
Expand All @@ -26,10 +28,10 @@
curl_setopt_array($ch1, CURLOPT_URL, 'http://httpbin.org/delay/5');
curl_setopt_array($ch2, CURLOPT_URL, 'http://httpbin.org/delay/5');

//create the multiple cURL handle
// create the multiple cURL handle
$mh = curl_multi_init();

//add the two handles
// add the two handles
curl_multi_add_handle($mh, $ch1);
curl_multi_add_handle($mh, $ch2);

Expand Down Expand Up @@ -112,7 +114,7 @@ function curl_multi_loop_scheduler($mh, callable $done)

Loop\run();

//close the handles
// close the handles
curl_multi_remove_handle($mh, $ch1);
curl_multi_remove_handle($mh, $ch2);
curl_multi_close($mh);
9 changes: 7 additions & 2 deletions examples/promise.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/usr/bin/env php
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

use function Sabre\Event\coroutine;
use Sabre\Event\Loop;
use Sabre\Event\Promise;

use function Sabre\Event\coroutine;

require __DIR__.'/../vendor/autoload.php';

/**
Expand All @@ -25,6 +28,7 @@
$result = $promise
->then(function ($value) {
echo "Step 2\n";

// Immediately returning a new value.
return $value.' world';
})
Expand All @@ -42,6 +46,7 @@
})
->then(function ($value) {
echo "Step 4\n";

// This is the final event handler.
return $value.' you rock!';
})
Expand Down
4 changes: 3 additions & 1 deletion examples/tail.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env php
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

/*
* This example can be used to logfile processing and basically wraps the tail
Expand Down
2 changes: 1 addition & 1 deletion lib/Loop/Loop.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Loop
*/
public function setTimeout(callable $cb, float $timeout)
{
$triggerTime = microtime(true) + ($timeout);
$triggerTime = microtime(true) + $timeout;

if (!$this->timers) {
// Special case when the timers array was empty.
Expand Down
18 changes: 6 additions & 12 deletions lib/Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Sabre\Event;

use Exception;
use Throwable;

/**
* An implementation of the Promise pattern.
Expand All @@ -30,17 +29,17 @@ class Promise
/**
* The asynchronous operation is pending.
*/
const PENDING = 0;
public const PENDING = 0;

/**
* The asynchronous operation has completed, and has a result.
*/
const FULFILLED = 1;
public const FULFILLED = 1;

/**
* The asynchronous operation has completed with an error.
*/
const REJECTED = 2;
public const REJECTED = 2;

/**
* The current state of this promise.
Expand Down Expand Up @@ -128,8 +127,6 @@ public function otherwise(callable $onRejected): Promise

/**
* Marks this promise as fulfilled and sets its return value.
*
* @param mixed $value
*/
public function fulfill($value = null)
{
Expand All @@ -146,7 +143,7 @@ public function fulfill($value = null)
/**
* Marks this promise as rejected, and set its rejection reason.
*/
public function reject(Throwable $reason)
public function reject(\Throwable $reason)
{
if (self::PENDING !== $this->state) {
throw new PromiseAlreadyResolvedException('This promise is already resolved, and you\'re not allowed to resolve a promise more than once');
Expand All @@ -169,7 +166,6 @@ public function reject(Throwable $reason)
* one. In PHP it might be useful to call this on the last promise in a
* chain.
*
* @return mixed
* @psalm-return TReturn
*/
public function wait()
Expand Down Expand Up @@ -208,10 +204,8 @@ public function wait()
*
* If the promise was fulfilled, this will be the result value. If the
* promise was rejected, this property hold the rejection reason.
*
* @var mixed
*/
protected $value = null;
protected $value;

/**
* This method is used to call either an onFulfilled or onRejected callback.
Expand Down Expand Up @@ -242,7 +236,7 @@ private function invokeCallback(Promise $subPromise, ?callable $callBack = null)
// immediately fulfill the chained promise.
$subPromise->fulfill($result);
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
// If the event handler threw an exception, we need to make sure that
// the chained promise is rejected as well.
$subPromise->reject($e);
Expand Down
5 changes: 1 addition & 4 deletions lib/Promise/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Sabre\Event\Promise;

use Sabre\Event\Promise;
use Throwable;

/**
* This file contains a set of functions that are useful for dealing with the
Expand Down Expand Up @@ -101,8 +100,6 @@ function ($reason) use ($fail, &$alreadyDone) {
*
* If the value is a promise, the returned promise will attach itself to that
* promise and eventually get the same state as the followed promise.
*
* @param mixed $value
*/
function resolve($value): Promise
{
Expand All @@ -119,7 +116,7 @@ function resolve($value): Promise
/**
* Returns a Promise that will reject with the given reason.
*/
function reject(Throwable $reason): Promise
function reject(\Throwable $reason): Promise
{
$promise = new Promise();
$promise->reject($reason);
Expand Down
2 changes: 1 addition & 1 deletion lib/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ class Version
/**
* Full version number.
*/
const VERSION = '5.1.6';
public const VERSION = '5.1.6';
}
13 changes: 7 additions & 6 deletions lib/coroutine.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Sabre\Event;

use Generator;
use Throwable;

/**
* Turn asynchronous promise-based code into something that looks synchronous
Expand Down Expand Up @@ -43,7 +42,9 @@
* });
*
* @psalm-template TReturn
*
* @psalm-param callable():\Generator<mixed, mixed, mixed, TReturn> $gen
*
* @psalm-return Promise<TReturn>
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
Expand All @@ -53,7 +54,7 @@
function coroutine(callable $gen): Promise
{
$generator = $gen();
if (!$generator instanceof Generator) {
if (!$generator instanceof \Generator) {
throw new \InvalidArgumentException('You must pass a generator function');
}

Expand All @@ -73,11 +74,11 @@ function ($value) use ($generator, &$advanceGenerator) {
$generator->send($value);
$advanceGenerator();
},
function (Throwable $reason) use ($generator, $advanceGenerator) {
function (\Throwable $reason) use ($generator, $advanceGenerator) {
$generator->throw($reason);
$advanceGenerator();
}
)->otherwise(function (Throwable $reason) use ($promise) {
)->otherwise(function (\Throwable $reason) use ($promise) {
// This error handler would be called, if something in the
// generator throws an exception, and it's not caught
// locally.
Expand All @@ -102,7 +103,7 @@ function (Throwable $reason) use ($generator, $advanceGenerator) {
if ($returnValue instanceof Promise) {
$returnValue->then(function ($value) use ($promise) {
$promise->fulfill($value);
}, function (Throwable $reason) use ($promise) {
}, function (\Throwable $reason) use ($promise) {
$promise->reject($reason);
});
} else {
Expand All @@ -113,7 +114,7 @@ function (Throwable $reason) use ($generator, $advanceGenerator) {

try {
$advanceGenerator();
} catch (Throwable $e) {
} catch (\Throwable $e) {
$promise->reject($e);
}

Expand Down
4 changes: 1 addition & 3 deletions tests/Event/CoroutineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Sabre\Event;

use Exception;

class CoroutineTest extends \PHPUnit\Framework\TestCase
{
public function testNonGenerator()
Expand Down Expand Up @@ -46,7 +44,7 @@ public function testRejectedPromise()
{
$start = 0;
$promise = new Promise(function ($fulfill, $reject) {
$reject(new Exception('2'));
$reject(new \Exception('2'));
});

coroutine(function () use (&$start, $promise) {
Expand Down
15 changes: 7 additions & 8 deletions tests/Event/Promise/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Sabre\Event\Promise;

use Exception;
use Sabre\Event\Loop;
use Sabre\Event\Promise;

Expand Down Expand Up @@ -53,10 +52,10 @@ function ($value) use (&$finalValue) {
}
);

$promise1->reject(new Exception('1'));
$promise1->reject(new \Exception('1'));
Loop\run();
$this->assertEquals('1', $finalValue->getMessage());
$promise2->reject(new Exception('2'));
$promise2->reject(new \Exception('2'));
Loop\run();
$this->assertEquals(1, $finalValue->getMessage());
}
Expand All @@ -78,10 +77,10 @@ function ($value) use (&$finalValue) {
}
);

$promise1->reject(new Exception('1'));
$promise1->reject(new \Exception('1'));
Loop\run();
$this->assertEquals(1, $finalValue->getMessage());
$promise2->fulfill(new Exception('2'));
$promise2->fulfill(new \Exception('2'));
Loop\run();
$this->assertEquals(1, $finalValue->getMessage());
}
Expand Down Expand Up @@ -124,10 +123,10 @@ function ($value) use (&$finalValue) {
}
);

$promise1->reject(new Exception('1'));
$promise1->reject(new \Exception('1'));
Loop\run();
$this->assertEquals(1, $finalValue->getMessage());
$promise2->reject(new Exception('2'));
$promise2->reject(new \Exception('2'));
Loop\run();
$this->assertEquals(1, $finalValue->getMessage());
}
Expand Down Expand Up @@ -162,7 +161,7 @@ public function testReject()
{
$finalValue = 0;

$promise = reject(new Exception('1'));
$promise = reject(new \Exception('1'));
$promise->then(function ($value) use (&$finalValue) {
$finalValue = 'im broken';
}, function ($reason) use (&$finalValue) {
Expand Down
Loading

0 comments on commit 7d78ce1

Please sign in to comment.