Skip to content

Commit

Permalink
Merge pull request #23 from wmde/fun-cs
Browse files Browse the repository at this point in the history
Add new Coding Style
  • Loading branch information
gbirke authored Jul 3, 2020
2 parents d072097 + 905ea27 commit 0589bf7
Show file tree
Hide file tree
Showing 24 changed files with 58 additions and 210 deletions.
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
"require-dev": {
"phpunit/phpunit": "~9.2",
"ockcyp/covers-validator": "~1.0",
"squizlabs/php_codesniffer": "~3.5",
"slevomat/coding-standard": "~4.5",
"wmde/fundraising-phpcs": "~1.0",
"phpstan/phpstan": "~0.11"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/wmde/fundraisingstore",
"url": "https://github.com/wmde/fundraising-phpcs",
"no-api": true
},
{
Expand Down
157 changes: 1 addition & 156 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,161 +11,6 @@
<arg name="extensions" value="php"/>
<arg value="s"/>
<arg value="p"/>

<rule ref="Generic.Arrays.DisallowLongArraySyntax" />
<rule ref="Generic.Classes" />
<rule ref="Generic.CodeAnalysis">
<exclude name="Generic.CodeAnalysis.EmptyStatement" />
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter" />
</rule>
<rule ref="Generic.ControlStructures" />

<rule ref="Generic.Files.ByteOrderMark" />
<rule ref="Generic.Files.LineEndings" />
<rule ref="Generic.Files.LineLength">
<properties>
<!-- https://github.com/squizlabs/PHP_CodeSniffer/issues/1094 -->
<property name="lineLimit" value="170" />
<property name="absoluteLineLimit" value="170" />
</properties>
</rule>

<rule ref="Generic.Formatting.DisallowMultipleStatements" />

<rule ref="Generic.Functions.CallTimePassByReference" />
<rule ref="Generic.Functions.FunctionCallArgumentSpacing" />

<rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie" />

<rule ref="Generic.Metrics.NestingLevel">
<properties>
<property name="nestingLevel" value="3" />
<property name="absoluteNestingLevel" value="3" />
</properties>
</rule>

<rule ref="Generic.Metrics.CyclomaticComplexity">
<properties>
<property name="complexity" value="10" />
<property name="absoluteComplexity" value="10" />
</properties>
</rule>

<rule ref="Generic.NamingConventions" />
<!-- TODO: create variation of this sniff that allows underscores in test methods -->
<rule ref="Generic.NamingConventions.CamelCapsFunctionName.ScopeNotCamelCaps">
<!-- Exclude test methods like "testGivenInvalidInput_methodThrowsException". -->
<exclude-pattern>*Test\.php</exclude-pattern>
</rule>

<rule ref="Generic.PHP.CharacterBeforePHPOpeningTag" />
<rule ref="Generic.PHP.DeprecatedFunctions" />
<rule ref="Generic.PHP.DisallowShortOpenTag" />
<rule ref="Generic.PHP.ForbiddenFunctions" />
<rule ref="Generic.PHP.LowerCaseConstant" />
<rule ref="Generic.PHP.LowerCaseKeyword" />
<rule ref="Generic.PHP.SAPIUsage" />

<rule ref="Generic.WhiteSpace.DisallowSpaceIndent" />

<rule ref="PSR1" />
<!-- TODO: create variation of this sniff that allows underscores in test methods -->
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
<!-- Exclude test methods like "testGivenInvalidInput_methodThrowsException". -->
<exclude-pattern>*Test\.php</exclude-pattern>
</rule>

<rule ref="PSR2.Classes.PropertyDeclaration" />
<rule ref="PSR2.ControlStructures.ElseIfDeclaration" />
<rule ref="PSR2.Namespaces" />

<rule ref="Squiz.Arrays.ArrayBracketSpacing" />
<rule ref="Squiz.CSS.SemicolonSpacing" />
<rule ref="Squiz.Classes.DuplicateProperty" />
<rule ref="Squiz.Classes.SelfMemberReference" />
<rule ref="Squiz.Classes.ValidClassName" />
<rule ref="Squiz.Functions.FunctionDuplicateArgument" />
<rule ref="Squiz.Functions.GlobalFunction" />
<rule ref="Squiz.Scope" />

<rule ref="Squiz.Strings.DoubleQuoteUsage" />
<rule ref="Squiz.Strings.DoubleQuoteUsage.ContainsVar">
<severity>0</severity>
</rule>

<rule ref="Squiz.WhiteSpace.CastSpacing" />
<rule ref="Squiz.WhiteSpace.LanguageConstructSpacing" />
<rule ref="Squiz.WhiteSpace.LogicalOperatorSpacing" />

<rule ref="Squiz.WhiteSpace.OperatorSpacing">
<properties>
<property name="ignoreNewlines" value="true" />
</properties>
<exclude name="Squiz.WhiteSpace.OperatorSpacing.NoSpaceBefore" />
<exclude name="Squiz.WhiteSpace.OperatorSpacing.NoSpaceAfter" />
</rule>

<rule ref="Squiz.WhiteSpace.ScopeClosingBrace" />
<rule ref="Squiz.WhiteSpace.ScopeKeywordSpacing" />
<rule ref="Squiz.WhiteSpace.SemicolonSpacing" />
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace" />
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines">
<severity>0</severity>
</rule>

<rule ref="Zend.Files.ClosingTag" />

<!-- MediaWiki.WhiteSpace.SpaceyParenthesis replica for up-to-date codesniffer version -->
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
<properties>
<property name="equalsSpacing" value="1" />
<property name="requiredSpacesAfterOpen" value="1" />
<property name="requiredSpacesBeforeClose" value="1" />
</properties>
</rule>

<rule ref="PEAR.Functions.FunctionCallSignature">
<properties>
<property name="requiredSpacesAfterOpen" value="1" />
<property name="requiredSpacesBeforeClose" value="1" />
</properties>
<exclude name="PEAR.Functions.FunctionCallSignature.Indent" />
<exclude name="PEAR.Functions.FunctionCallSignature.OpeningIndent" />
<exclude name="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket" />
<exclude name="PEAR.Functions.FunctionCallSignature.CloseBracketLine" />
</rule>

<!-- Using 3rd party sniff while Squiz isn't there, yet. https://github.com/squizlabs/PHP_CodeSniffer/issues/911 -->
<rule ref="./vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/TypeHints/DeclareStrictTypesSniff.php" />
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<properties>
<property name="newlinesCountBetweenOpenTagAndDeclare" value="2" />
<property name="spacesCountAroundEqualsSign" value="1" />
</properties>
</rule>

<rule ref="./vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/TypeHints/ReturnTypeHintSpacingSniff.php" />

<rule ref="./vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/TypeHints/TypeHintDeclarationSniff.php">
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableParameterTypeHintSpecification" />
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversablePropertyTypeHintSpecification" />
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification" />
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingPropertyTypeHint" />
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration">
<properties>
<property name="usefulAnnotations" type="array" value="
@see,
@throws,
@dataProvider,
@slowThreshold,
@noinspection
"/>
<property name="enableVoidTypeHint" value="false" />
</properties>
</rule>

<rule ref="./vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Namespaces/UseDoesNotStartWithBackslashSniff.php" />
<rule ref="vendor/wmde/fundraising-phpcs/WMDE/Fundraising" />

</ruleset>
16 changes: 11 additions & 5 deletions src/DataAccess/DoctrineSubscriptionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
use WMDE\Fundraising\SubscriptionContext\Domain\Repositories\SubscriptionRepositoryException;

/**
* @license GNU GPL v2+
* @license GPL-2.0-or-later
* @author Gabriel Birke < [email protected] >
*/
class DoctrineSubscriptionRepository implements SubscriptionRepository {

private $entityManager;
private EntityManager $entityManager;

public function __construct( EntityManager $entityManager ) {
$this->entityManager = $entityManager;
Expand Down Expand Up @@ -47,15 +47,21 @@ public function countSimilar( Subscription $subscription, \DateTime $cutoffDateT
->setParameter( 'cutoffDate', $cutoffDateTime, Type::DATETIME )
->getQuery();
try {
return (int) $query->getSingleScalarResult();
return (int)$query->getSingleScalarResult();
}
catch ( ORMException $e ) {
throw new SubscriptionRepositoryException( 'Could not count subscriptions, check your query and its parameters.', $e );
}

}

/**
*/

/**
* @param string $confirmationCode
*
* @return Subscription|null
*
* @throws SubscriptionRepositoryException
*/
public function findByConfirmationCode( string $confirmationCode ): ?Subscription {
Expand All @@ -69,4 +75,4 @@ public function findByConfirmationCode( string $confirmationCode ): ?Subscriptio
}
}

}
}
2 changes: 1 addition & 1 deletion src/Domain/Repositories/SubscriptionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use WMDE\Fundraising\SubscriptionContext\Domain\Model\Subscription;

