Skip to content

Commit 3bd2083

Browse files
authored
Merge pull request #132 from phil-davis/php-cs-fixer-3-for-5.1
chore: allow php-cs-fixer major version 3
2 parents e0e1ccb + 162d4c6 commit 3bd2083

File tree

16 files changed

+77
-54
lines changed

16 files changed

+77
-54
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ jobs:
1414
matrix:
1515
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
1616
coverage: ['pcov']
17+
code-style: ['yes']
1718
code-analysis: ['no']
1819
include:
1920
- php-versions: '7.1'
2021
coverage: 'none'
22+
code-style: 'yes'
2123
code-analysis: 'yes'
2224
- php-versions: '8.4'
2325
coverage: 'pcov'
26+
code-style: 'yes'
2427
code-analysis: 'yes'
2528
steps:
2629
- name: Checkout
@@ -51,7 +54,7 @@ jobs:
5154
run: composer install --no-progress --prefer-dist --optimize-autoloader
5255

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

5760
- name: Code Analysis (PHPStan)

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ composer.lock
66
tests/cov
77
tests/.phpunit.result.cache
88
.php_cs.cache
9+
.php-cs-fixer.cache

.php-cs-fixer.dist.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->exclude('vendor')
5+
->in(__DIR__);
6+
7+
$config = new PhpCsFixer\Config();
8+
$config->setRules([
9+
'@PSR1' => true,
10+
'@Symfony' => true,
11+
'blank_line_between_import_groups' => false,
12+
'nullable_type_declaration' => [
13+
'syntax' => 'question_mark',
14+
],
15+
'nullable_type_declaration_for_default_null_value' => true,
16+
]);
17+
$config->setFinder($finder);
18+
return $config;

.php_cs.dist

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ $config->getFinder()
66
->in(__DIR__);
77
$config->setRules([
88
'@PSR1' => true,
9-
'@Symfony' => true
9+
'@Symfony' => true,
10+
'ordered_imports' => [
11+
'imports_order' => [
12+
'class', 'function', 'const',
13+
],
14+
],
1015
]);
1116

1217
return $config;

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
}
4747
},
4848
"require-dev": {
49-
"friendsofphp/php-cs-fixer": "~2.17.1",
49+
"friendsofphp/php-cs-fixer": "~2.17.1||^3.63",
5050
"phpstan/phpstan": "^0.12",
5151
"phpunit/phpunit" : "^7.5 || ^8.5 || ^9.6"
5252
},
@@ -55,7 +55,7 @@
5555
"phpstan analyse lib tests"
5656
],
5757
"cs-fixer": [
58-
"php-cs-fixer fix"
58+
"PHP_CS_FIXER_IGNORE_ENV=true php-cs-fixer fix"
5959
],
6060
"phpunit": [
6161
"phpunit --configuration tests/phpunit.xml"

examples/curl.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env php
2-
<?php declare(strict_types=1);
2+
<?php
3+
4+
declare(strict_types=1);
35

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

29-
//create the multiple cURL handle
31+
// create the multiple cURL handle
3032
$mh = curl_multi_init();
3133

32-
//add the two handles
34+
// add the two handles
3335
curl_multi_add_handle($mh, $ch1);
3436
curl_multi_add_handle($mh, $ch2);
3537

@@ -112,7 +114,7 @@ function curl_multi_loop_scheduler($mh, callable $done)
112114

113115
Loop\run();
114116

115-
//close the handles
117+
// close the handles
116118
curl_multi_remove_handle($mh, $ch1);
117119
curl_multi_remove_handle($mh, $ch2);
118120
curl_multi_close($mh);

examples/promise.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#!/usr/bin/env php
2-
<?php declare(strict_types=1);
2+
<?php
3+
4+
declare(strict_types=1);
35

4-
use function Sabre\Event\coroutine;
56
use Sabre\Event\Loop;
67
use Sabre\Event\Promise;
8+
use function Sabre\Event\coroutine;
79

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

@@ -25,6 +27,7 @@
2527
$result = $promise
2628
->then(function ($value) {
2729
echo "Step 2\n";
30+
2831
// Immediately returning a new value.
2932
return $value.' world';
3033
})
@@ -42,6 +45,7 @@
4245
})
4346
->then(function ($value) {
4447
echo "Step 4\n";
48+
4549
// This is the final event handler.
4650
return $value.' you rock!';
4751
})

examples/tail.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env php
2-
<?php declare(strict_types=1);
2+
<?php
3+
4+
declare(strict_types=1);
35

46
/*
57
* This example can be used to logfile processing and basically wraps the tail

lib/Loop/Loop.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Loop
2424
*/
2525
public function setTimeout(callable $cb, float $timeout)
2626
{
27-
$triggerTime = microtime(true) + ($timeout);
27+
$triggerTime = microtime(true) + $timeout;
2828

2929
if (!$this->timers) {
3030
// Special case when the timers array was empty.

lib/Promise.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Sabre\Event;
66

77
use Exception;
8-
use Throwable;
98

109
/**
1110
* An implementation of the Promise pattern.
@@ -30,17 +29,17 @@ class Promise
3029
/**
3130
* The asynchronous operation is pending.
3231
*/
33-
const PENDING = 0;
32+
public const PENDING = 0;
3433

3534
/**
3635
* The asynchronous operation has completed, and has a result.
3736
*/
38-
const FULFILLED = 1;
37+
public const FULFILLED = 1;
3938

4039
/**
4140
* The asynchronous operation has completed with an error.
4241
*/
43-
const REJECTED = 2;
42+
public const REJECTED = 2;
4443

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

129128
/**
130129
* Marks this promise as fulfilled and sets its return value.
131-
*
132-
* @param mixed $value
133130
*/
134131
public function fulfill($value = null)
135132
{
@@ -146,7 +143,7 @@ public function fulfill($value = null)
146143
/**
147144
* Marks this promise as rejected, and set its rejection reason.
148145
*/
149-
public function reject(Throwable $reason)
146+
public function reject(\Throwable $reason)
150147
{
151148
if (self::PENDING !== $this->state) {
152149
throw new PromiseAlreadyResolvedException('This promise is already resolved, and you\'re not allowed to resolve a promise more than once');
@@ -169,7 +166,6 @@ public function reject(Throwable $reason)
169166
* one. In PHP it might be useful to call this on the last promise in a
170167
* chain.
171168
*
172-
* @return mixed
173169
* @psalm-return TReturn
174170
*/
175171
public function wait()
@@ -208,10 +204,8 @@ public function wait()
208204
*
209205
* If the promise was fulfilled, this will be the result value. If the
210206
* promise was rejected, this property hold the rejection reason.
211-
*
212-
* @var mixed
213207
*/
214-
protected $value = null;
208+
protected $value;
215209

216210
/**
217211
* This method is used to call either an onFulfilled or onRejected callback.
@@ -242,7 +236,7 @@ private function invokeCallback(Promise $subPromise, ?callable $callBack = null)
242236
// immediately fulfill the chained promise.
243237
$subPromise->fulfill($result);
244238
}
245-
} catch (Throwable $e) {
239+
} catch (\Throwable $e) {
246240
// If the event handler threw an exception, we need to make sure that
247241
// the chained promise is rejected as well.
248242
$subPromise->reject($e);

0 commit comments

Comments
 (0)