Skip to content

Commit 855ddd1

Browse files
authored
Merge pull request #17 from wmde/fun-cs
Add new Coding Style
2 parents 9439519 + a3ba917 commit 855ddd1

24 files changed

+60
-211
lines changed

composer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,20 @@
1010
"wmde/freezable-value-object": "~1.0"
1111
},
1212
"require-dev": {
13-
"squizlabs/php_codesniffer": "~3.5",
1413
"phpunit/phpunit": "~9.2",
1514
"ockcyp/covers-validator": "~1.0",
16-
"slevomat/coding-standard": "^4.6",
15+
"wmde/fundraising-phpcs": "~1.0",
1716
"phpmd/phpmd": "~2.6",
1817
"phpstan/phpstan": "^0.12",
1918
"phpstan/phpstan-phpunit": "^0.12"
2019
},
20+
"repositories": [
21+
{
22+
"type": "vcs",
23+
"url": "https://github.com/wmde/fundraising-phpcs",
24+
"no-api": true
25+
}
26+
],
2127
"autoload": {
2228
"psr-4": {
2329
"WMDE\\Fundraising\\AddressChangeContext\\": "src/"

phpcs.xml

Lines changed: 1 addition & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -11,168 +11,6 @@
1111
<arg name="extensions" value="php"/>
1212
<arg value="s"/>
1313
<arg value="p"/>
14+
<rule ref="vendor/wmde/fundraising-phpcs/WMDE/Fundraising" />
1415

15-
<!--<rule ref="vendor/mediawiki/mediawiki-codesniffer/MediaWiki/Sniffs/WhiteSpace">-->
16-
<!--<exclude name="vendor/mediawiki/mediawiki-codesniffer/MediaWiki/Sniffs/WhiteSpace/SpaceBeforeSingleLineCommentSniff.php" />-->
17-
<!--</rule>-->
18-
19-
<rule ref="Generic.Arrays.DisallowLongArraySyntax" />
20-
<rule ref="Generic.Classes" />
21-
<rule ref="Generic.CodeAnalysis">
22-
<exclude name="Generic.CodeAnalysis.EmptyStatement" />
23-
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter" />
24-
<exclude name="Generic.CodeAnalysis.AssignmentInCondition.Found" />
25-
</rule>
26-
<rule ref="Generic.ControlStructures" />
27-
28-
<rule ref="Generic.Files.ByteOrderMark" />
29-
<rule ref="Generic.Files.LineEndings" />
30-
<rule ref="Generic.Files.LineLength">
31-
<properties>
32-
<!-- https://github.com/squizlabs/PHP_CodeSniffer/issues/1094 -->
33-
<property name="lineLimit" value="170" />
34-
<property name="absoluteLineLimit" value="170" />
35-
</properties>
36-
</rule>
37-
38-
<rule ref="Generic.Formatting.DisallowMultipleStatements" />
39-
40-
<rule ref="Generic.Functions.CallTimePassByReference" />
41-
<rule ref="Generic.Functions.FunctionCallArgumentSpacing" />
42-
43-
<rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie" />
44-
45-
<rule ref="Generic.Metrics.NestingLevel">
46-
<properties>
47-
<property name="nestingLevel" value="3" />
48-
<property name="absoluteNestingLevel" value="3" />
49-
</properties>
50-
</rule>
51-
52-
<rule ref="Generic.Metrics.CyclomaticComplexity">
53-
<properties>
54-
<property name="complexity" value="10" />
55-
<property name="absoluteComplexity" value="10" />
56-
</properties>
57-
</rule>
58-
59-
<rule ref="Generic.NamingConventions" />
60-
<!-- TODO: create variation of this sniff that allows underscores in test methods -->
61-
<rule ref="Generic.NamingConventions.CamelCapsFunctionName.ScopeNotCamelCaps">
62-
<!-- Exclude test methods like "testGivenInvalidInput_methodThrowsException". -->
63-
<exclude-pattern>*Test\.php</exclude-pattern>
64-
</rule>
65-
66-
<rule ref="Generic.PHP.CharacterBeforePHPOpeningTag" />
67-
<rule ref="Generic.PHP.DeprecatedFunctions" />
68-
<rule ref="Generic.PHP.DisallowShortOpenTag" />
69-
<rule ref="Generic.PHP.ForbiddenFunctions" />
70-
<rule ref="Generic.PHP.LowerCaseConstant" />
71-
<rule ref="Generic.PHP.LowerCaseKeyword" />
72-
<rule ref="Generic.PHP.SAPIUsage" />
73-
74-
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent" />
75-
76-
<rule ref="PSR1" />
77-
<!-- TODO: create variation of this sniff that allows underscores in test methods -->
78-
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
79-
<!-- Exclude test methods like "testGivenInvalidInput_methodThrowsException". -->
80-
<exclude-pattern>*Test\.php</exclude-pattern>
81-
</rule>
82-
83-
<rule ref="PSR2.Classes.PropertyDeclaration" />
84-
<rule ref="PSR2.ControlStructures.ElseIfDeclaration" />
85-
<rule ref="PSR2.Namespaces" />
86-
87-
<rule ref="Squiz.Arrays.ArrayBracketSpacing" />
88-
<rule ref="Squiz.CSS.SemicolonSpacing" />
89-
<rule ref="Squiz.Classes.DuplicateProperty" />
90-
<rule ref="Squiz.Classes.SelfMemberReference" />
91-
<rule ref="Squiz.Classes.ValidClassName" />
92-
<rule ref="Squiz.Functions.FunctionDuplicateArgument" />
93-
<rule ref="Squiz.Functions.GlobalFunction" />
94-
<rule ref="Squiz.Scope" />
95-
96-
<rule ref="Squiz.Strings.DoubleQuoteUsage" />
97-
<rule ref="Squiz.Strings.DoubleQuoteUsage.ContainsVar">
98-
<severity>0</severity>
99-
</rule>
100-
101-
<rule ref="Squiz.WhiteSpace.CastSpacing" />
102-
<rule ref="Squiz.WhiteSpace.LanguageConstructSpacing" />
103-
<rule ref="Squiz.WhiteSpace.LogicalOperatorSpacing" />
104-
105-
<rule ref="Squiz.WhiteSpace.OperatorSpacing">
106-
<properties>
107-
<property name="ignoreNewlines" value="true" />
108-
</properties>
109-
<exclude name="Squiz.WhiteSpace.OperatorSpacing.NoSpaceBefore" />
110-
<exclude name="Squiz.WhiteSpace.OperatorSpacing.NoSpaceAfter" />
111-
</rule>
112-
113-
<rule ref="Squiz.WhiteSpace.ScopeClosingBrace" />
114-
<rule ref="Squiz.WhiteSpace.ScopeKeywordSpacing" />
115-
<rule ref="Squiz.WhiteSpace.SemicolonSpacing" />
116-
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace" />
117-
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines">
118-
<severity>0</severity>
119-
</rule>
120-
121-
<rule ref="Zend.Files.ClosingTag" />
122-
123-
<!-- Using 3rd party sniff while Squiz isn't there, yet. https://github.com/squizlabs/PHP_CodeSniffer/issues/911 -->
124-
<rule ref="./vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/TypeHints/DeclareStrictTypesSniff.php" />
125-
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
126-
<properties>
127-
<property name="newlinesCountBetweenOpenTagAndDeclare" value="2" />
128-
<property name="spacesCountAroundEqualsSign" value="1" />
129-
</properties>
130-
</rule>
131-
132-
<rule ref="./vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/TypeHints/ReturnTypeHintSpacingSniff.php" />
133-
134-
<rule ref="./vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/TypeHints/TypeHintDeclarationSniff.php">
135-
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableParameterTypeHintSpecification" />
136-
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversablePropertyTypeHintSpecification" />
137-
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification" />
138-
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingPropertyTypeHint" />
139-
</rule>
140-
141-
<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration">
142-
<properties>
143-
<property name="usefulAnnotations" type="array" value="
144-
@see,
145-
@throws,
146-
@expectedException,
147-
@expectedExceptionMessage,
148-
@dataProvider,
149-
@slowThreshold,
150-
@noinspection,
151-
@SuppressWarnings
152-
"/>
153-
<property name="enableVoidTypeHint" value="false" />
154-
</properties>
155-
</rule>
156-
157-
<rule ref="./vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Namespaces/UseDoesNotStartWithBackslashSniff.php" />
158-
159-
<!-- MediaWiki.WhiteSpace.SpaceyParenthesis replica for up-to-date codesniffer version -->
160-
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
161-
<properties>
162-
<property name="equalsSpacing" value="1" />
163-
<property name="requiredSpacesAfterOpen" value="1" />
164-
<property name="requiredSpacesBeforeClose" value="1" />
165-
</properties>
166-
</rule>
167-
168-
<rule ref="PEAR.Functions.FunctionCallSignature">
169-
<properties>
170-
<property name="requiredSpacesAfterOpen" value="1" />
171-
<property name="requiredSpacesBeforeClose" value="1" />
172-
</properties>
173-
<exclude name="PEAR.Functions.FunctionCallSignature.Indent" />
174-
<exclude name="PEAR.Functions.FunctionCallSignature.OpeningIndent" />
175-
<exclude name="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket" />
176-
<exclude name="PEAR.Functions.FunctionCallSignature.CloseBracketLine" />
177-
</rule>
17816
</ruleset>

src/AddressChangeContextFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
namespace WMDE\Fundraising\AddressChangeContext;
66

7-
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
87
use Doctrine\ORM\Mapping\Driver\XmlDriver;
8+
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
99

1010
/**
11-
* @licence GNU GPL v2+
11+
* @license GPL-2.0-or-later
1212
*/
1313
class AddressChangeContextFactory {
1414

src/DataAccess/DoctrineAddressChangeRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ public function storeAddressChange( AddressChange $addressChange ): void {
2424
$this->entityManager->persist( $addressChange );
2525
$this->entityManager->flush();
2626
}
27-
}
27+
}

src/Domain/AddressChangeRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use WMDE\Fundraising\AddressChangeContext\Domain\Model\AddressChange;
88

99
/**
10-
* @license GNU GPL v2+
10+
* @license GPL-2.0-or-later
1111
*/
1212
interface AddressChangeRepository {
1313

src/Domain/Model/Address.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private function __construct(
6060
$this->addressType = $addressType;
6161
}
6262

63-
static public function newPersonalAddress(
63+
public static function newPersonalAddress(
6464
string $salutation,
6565
string $title,
6666
string $firstName,
@@ -80,7 +80,7 @@ static public function newPersonalAddress(
8080
return new self( $salutation, '', $title, $firstName, $lastName, $address, $postcode, $city, $country, self::TYPE_PERSONAL );
8181
}
8282

83-
static public function newCompanyAddress(
83+
public static function newCompanyAddress(
8484
string $company,
8585
string $address,
8686
string $postcode,
@@ -94,7 +94,7 @@ static public function newCompanyAddress(
9494
return new self( '', $company, '', '', '', $address, $postcode, $city, $country, self::TYPE_COMPANY );
9595
}
9696

97-
static private function assertNotEmpty( string $field, string $value ): void {
97+
private static function assertNotEmpty( string $field, string $value ): void {
9898
if ( $value === '' ) {
9999
throw new ChangeAddressValidationException( $field );
100100
}

src/Domain/Model/AddressChange.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ public function __construct( string $addressType, string $externalIdType, int $e
6060
if ( $addressType !== self::ADDRESS_TYPE_PERSON && $addressType !== self::ADDRESS_TYPE_COMPANY ) {
6161
throw new \InvalidArgumentException( 'Invalid address type' );
6262
}
63-
if( $externalIdType !== self::EXTERNAL_ID_TYPE_DONATION && $externalIdType !== self::EXTERNAL_ID_TYPE_MEMBERSHIP ) {
63+
if ( $externalIdType !== self::EXTERNAL_ID_TYPE_DONATION && $externalIdType !== self::EXTERNAL_ID_TYPE_MEMBERSHIP ) {
6464
throw new \InvalidArgumentException( 'Invalid external reference type' );
6565
}
6666
$this->createdAt = $createdAt ?? new \DateTime();
67-
$this->modifiedAt = clone( $this->createdAt );
67+
$this->modifiedAt = clone $this->createdAt;
6868
$this->donationReceipt = true;
6969
$this->externalId = $externalId;
7070
$this->externalIdType = $externalIdType;

src/Domain/Model/AddressChangeBuilder.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,4 @@ public static function generateUuid(): string {
8484
return call_user_func( [ self::$uuidGenerator, 'generate' ] );
8585
}
8686

87-
88-
}
87+
}

src/Domain/Model/AddressChangeId.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ public function __toString(): string {
2525
return $this->identifier;
2626
}
2727

28-
}
28+
}

src/Domain/Model/UuidGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66

77
interface UuidGenerator {
88
public function generate(): string;
9-
}
9+
}

0 commit comments

Comments
 (0)