/**
* @license GNU GPL v2+
* @license GPL-2.0-or-later
* @author Gabriel Birke < [email protected] >
*/
interface SubscriptionRepository {
Expand Down
4 changes: 2 additions & 2 deletions src/Domain/Repositories/SubscriptionRepositoryException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace WMDE\Fundraising\SubscriptionContext\Domain\Repositories;

/**
* @license GNU GPL v2+
* @license GPL-2.0-or-later
* @author Gabriel Birke < [email protected] >
*/
class SubscriptionRepositoryException extends \RuntimeException {
Expand All @@ -14,4 +14,4 @@ public function __construct( string $message, \Exception $previous = null ) {
parent::__construct( $message, 0, $previous );
}

}
}
10 changes: 5 additions & 5 deletions src/Infrastructure/LoggingSubscriptionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
use WMDE\Fundraising\SubscriptionContext\Domain\Repositories\SubscriptionRepositoryException;

/**
* @license GNU GPL v2+
* @license GPL-2.0-or-later
* @author Jeroen De Dauw < [email protected] >
*/
class LoggingSubscriptionRepository implements SubscriptionRepository {

const CONTEXT_EXCEPTION_KEY = 'exception';
private const CONTEXT_EXCEPTION_KEY = 'exception';

private $repository;
private $logger;
private $logLevel;
private SubscriptionRepository $repository;
private LoggerInterface $logger;
private string $logLevel;

public function __construct( SubscriptionRepository $repository, LoggerInterface $logger ) {
$this->repository = $repository;
Expand Down
2 changes: 1 addition & 1 deletion src/SubscriptionContextFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ public function newEventSubscribers(): array {
];
}

}
}
7 changes: 3 additions & 4 deletions src/UseCases/AddSubscription/AddSubscriptionUseCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

