Skip to content

Commit 2ec5ff2

Browse files
committed
switch coding style checks from PHP_CodeSniffer to PHP CS Fixer
1 parent 99f377a commit 2ec5ff2

11 files changed

Lines changed: 136 additions & 60 deletions

.github/workflows/coding_style_checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ jobs:
1111
uses: actions/checkout@v4
1212

1313
- name: Run Coding Style Checks
14-
run: docker run -q --rm -v "$(pwd):/project" -w /project -i jakzal/phpqa:php8.2 phpcs -v --standard=PSR2 src tests/unit
14+
run: docker run -q --rm -v "$(pwd):/project" -w /project -i jakzal/phpqa:php8.2-alpine php-cs-fixer fix --dry-run

.php-cs-fixer.dist.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$header = <<<'EOF'
6+
Copyright 2018 Glu Mobile Inc.
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
EOF;
20+
21+
return (new PhpCsFixer\Config())
22+
->setRiskyAllowed(true)
23+
->setRules([
24+
'@DoctrineAnnotation' => true,
25+
'@PhpCsFixer' => true,
26+
'@PSR2' => true,
27+
'@Symfony' => true,
28+
'align_multiline_comment' => ['comment_type' => 'all_multiline'],
29+
'array_syntax' => ['syntax' => 'short'],
30+
'binary_operator_spaces' => ['operators' => ['=' => 'align', '=>' => 'align', ]],
31+
'blank_line_after_namespace' => true,
32+
'blank_line_before_statement' => ['statements' => ['declare']],
33+
'class_attributes_separation' => true,
34+
'concat_space' => ['spacing' => 'one'],
35+
'constant_case' => ['case' => 'lower'],
36+
'combine_consecutive_unsets' => true,
37+
'declare_strict_types' => true,
38+
'general_phpdoc_annotation_remove' => ['annotations' => ['author']],
39+
'header_comment' => ['comment_type' => 'PHPDoc', 'header' => $header, 'location' => 'after_open', 'separate' => 'bottom'],
40+
'increment_style' => ['style' => 'post'],
41+
'lambda_not_used_import' => false,
42+
'linebreak_after_opening_tag' => true,
43+
'list_syntax' => ['syntax' => 'short'],
44+
'lowercase_static_reference' => true,
45+
'multiline_comment_opening_closing' => true,
46+
'multiline_whitespace_before_semicolons' => ['strategy' => 'new_line_for_chained_calls'],
47+
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true, 'allow_unused_params' => true, 'remove_inheritdoc' => false],
48+
'no_unused_imports' => true,
49+
'no_useless_else' => true,
50+
'no_useless_return' => true,
51+
'not_operator_with_space' => false,
52+
'not_operator_with_successor_space' => false,
53+
'nullable_type_declaration_for_default_null_value' => ['use_nullable_type_declaration' => true],
54+
'php_unit_strict' => false,
55+
'phpdoc_align' => ['align' => 'left'],
56+
'phpdoc_annotation_without_dot' => false,
57+
'phpdoc_no_empty_return' => false,
58+
'phpdoc_types_order' => ['sort_algorithm' => 'none', 'null_adjustment' => 'always_last'],
59+
'phpdoc_separation' => false,
60+
'phpdoc_summary' => false,
61+
'ordered_class_elements' => true,
62+
'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'],
63+
'ordered_types' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
64+
'single_line_comment_style' => ['comment_types' => []],
65+
'single_line_comment_spacing' => false,
66+
'single_line_empty_body' => false,
67+
'single_quote' => true,
68+
'standardize_increment' => false,
69+
'standardize_not_equals' => true,
70+
'yoda_style' => ['always_move_variable' => false, 'equal' => false, 'identical' => false],
71+
])
72+
->setFinder(
73+
PhpCsFixer\Finder::create()
74+
->exclude(['vendor'])
75+
->in(__DIR__)
76+
)
77+
->setUsingCache(false);

index.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
<?php
22
/**
3+
* Copyright 2018 Glu Mobile Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
declare(strict_types=1);
19+
20+
/*
321
* This PHP page is used under Nginx/PHP-FPM for unit test purpose. It accepts three request parameters:
422
* 1. Parameter "reset" to wipe data cached in APCu.
523
* 2. If parameter "reset" not set:
@@ -17,8 +35,6 @@
1735
* docker exec -t $(docker ps -qf "name=php") bash -c "curl -i -w \"\n\" http://web"
1836
*/
1937

20-
declare(strict_types=1);
21-
2238
use CrowdStar\BackgroundProcessing\BackgroundProcessing;
2339
use Symfony\Component\Cache\Adapter\ApcuAdapter;
2440
use Symfony\Contracts\Cache\ItemInterface;

src/BackgroundProcessing.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
/**************************************************************************
2+
/**
33
* Copyright 2018 Glu Mobile Inc.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,26 +13,23 @@
1313
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
16-
*************************************************************************/
16+
*/
1717

1818
declare(strict_types=1);
1919

2020
namespace CrowdStar\BackgroundProcessing;
2121

22-
use Closure;
2322
use CrowdStar\BackgroundProcessing\Exception\AlreadyInvokedException;
2423
use CrowdStar\BackgroundProcessing\Exception\InvalidEnvironmentException;
2524
use CrowdStar\BackgroundProcessing\Timer\AbstractTimer;
2625

2726
/**
2827
* Class BackgroundProcessing
29-
*
30-
* @package CrowdStar\BackgroundProcessing
3128
*/
3229
class BackgroundProcessing
3330
{
3431
/**
35-
* @var Closure[]
32+
* @var \Closure[]
3633
*/
3734
protected static $closures = [];
3835

@@ -89,19 +86,17 @@ public static function reset()
8986
}
9087

