Skip to content
This repository was archived by the owner on Jun 10, 2022. It is now read-only.

Commit 22c15d1

Browse files
committed
Use doctrine/coding-standard:^2.1 as CS
Which is essentially the same as we were using before, it only imports the functions and constants from global scope (which in my opinion is more readable than what we had before).
1 parent d093aee commit 22c15d1

Some content is hidden

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

60 files changed

+710
-630
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@
3636
"ext-krb5": "To be able to ues the GSSAPI SASL mechanism"
3737
},
3838
"require-dev": {
39-
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.4",
39+
"doctrine/coding-standard": "^2.1",
4040
"infection/infection": "^0.7",
4141
"kmelia/monolog-stdout-handler": "^1.2",
4242
"mikey179/vfsStream": "^1.6.5",
4343
"monolog/monolog": "^1.23",
4444
"phpstan/phpstan": "^0.9",
4545
"phpstan/phpstan-phpunit": "^0.9",
46-
"phpstan/phpstan-strict-rules": "^0.9.0",
46+
"phpstan/phpstan-strict-rules": "^0.9",
4747
"phpunit/phpcov": "^4.0",
4848
"phpunit/phpunit": "^6.5",
4949
"satooshi/php-coveralls": "2.0.0",
5050
"slevomat/coding-standard": "^4.1",
51-
"squizlabs/php_codesniffer": "^3.1"
51+
"squizlabs/php_codesniffer": "^3.2"
5252
}
5353
}

phpcs.xml.dist

Lines changed: 14 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -11,175 +11,35 @@
1111
<file>src</file>
1212
<file>tests</file>
1313

14-
<rule ref="PSR2"/>
14+
<rule ref="Doctrine" />
1515