use WMDE\EmailAddress\EmailAddress;
use WMDE\Fundraising\SubscriptionContext\Domain\Model\Subscription;
use WMDE\Fundraising\SubscriptionContext\Infrastructure\TemplateMailerInterface;
use WMDE\Fundraising\SubscriptionContext\Domain\Repositories\SubscriptionRepository;
use WMDE\Fundraising\SubscriptionContext\Domain\Repositories\SubscriptionRepositoryException;
use WMDE\Fundraising\SubscriptionContext\Infrastructure\TemplateMailerInterface;
use WMDE\Fundraising\SubscriptionContext\Validation\SubscriptionValidator;
use WMDE\FunValidators\ValidationResponse;

/**
* @license GNU GPL v2+
* @license GPL-2.0-or-later
* @author Gabriel Birke < [email protected] >
*/
class AddSubscriptionUseCase {
Expand All @@ -26,7 +26,6 @@ class AddSubscriptionUseCase {

public function __construct( SubscriptionRepository $subscriptionRepository,
SubscriptionValidator $subscriptionValidator, TemplateMailerInterface $mailer ) {

$this->subscriptionRepository = $subscriptionRepository;
$this->subscriptionValidator = $subscriptionValidator;
$this->mailer = $mailer;
Expand Down Expand Up @@ -80,4 +79,4 @@ private function generateConfirmationCode(): string {
return bin2hex( random_bytes( self::CONFIRMATION_CODE_LENGTH_BYTES ) );
}

}
}
4 changes: 2 additions & 2 deletions src/UseCases/AddSubscription/SubscriptionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace WMDE\Fundraising\SubscriptionContext\UseCases\AddSubscription;

/**
* @license GNU GPL v2+
* @license GPL-2.0-or-later
* @author Gabriel Birke < [email protected] >
*/
class SubscriptionRequest {
Expand Down Expand Up @@ -38,4 +38,4 @@ public function setSource( string $source ): void {
$this->source = $source;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
namespace WMDE\Fundraising\SubscriptionContext\UseCases\ConfirmSubscription;

use WMDE\EmailAddress\EmailAddress;
use WMDE\Fundraising\SubscriptionContext\Infrastructure\TemplateMailerInterface;
use WMDE\Fundraising\SubscriptionContext\Domain\Repositories\SubscriptionRepository;
use WMDE\Fundraising\SubscriptionContext\Infrastructure\TemplateMailerInterface;
use WMDE\FunValidators\ConstraintViolation;
use WMDE\FunValidators\ValidationResponse;

/**
* @license GNU GPL v2+
* @license GPL-2.0-or-later
* @author Gabriel Birke < [email protected] >
*/
class ConfirmSubscriptionUseCase {
Expand All @@ -26,7 +26,6 @@ public function __construct( SubscriptionRepository $subscriptionRepository, Tem
}

public function confirmSubscription( string $confirmationCode ): ValidationResponse {

$subscription = $this->subscriptionRepository->findByConfirmationCode( $confirmationCode );

if ( $subscription === null ) {
Expand All @@ -47,4 +46,4 @@ public function confirmSubscription( string $confirmationCode ): ValidationRespo
] );
}

}
}
8 changes: 4 additions & 4 deletions src/Validation/SubscriptionDuplicateValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
use WMDE\FunValidators\ValidationResult;

/**
* @license GNU GPL v2+
* @license GPL-2.0-or-later
* @author Gabriel Birke < [email protected] >
*/
class SubscriptionDuplicateValidator {

const SOURCE_NAME = 'subscription_duplicate_subscription';
public const SOURCE_NAME = 'subscription_duplicate_subscription';

private $repository;
private $cutoffDateTime;
private SubscriptionRepository $repository;
private \DateTime $cutoffDateTime;

public function __construct( SubscriptionRepository $repository, \DateTime $cutoffDateTime ) {
$this->repository = $repository;
Expand Down
4 changes: 2 additions & 2 deletions src/Validation/SubscriptionValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use WMDE\FunValidators\Validators\RequiredFieldValidator;

/**
* @license GNU GPL v2+
* @license GPL-2.0-or-later
* @author Gabriel Birke < [email protected] >
*/
class SubscriptionValidator {
Expand Down Expand Up @@ -49,4 +49,4 @@ private function getRequiredFieldViolations( Subscription $subscription ): array
];
}

}
}
Loading

0 comments on commit 0589bf7

Please sign in to comment.