Skip to content

Commit b486cab

Browse files
committed
apply php-code-sniffer standard
1 parent 8cae0fa commit b486cab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+2034
-1452
lines changed

build/phpcs-ruleset.xml

+27-6
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717
<!-- https://github.com/slevomat/coding-standard -->
1818
<!-- https://github.com/symplify/easy-coding-standard#ignore-what-you-cant-fix -->
1919
<exclude-pattern>*/vendor/*</exclude-pattern>
20+
<exclude-pattern>*/Zend/*</exclude-pattern>
21+
<exclude-pattern>*/example/*</exclude-pattern>
2022

2123
<arg name="error-severity" value="1" />
22-
<arg name="warning-severity" value="1" />
24+
<!-- TODO: warning-severity=1 -->
25+
<arg name="warning-severity" value="0" />
26+
<!-- TODO: warning-severity=1 -->
2327

2428
<arg name="cache" value="tmp/phpcs-tempfile" />
2529
<arg name="encoding" value="utf8" />
@@ -34,9 +38,29 @@
3438

3539
<ini name="memory_limit" value="-1" />
3640

37-
<rule ref="PSR1"/>
41+
<rule ref="PSR1">
42+
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps" />
43+
</rule>
3844
<rule ref="PSR2"/>
3945
<rule ref="vendor/slevomat/coding-standard/SlevomatCodingStandard/ruleset.xml">
46+
<!-- TODO: remove below -->
47+
<exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes" />
48+
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingAnyTypeHint" />
49+
<exclude name="SlevomatCodingStandard.ControlStructures.DisallowEmpty.DisallowedEmpty" />
50+
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingAnyTypeHint" />
51+
<exclude name="SlevomatCodingStandard.ControlStructures.AssignmentInCondition.AssignmentInCondition" />
52+
<exclude name="SlevomatCodingStandard.Files.LineLength.LineTooLong" />
53+
<exclude name="SlevomatCodingStandard.Classes.ForbiddenPublicProperty.ForbiddenPublicProperty" />
54+
<exclude name="SlevomatCodingStandard.Functions.StrictCall.StrictParameterMissing" />
55+
<exclude name="SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter" />
56+
<exclude name="SlevomatCodingStandard.PHP.DisallowReference.DisallowedAssigningByReference" />
57+
<exclude name="SlevomatCodingStandard.Operators.DisallowIncrementAndDecrementOperators.DisallowedPostIncrementOperator" />
58+
<exclude name="SlevomatCodingStandard.Operators.DisallowIncrementAndDecrementOperators.DisallowedPostDecrementOperator" />
59+
<exclude name="SlevomatCodingStandard.Operators.DisallowIncrementAndDecrementOperators.DisallowedPreIncrementOperator" />
60+
<exclude name="SlevomatCodingStandard.Operators.RequireOnlyStandaloneIncrementAndDecrementOperators.PreIncrementOperatorNotUsedStandalone" />
61+
<exclude name="SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh" />
62+
<!-- TODO: remove above -->
63+
4064
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint" />
4165
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification" />
4266
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversablePropertyTypeHintSpecification" />
@@ -48,6 +72,7 @@
4872
<exclude name="SlevomatCodingStandard.Commenting" />
4973

5074
<exclude name="SlevomatCodingStandard.Classes.RequireAbstractOrFinal" />
75+
<exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming" />
5176
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming" />
5277
<exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming" />
5378
<exclude name="SlevomatCodingStandard.Classes.SuperfluousTraitNaming" />
@@ -267,16 +292,12 @@
267292
</rule>
268293
<rule ref="Squiz.WhiteSpace.SemicolonSpacing"/>
269294
<rule ref="PSR12.Properties.ConstantVisibility" />
270-
<rule ref="Squiz.Strings.DoubleQuoteUsage.ContainsVar" />
271295
<rule ref="Squiz.Strings.ConcatenationSpacing">
272296
<properties>
273297
<property name="ignoreNewlines" value="true"/>
274298
<property name="spacing" value="1"/>
275299
</properties>
276300
</rule>
277-
<rule ref="Squiz.Strings.DoubleQuoteUsage.ContainsVar">
278-
<message>Variable "%s" not allowed in double quoted string; use sprintf() instead</message>
279-
</rule>
280301
<rule ref="Squiz.Scope.StaticThisUsage"/>
281302
<rule ref="Internal.NoCodeFound">
282303
<severity>5</severity>

example/adapter/nsq/pop.php

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Backq: Background tasks with workers & publishers via queues
45
*
@@ -7,23 +8,24 @@
78
* Distributed under the terms of the MIT License.
89
* Redistributions of files must retain the above copyright notice.
910
*/
11+
use BackQ\Adapter\Nsq;
1012