16-
<rule ref="Generic.Formatting.SpaceAfterCast" />
17-
<rule ref="Generic.Formatting.SpaceAfterNot" />
18-
<rule ref="Generic.Arrays.DisallowLongArraySyntax" />
19-
20-
<rule ref="Squiz.Strings.ConcatenationSpacing">
21-
<properties>
22-
<property name="spacing" value="1"/>
23-
<property name="ignoreNewlines" value="true"/>
24-
</properties>
25-
</rule>
26-
27-
<rule ref="Generic.Formatting.MultipleStatementAlignment">
28-
<properties>
29-
<property name="error" value="true"/>
30-
</properties>
31-
</rule>
32-
33-
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
34-
<exclude-pattern>*/example/*</exclude-pattern>
35-
</rule>
3616
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
3717
<exclude-pattern>*/tests\/Base\/StreamStub/*</exclude-pattern>
3818
</rule>
3919

40-
<!-- strict rules -->
41-
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowEqualOperators" />
42-
<rule ref="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly" />
43-
<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition" />
44-
<rule ref="SlevomatCodingStandard.ControlStructures.LanguageConstructWithParentheses" />
45-
<rule ref="SlevomatCodingStandard.Classes.UnusedPrivateElements" />
46-
<rule ref="SlevomatCodingStandard.Namespaces.UseFromSameNamespace" />
47-
<rule ref="SlevomatCodingStandard.Exceptions.DeadCatch" />
48-
<rule ref="SlevomatCodingStandard.Arrays.TrailingArrayComma" />
49-
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowYodaComparison" />
50-
<rule ref="SlevomatCodingStandard.TypeHints.LongTypeHints" />
51-
<rule ref="SlevomatCodingStandard.Classes.ClassConstantVisibility" />
52-
<rule ref="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue" />
53-
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHintSpacing" />
54-
<rule ref="SlevomatCodingStandard.Namespaces.DisallowGroupUse" />
55-
<rule ref="SlevomatCodingStandard.Namespaces.MultipleUsesPerLine" />
56-
<rule ref="SlevomatCodingStandard.Namespaces.UseDoesNotStartWithBackslash" />
57-
<rule ref="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration" />
58-
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing" />
59-
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses" />
60-
61-
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
62-
<properties>
63-
<property name="allowFullyQualifiedGlobalClasses" type="boolean" value="true"/>
64-
<property name="allowFullyQualifiedGlobalFunctions" type="boolean" value="true"/>
65-
<property name="allowFullyQualifiedGlobalConstants" type="boolean" value="true"/>
66-
<property name="allowFullyQualifiedNameForCollidingClasses" type="boolean" value="true"/>
67-
</properties>
68-
</rule>
69-
70-
<rule ref="SlevomatCodingStandard.Types.EmptyLinesAroundTypeBraces">
71-
<properties>
72-
<property name="linesCountAfterOpeningBrace" value="0"/>
73-
<property name="linesCountBeforeClosingBrace" value="0"/>
74-
</properties>
20+
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
21+
<exclude-pattern>*/example/*</exclude-pattern>
7522
</rule>
76-
77-
<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration">
78-
<properties>
79-
<property name="enableEachParameterAndReturnInspection" value="true"/>
80-
<property name="traversableTypeHints" type="array" value="Doctrine\Common\Collections\Collection"/>
81-
<property
82-
name="usefulAnnotations"
83-
type="array"
84-
value="
85-
@before,
86-
@beforeClass,
87-
@after,
88-
@afterClass,
89-
@test,
90-
@dataProvider,
91-
@deprecated,
92-
@expectedException,
93-
@expectedExceptionMessage,
94-
@expectedExceptionMessageRegExp,
95-
@expectedExceptionCode,
96-
@expectedDeprecation,
97-
@group,
98-
@internal,
99-
@link,
100-
@see,
101-
@throws
102-
"
103-
/>
104-
</properties>
23+
<rule ref="Squiz.Classes.ClassFileName.NoMatch">
24+
<exclude-pattern>*/example/*</exclude-pattern>
10525
</rule>
106-
107-
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
108-
<properties>
109-
<property name="searchAnnotations" type="boolean" value="true"/>
110-
</properties>
26+
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFallbackGlobalName">
27+
<exclude-pattern>*/example/*</exclude-pattern>
11128
</rule>
11229

30+
<!-- Require presence of declare(strict_types=1) -->
11331
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
11432
<properties>
115-
<property name="newlinesCountBetweenOpenTagAndDeclare" value="1" />
116-
<property name="spacesCountAroundEqualsSign" value="0" />
33+
<property name="newlinesCountBetweenOpenTagAndDeclare" value="1"/>
34+
<property name="spacesCountAroundEqualsSign" value="0"/>
35+
<property name="newlinesCountAfterDeclare" value="2"/>
11736
</properties>
11837
</rule>
11938

120-
<rule ref="Squiz.Strings.DoubleQuoteUsage"/>
121-
<rule ref="Squiz.Strings.DoubleQuoteUsage.ContainsVar">
122-
<message>Variable "%s" not allowed in double quoted string; use sprintf() or concatenation instead</message>
123-
</rule>
124-
125-
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
126-
127-
<rule ref="Squiz.Arrays.ArrayDeclaration">
128-
<exclude name="Squiz.Arrays.ArrayDeclaration.KeyNotAligned"/>
129-
<exclude name="Squiz.Arrays.ArrayDeclaration.SingleLineNotAllowed"/>
130-
<exclude name="Squiz.Arrays.ArrayDeclaration.CloseBraceNotAligned"/>
131-
<exclude name="Squiz.Arrays.ArrayDeclaration.ValueNotAligned"/>
132-
</rule>
133-
134-
<rule ref="Squiz.Strings.EchoedStrings"/>
135-
<rule ref="Squiz.WhiteSpace.CastSpacing"/>
136-
<rule ref="Squiz.WhiteSpace.FunctionOpeningBraceSpace"/>
137-
<rule ref="Squiz.WhiteSpace.LanguageConstructSpacing"/>
138-
<rule ref="Squiz.WhiteSpace.LogicalOperatorSpacing"/>
139-
<rule ref="Generic.Files.EndFileNewline"/>
140-
<rule ref="Generic.WhiteSpace.ScopeIndent"/>
141-
142-
<rule ref="Squiz.WhiteSpace.ObjectOperatorSpacing">
39+
<!-- Require space around colon in return types -->
40+
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing">
14341
<properties>
144-
<property name="ignoreNewlines" value="true"/>
42+
<property name="spacesCountBeforeColon" value="0"/>
14543
</properties>
14644
</rule>
147-
148-
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
149-
<properties>
150-
<property name="ignoreBlankLines" value="false"/>
151-
</properties>
152-
</rule>
153-
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines">
154-
<severity>5</severity>
155-
</rule>
156-
157-
<rule ref="Generic.CodeAnalysis.EmptyStatement">
158-
<exclude name="Generic.CodeAnalysis.EmptyStatement.DetectedCATCH"/>
159-
</rule>
160-
161-
<rule ref="Squiz.PHP.NonExecutableCode"/>
162-
163-
<rule ref="Squiz.Scope.StaticThisUsage"/>
164-
<rule ref="Generic.CodeAnalysis.UnnecessaryFinalModifier"/>
165-
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/>
166-
<rule ref="Squiz.Functions.GlobalFunction"/>
167-
<rule ref="Squiz.PHP.GlobalKeyword"/>
168-
<rule ref="Squiz.PHP.InnerFunctions"/>
169-
<rule ref="Generic.PHP.DeprecatedFunctions"/>
170-
<rule ref="Generic.PHP.ForbiddenFunctions"/>
171-
<rule ref="Squiz.Operators.ValidLogicalOperators"/>
172-
<rule ref="Squiz.PHP.LowercasePHPFunctions"/>
173-
<rule ref="Generic.PHP.BacktickOperator"/>
174-
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
175-
<rule ref="Generic.PHP.SAPIUsage"/>
176-
<rule ref="PEAR.Commenting.InlineComment"/>
177-
178-
<rule ref="SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalConstants">
179-
<exclude-pattern>*/example/*</exclude-pattern>
180-
</rule>
181-
<rule ref="SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions">
182-
<exclude-pattern>*/example/*</exclude-pattern>
183-
</rule>
18445
</ruleset>
185-

src/Broker.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
use Kafka\Sasl\Gssapi;
77
use Kafka\Sasl\Plain;
88
use Kafka\Sasl\Scram;
9+
use function array_keys;
10+
use function explode;
11+
use function in_array;
12+
use function serialize;
13+
use function shuffle;
14+
use function sprintf;
15+
use function strpos;
916

1017
class Broker
1118
{
@@ -68,7 +75,7 @@ public function getGroupBrokerId(): int
6875

6976
/**
7077
* @param mixed[][] $topics
71-
* @param mixed[] $brokersResult
78+
* @param mixed[] $brokersResult
7279
*/
7380
public function setData(array $topics, array $brokersResult): bool
7481
{
@@ -80,7 +87,7 @@ public function setData(array $topics, array $brokersResult): bool
8087

8188
$changed = false;
8289

83-
if (\serialize($this->brokers) !== \serialize($brokers)) {
90+
if (serialize($this->brokers) !== serialize($brokers)) {
8491
$this->brokers = $brokers;
8592

8693
$changed = true;
@@ -102,7 +109,7 @@ public function setData(array $topics, array $brokersResult): bool
102109
$newTopics[$topic['topicName']] = $item;
103110
}
104111

105-
if (\serialize($this->topics) !== \serialize($newTopics)) {
112+
if (serialize($this->topics) !== serialize($newTopics)) {
106113
$this->topics = $newTopics;
107114

108115
$changed = true;
@@ -134,8 +141,8 @@ public function getMetaConnect(string $key, bool $modeSync = false): ?CommonSock
134141

135142
public function getRandConnect(bool $modeSync = false): ?CommonSocket
136143
{
137-
$nodeIds = \array_keys($this->brokers);
138-
\shuffle($nodeIds);
144+
$nodeIds = array_keys($this->brokers);
145+
shuffle($nodeIds);
139146

140147
if (! isset($nodeIds[0])) {
141148
return null;
@@ -168,11 +175,11 @@ public function getConnect(string $key, string $type, bool $modeSync = false): ?
168175
if (isset($this->brokers[$key])) {
169176
$hostname = $this->brokers[$key];
170177

171-
[$host, $port] = \explode(':', $hostname);
178+
[$host, $port] = explode(':', $hostname);
172179
}
173180

174-
if (\strpos($key, ':') !== false) {
175-
[$host, $port] = \explode(':', $key);
181+
if (strpos($key, ':') !== false) {
182+
[$host, $port] = explode(':', $key);
176183
}
177184

178185
if ($host === null || $port === null || (! $modeSync && $this->process === null)) {
@@ -243,9 +250,9 @@ private function judgeConnectionConfig(): ?SaslMechanism
243250

244251
$securityProtocol = $this->config->getSecurityProtocol();
245252

246-
$this->config->setSslEnable(! \in_array($securityProtocol, $plainConnections, true));
253+
$this->config->setSslEnable(! in_array($securityProtocol, $plainConnections, true));
247254

248-
if (\in_array($securityProtocol, $saslConnections, true)) {
255+
if (in_array($securityProtocol, $saslConnections, true)) {
249256
return $this->getSaslMechanismProvider($this->config);
250257
}
251258

@@ -272,6 +279,6 @@ private function getSaslMechanismProvider(Config $config): SaslMechanism
272279
return new Scram($username, $password, Scram::SCRAM_SHA_512);
273280
}
274281

275-
throw new Exception(\sprintf('"%s" is an invalid SASL mechanism', $mechanism));
282+
throw new Exception(sprintf('"%s" is an invalid SASL mechanism', $mechanism));
276283
}
277284
}

0 commit comments

Comments
 (0)