9188
/**
92-
* @param Closure $op
9389
* @param array<mixed> ...$params
9490
* @return void
9591
*/
96-
public static function add(Closure $op, ...$params)
92+
public static function add(\Closure $op, ...$params)
9793
{
9894
self::$closures[] = function () use ($op, $params) {
9995
return $op(...$params);
10096
};
10197
}
10298

10399
/**
104-
* @param AbstractTimer $timer
105100
* @return void
106101
*/
107102
public static function addTimer(AbstractTimer $timer)
@@ -110,17 +105,13 @@ public static function addTimer(AbstractTimer $timer)
110105
}
111106

112107
/**
113-
* @param bool $invoked
114108
* @return void
115109
*/
116110
protected static function setInvoked(bool $invoked)
117111
{
118112
self::$invoked = $invoked;
119113
}
120114

121-
/**
122-
* @return bool
123-
*/
124115
protected static function isInvoked(): bool
125116
{
126117
return self::$invoked;

src/Exception/AlreadyInvokedException.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
/**************************************************************************
2+
/**
33
* Copyright 2018 Glu Mobile Inc.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,16 +13,14 @@
1313
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
16-
*************************************************************************/
16+
*/
1717

1818
declare(strict_types=1);
1919

2020
namespace CrowdStar\BackgroundProcessing\Exception;
2121

2222
/**
2323
* Class Exception
24-
*
25-
* @package CrowdStar\BackgroundProcessing
2624
*/
2725
class AlreadyInvokedException extends \Exception
2826
{

src/Exception/InvalidEnvironmentException.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
/**************************************************************************
2+
/**
33
* Copyright 2018 Glu Mobile Inc.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,16 +13,14 @@
1313
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
16-
*************************************************************************/
16+
*/
1717

1818
declare(strict_types=1);
1919

2020
namespace CrowdStar\BackgroundProcessing\Exception;
2121

2222
/**
2323
* Class Exception
24-
*
25-
* @package CrowdStar\BackgroundProcessing
2624
*/
2725
class InvalidEnvironmentException extends \Exception
2826
{

src/Timer/AbstractTimer.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
/**************************************************************************
2+
/**
33
* Copyright 2018 Glu Mobile Inc.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,23 +13,19 @@
1313
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
16-
*************************************************************************/
16+
*/
1717

1818
declare(strict_types=1);
1919

2020
namespace CrowdStar\BackgroundProcessing\Timer;
2121

2222
/**
2323
* Class AbstractTimer
24-
*
25-
* @package CrowdStar\BackgroundProcessing\Timer
2624
*/
2725
abstract class AbstractTimer
2826
{
2927
/**
3028
* Stop timing the current transaction before starting processing tasks in background.
31-
*
32-
* @return AbstractTimer
3329
*/
3430
abstract public function stopTiming(): AbstractTimer;
3531
}

src/Timer/NewRelicTimer.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
/**************************************************************************
2+
/**
33
* Copyright 2018 Glu Mobile Inc.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,21 +13,19 @@
1313
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
16-
*************************************************************************/
16+
*/
1717

1818
declare(strict_types=1);
1919

2020
namespace CrowdStar\BackgroundProcessing\Timer;
2121

2222
/**
2323
* Class NewRelicTimer
24-
*
25-
* @package CrowdStar\BackgroundProcessing\Timer
2624
*/
2725
class NewRelicTimer extends AbstractTimer
2826
{
2927
/**
30-
* @inheritdoc
28+
* {@inheritdoc}
3129
*/
3230
public function stopTiming(): AbstractTimer
3331
{

tests/bootstrap.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
/**************************************************************************
2+
/**
33
* Copyright 2018 Glu Mobile Inc.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,7 +13,7 @@
1313
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
16-
*************************************************************************/
16+
*/
1717

1818
declare(strict_types=1);
1919

tests/unit/BasicTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
/**************************************************************************
2+
/**
33
* Copyright 2018 Glu Mobile Inc.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,7 +13,7 @@
1313
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
16-
*************************************************************************/
16+
*/
1717

1818
declare(strict_types=1);
1919

@@ -26,7 +26,8 @@
2626
/**
2727
* Class BasicTest
2828
*
29-
* @package CrowdStar\Tests\BackgroundProcessing
29+
* @internal
30+
* @coversNothing
3031
*/
3132
class BasicTest extends TestCase
3233
{
@@ -36,7 +37,7 @@ class BasicTest extends TestCase
3637
protected static $counter = 0;
3738

3839
/**
39-
* @inheritdoc
40+
* {@inheritdoc}
4041
*/
4142
public static function tearDownAfterClass(): void
4243
{
@@ -46,7 +47,7 @@ public static function tearDownAfterClass(): void
4647
}
4748

4849
/**
49-
* @inheritdoc
50+
* {@inheritdoc}
5051
*/
5152
public function setUp(): void
5253
{
@@ -102,7 +103,7 @@ public static function dataRun(): array
102103
/**
103104
* @param array<array{0: \Closure, ?mixed}> $closures
104105
* @dataProvider dataRun
105-
* @covers BackgroundProcessing::run()
106+
* @covers \CrowdStar\BackgroundProcessing\BackgroundProcessing::run()
106107
* @throws AlreadyInvokedException|InvalidEnvironmentException
107108
*/
108109
public function testRun(int $expected, array $closures, string $message): void
@@ -115,7 +116,7 @@ public function testRun(int $expected, array $closures, string $message): void
115116
}
116117

117118
/**
118-
* @covers BackgroundProcessing::run()
119+
* @covers \CrowdStar\BackgroundProcessing\BackgroundProcessing::run()
119120
*/
120121
public function testRunWhenInvokedAlready(): void
121122
{

0 commit comments

Comments
 (0)