1113
/**
1214
* Example subscriber using
1315
* Adapter for NSQ
1416
* @see http://nsq.io
1517
*/
16-
include_once('../../../src/Adapter/AbstractAdapter.php');
17-
include_once('../../../src/Adapter/IO/AbstractIO.php');
18-
include_once('../../../src/Adapter/IO/StreamIO.php');
19-
include_once('../../../src/Adapter/Nsq.php');
20-
include_once('../../../src/Adapter/IO/Exception/IOException.php');
21-
include_once('../../../src/Adapter/IO/Exception/TimeoutException.php');
22-
include_once('../../../src/Adapter/IO/Exception/RuntimeException.php');
18+
include_once '../../../src/Adapter/AbstractAdapter.php';
19+
include_once '../../../src/Adapter/IO/AbstractIO.php';
20+
include_once '../../../src/Adapter/IO/StreamIO.php';
21+
include_once '../../../src/Adapter/Nsq.php';
22+
include_once '../../../src/Adapter/IO/Exception/IOException.php';
23+
include_once '../../../src/Adapter/IO/Exception/TimeoutException.php';
24+
include_once '../../../src/Adapter/IO/Exception/RuntimeException.php';
2325

2426
$queue = 'hello-world';
2527

26-
$nsqsub = new \BackQ\Adapter\Nsq('127.0.0.1', 4150, ['persistent' => false]);
28+
$nsqsub = new Nsq('127.0.0.1', 4150, ['persistent' => false]);
2729
$nsqsub->logInfo('Starting');
2830
$nsqsub->setWorkTimeout(5);
2931
if ($nsqsub->connect()) {
@@ -36,7 +38,7 @@
3638
$job = $nsqsub->pickTask();
3739
if ($job) {
3840
$nsqsub->logInfo('Got task: ' . json_encode($job));
39-
if (1 == rand(1,2)) {
41+
if (1 === rand(1, 2)) {
4042
$nsqsub->logInfo('Reporting success');
4143
$nsqsub->afterWorkSuccess($job[0]);
4244
} else {

example/adapter/nsq/push.php

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Backq: Background tasks with workers & publishers via queues
45
*
@@ -7,23 +8,24 @@
78
* Distributed under the terms of the MIT License.
89
* Redistributions of files must retain the above copyright notice.
910
*/
11+
use BackQ\Adapter\Nsq;
1012

1113
/**
1214
* Example publisher using
1315
* Adapter for NSQ
1416
* @see http://nsq.io
1517
*/
16-
include_once('../../../src/Adapter/AbstractAdapter.php');
17-
include_once('../../../src/Adapter/IO/AbstractIO.php');
18-
include_once('../../../src/Adapter/IO/StreamIO.php');
19-
include_once('../../../src/Adapter/Nsq.php');
20-
include_once('../../../src/Adapter/IO/Exception/IOException.php');
21-
include_once('../../../src/Adapter/IO/Exception/TimeoutException.php');
22-
include_once('../../../src/Adapter/IO/Exception/RuntimeException.php');
18+
include_once '../../../src/Adapter/AbstractAdapter.php';
19+
include_once '../../../src/Adapter/IO/AbstractIO.php';
20+
include_once '../../../src/Adapter/IO/StreamIO.php';
21+
include_once '../../../src/Adapter/Nsq.php';
22+
include_once '../../../src/Adapter/IO/Exception/IOException.php';
23+
include_once '../../../src/Adapter/IO/Exception/TimeoutException.php';
24+
include_once '../../../src/Adapter/IO/Exception/RuntimeException.php';
2325

2426
$queue = 'hello-world';
2527

26-
$nsqpub = new \BackQ\Adapter\Nsq('127.0.0.1', 4150, ['persistent' => false]);
28+
$nsqpub = new Nsq('127.0.0.1', 4150, ['persistent' => false]);
2729
$nsqpub->setWorkTimeout(5);
2830
if ($nsqpub->connect()) {
2931
$nsqpub->logInfo('Connected');
@@ -45,4 +47,3 @@
4547
$nsqpub->logInfo('All done');
4648
$nsqpub->disconnect();
4749
$nsqpub->logInfo('Disconnected');
48-

example/publishers/apnsd.php

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Backq: Background tasks with workers & publishers via queues
45
*
@@ -7,21 +8,24 @@
78
* Distributed under the terms of the MIT License.
89
* Redistributions of files must retain the above copyright notice.
910
*/
11+
use Backq\Adapter\AbstractAdapter;
12+
use BackQ\Adapter\Beanstalk;
13+
use BackQ\Publisher\Apnsd;
1014

1115
/**
1216
* APNS Publisher
1317
* Queues APNS (Apple Push Notifications)
1418
*/
1519
include_once '../../../../../vendor/autoload.php';
1620

17-
class MyApnsdPublisher extends \BackQ\Publisher\Apnsd
21+
class MyApnsdPublisher extends Apnsd
1822
{
19-
public const PARAM_JOBTTR = \BackQ\Adapter\Beanstalk::PARAM_JOBTTR;
20-
public const PARAM_READYWAIT = \BackQ\Adapter\Beanstalk::PARAM_READYWAIT;
23+
public const PARAM_JOBTTR = Beanstalk::PARAM_JOBTTR;
24+
public const PARAM_READYWAIT = Beanstalk::PARAM_READYWAIT;
2125

22-
protected function setupAdapter(): \Backq\Adapter\AbstractAdapter
26+
protected function setupAdapter(): AbstractAdapter
2327
{
24-
return new \BackQ\Adapter\Beanstalk;
28+
return new Beanstalk();
2529
}
2630
}
2731

@@ -31,8 +35,8 @@ protected function setupAdapter(): \Backq\Adapter\AbstractAdapter
3135
$message->setBadge(3);
3236
$message->setText('Hello APNs-enabled device!');
3337
$message->setSound();
34-
$message->setCustomProperty('acme2', array('bang', 'whiz'));
35-
$message->setCustomProperty('acme3', array('bing', 'bong'));
38+
$message->setCustomProperty('acme2', ['bang', 'whiz']);
39+
$message->setCustomProperty('acme3', ['bing', 'bong']);
3640
$message->setExpiry(30);
3741

3842
$app = '-myapp1';
@@ -46,7 +50,7 @@ protected function setupAdapter(): \Backq\Adapter\AbstractAdapter
4650
* Delay each job by 1 second
4751
*/
4852
$params = [MyApnsdPublisher::PARAM_JOBTTR => 4,
49-
MyApnsdPublisher::PARAM_READYWAIT => 1];
53+
MyApnsdPublisher::PARAM_READYWAIT => 1];
5054

5155
foreach ($messagesQ as $app => $messages) {
5256
echo 'Publishing message: ' . $message->getText() . "\n";

example/publishers/lib/myprocesspublisher.php

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Backq: Background tasks with workers & publishers via queues
45
*
@@ -7,18 +8,23 @@
78
* Distributed under the terms of the MIT License.
89
* Redistributions of files must retain the above copyright notice.
910
*/
11+
use Backq\Adapter\AbstractAdapter;
12+
use BackQ\Adapter\Beanstalk;
13+
use BackQ\Publisher\Process;
14+
use Symfony\Component\Console\Logger\ConsoleLogger;
15+
use Symfony\Component\Console\Output\ConsoleOutput;
1016

11-
final class MyProcessPublisher extends \BackQ\Publisher\Process
17+
final class MyProcessPublisher extends Process
1218
{
13-
public const PARAM_JOBTTR = \BackQ\Adapter\Beanstalk::PARAM_JOBTTR;
14-
public const PARAM_READYWAIT = \BackQ\Adapter\Beanstalk::PARAM_READYWAIT;
19+
public const PARAM_JOBTTR = Beanstalk::PARAM_JOBTTR;
20+
public const PARAM_READYWAIT = Beanstalk::PARAM_READYWAIT;
1521

1622
protected $queueName = '456';
1723

18-
protected function setupAdapter(): \Backq\Adapter\AbstractAdapter
24+
protected function setupAdapter(): AbstractAdapter
1925
{
20-
$logger = new \Symfony\Component\Console\Logger\ConsoleLogger(new \Symfony\Component\Console\Output\ConsoleOutput(\Symfony\Component\Console\Output\ConsoleOutput::VERBOSITY_DEBUG));
21-
$adapter = new \BackQ\Adapter\Beanstalk;
26+
$logger = new ConsoleLogger(new ConsoleOutput(ConsoleOutput::VERBOSITY_DEBUG));
27+
$adapter = new Beanstalk();
2228
$adapter->setLogger($logger);
2329

2430
return $adapter;

example/publishers/process.php

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Backq: Background tasks with workers & publishers via queues
45
*
@@ -7,6 +8,12 @@
78
* Distributed under the terms of the MIT License.
89
* Redistributions of files must retain the above copyright notice.
910
*/
11+
use Backq\Adapter\AbstractAdapter;
12+
use BackQ\Adapter\Beanstalk;
13+
use BackQ\Adapter\Redis;
14+
use BackQ\Publisher\Process;
15+
use Symfony\Component\Console\Logger\ConsoleLogger;
16+
use Symfony\Component\Console\Output\ConsoleOutput;
1017

1118
/**
1219
* Publisher
@@ -17,18 +24,19 @@
1724

1825
include_once '../../../../../vendor/autoload.php';
1926

20-
final class MyProcessPublisher extends \BackQ\Publisher\Process
27+
final class MyProcessPublisher extends Process
2128
{
29+
2230
protected $queueName = 'abc';
2331

24-
protected function setupAdapter(): \Backq\Adapter\AbstractAdapter
32+
protected function setupAdapter(): AbstractAdapter
2533
{
26-
$adapters = [new \BackQ\Adapter\Redis(), new \BackQ\Adapter\Beanstalk()];
34+
$adapters = [new Redis(), new Beanstalk()];
2735
$adapter = $adapters[array_rand($adapters)];
2836
echo 'Using ' . get_class($adapter) . ' adapter' . "\n";
2937

30-
$output = new \Symfony\Component\Console\Output\ConsoleOutput(\Symfony\Component\Console\Output\ConsoleOutput::VERBOSITY_DEBUG);
31-
$logger = new \Symfony\Component\Console\Logger\ConsoleLogger($output);
38+
$output = new ConsoleOutput(ConsoleOutput::VERBOSITY_DEBUG);
39+
$logger = new ConsoleLogger($output);
3240

3341
$adapter->setLogger($logger);
3442

example/publishers/process/redis.php

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Backq: Background tasks with workers & publishers via queues
45
*
@@ -7,6 +8,11 @@
78
* Distributed under the terms of the MIT License.
89
* Redistributions of files must retain the above copyright notice.
910
*/
11+
use Backq\Adapter\AbstractAdapter;
12+
use BackQ\Adapter\Redis;
13+
use BackQ\Publisher\Process;
14+
use Symfony\Component\Console\Logger\ConsoleLogger;
15+
use Symfony\Component\Console\Output\ConsoleOutput;
1016

1117
/**
1218
* Publisher
@@ -17,16 +23,16 @@
1723

1824
include_once '../../../../../../vendor/autoload.php';
1925

20-
final class MyProcessPublisher extends \BackQ\Publisher\Process
26+
final class MyProcessPublisher extends Process
2127
{
22-
public const PARAM_READYWAIT = \BackQ\Adapter\Redis::PARAM_READYWAIT;
28+
public const PARAM_READYWAIT = Redis::PARAM_READYWAIT;
2329

24-
protected function setupAdapter(): \Backq\Adapter\AbstractAdapter
30+
protected function setupAdapter(): AbstractAdapter
2531
{
26-
$output = new \Symfony\Component\Console\Output\ConsoleOutput(\Symfony\Component\Console\Output\ConsoleOutput::VERBOSITY_DEBUG);
27-
$logger = new \Symfony\Component\Console\Logger\ConsoleLogger($output);
32+
$output = new ConsoleOutput(ConsoleOutput::VERBOSITY_DEBUG);
33+
$logger = new ConsoleLogger($output);
2834

29-
$adapter = new \BackQ\Adapter\Redis('127.0.0.1', 6379);
35+
$adapter = new Redis('127.0.0.1', 6379);
3036
$adapter->setLogger($logger);
3137

3238
return $adapter;

0 commit comments

Comments
 (0)