Skip to content

Commit

Permalink
Merge pull request #877 from wmde/codestyle
Browse files Browse the repository at this point in the history
Codestyle verification
  • Loading branch information
gbirke authored May 5, 2017
2 parents 66eb01e + 730e993 commit 8ca72db
Show file tree
Hide file tree
Showing 37 changed files with 147 additions and 34 deletions.
12 changes: 6 additions & 6 deletions cli/ConfigValidation/ValidateConfigCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class ValidateConfigCommand extends Command {
const NAME = 'validate-config';
const DEFAULT_SCHEMA = __DIR__ . '/../../app/config/schema.json';
const ERROR_RETURN_CODE = 1;
const OK_RETURN_CODE = 0;

protected function configure()
{
protected function configure(): void {
$this->setName( self::NAME )
->setDescription( 'Validate configuration files' )
->setHelp( 'This command merges the specified configuration files and validates them against a JSON schema' )
Expand All @@ -50,8 +50,7 @@ protected function configure()
);
}

protected function execute( InputInterface $input, OutputInterface $output )
{
protected function execute( InputInterface $input, OutputInterface $output ): int {
$configObject = $this->loadConfigObjectFromFiles( $input->getArgument( 'config_file' ) );

if ( $input->getOption( 'dump-config' ) ) {
Expand All @@ -66,7 +65,7 @@ protected function execute( InputInterface $input, OutputInterface $output )
);

if ( $validator->passes() ) {
return null;
return self::OK_RETURN_CODE;
}

$renderer = new ValidationErrorRenderer( $schema );
Expand All @@ -78,8 +77,9 @@ protected function execute( InputInterface $input, OutputInterface $output )
}

/**
* @param array $configFiles
* @throws \RuntimeException
* @param array $configFiles
* @return \stdClass
*/
private function loadConfigObjectFromFiles( array $configFiles ): \stdClass {
$configReader = new ConfigReader(
Expand Down
2 changes: 1 addition & 1 deletion cli/FundraisingCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FundraisingCli {
*/
private $app;

public function newApplication() :Application {
public function newApplication(): Application {
$this->app = new Application();
$this->setApplicationInfo();
$this->registerCommands();
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@
"mikey179/vfsStream": "~1.6",
"wmde/psr-log-test-doubles": "~2.1",

"squizlabs/php_codesniffer": "~2.7",
"squizlabs/php_codesniffer": "~2.8",
"phpmd/phpmd": "~2.3",
"slevomat/coding-standard": "^2.3",

"symfony/browser-kit": "^3.2",
"silex/web-profiler": "~2.0",
Expand Down Expand Up @@ -116,7 +117,7 @@
"@validate-app-config"
],
"phpcs": [
"vendor/bin/phpcs src/ tests/ contexts/ cli/ --standard=phpcs.xml --extensions=php -sp"
"vendor/bin/phpcs"
],
"phpmd": [
"vendor/bin/phpmd src/ text phpmd.xml"
Expand Down
39 changes: 38 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions contexts/DonationContext/src/Validation/DonorValidator.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare( strict_types = 1 );

namespace WMDE\Fundraising\Frontend\DonationContext\Validation;

use WMDE\Fundraising\Frontend\DonationContext\Domain\Model\Donor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private function getAddressArray(): array {
];
}

private function getPaypalArray():array {
private function getPaypalArray(): array {
return [
'paypal_payer_id' => ValidPayPalNotificationRequest::PAYER_ID,
'paypal_subscr_id' => ValidPayPalNotificationRequest::SUBSCRIBER_ID,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

declare( strict_types = 1 );

namespace WMDE\Fundraising\Frontend\DonationContext\Tests\Integration\DataAccess;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

declare( strict_types = 1 );

namespace WMDE\Fundraising\Frontend\MembershipContext\Tests\Unit\UseCases\ApplyForMembership;

Expand Down
48 changes: 44 additions & 4 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
<?xml version="1.0"?>
<!--
- https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
- https://github.com/squizlabs/PHP_CodeSniffer/tree/master/CodeSniffer/Standards
- https://github.com/squizlabs/PHP_CodeSniffer/tree/master/src/Standards
-->
<ruleset name="FunFunFundraisingFrontend">

<file>src/</file>
<file>tests/</file>
<file>contexts/</file>
<file>cli/</file>

<arg name="extensions" value="php"/>
<arg value="s"/>
<arg value="p"/>

<!--<rule ref="vendor/mediawiki/mediawiki-codesniffer/MediaWiki/Sniffs/WhiteSpace">-->
<!--<exclude name="vendor/mediawiki/mediawiki-codesniffer/MediaWiki/Sniffs/WhiteSpace/SpaceBeforeSingleLineCommentSniff.php" />-->
<!--<exclude name="vendor/mediawiki/mediawiki-codesniffer/MediaWiki/Sniffs/WhiteSpace/SpaceyParenthesisSniff.php" />-->
<!--</rule>-->

<rule ref="Generic.Arrays.DisallowLongArraySyntax" />
Expand All @@ -32,8 +41,7 @@
<rule ref="Generic.Functions.CallTimePassByReference" />
<rule ref="Generic.Functions.FunctionCallArgumentSpacing" />

<!-- Does not yet work with PHP7 return types -->
<!--<rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie" />-->
<rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie" />

<rule ref="Generic.Metrics.NestingLevel">
<properties>
Expand Down Expand Up @@ -112,4 +120,36 @@
</rule>

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

<!-- 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/Namespaces/UseDoesNotStartWithBackslashSniff.php" />

<!-- 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.ContentAfterOpenBracket" />
<exclude name="PEAR.Functions.FunctionCallSignature.CloseBracketLine" />
</rule>
</ruleset>
6 changes: 3 additions & 3 deletions src/Factories/FunFunFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,10 @@ private function newPimple(): Container {
};

$pimple['content_page_selector'] = function () {
$json = (new SimpleFileFetcher())->fetchFile($this->getI18nDirectory() . '/data/pages.json');
$config = json_decode($json, true) ?? [];
$json = (new SimpleFileFetcher())->fetchFile( $this->getI18nDirectory() . '/data/pages.json' );
$config = json_decode( $json, true ) ?? [];

return new PageSelector($config);
return new PageSelector( $config );
};

$pimple['content_provider'] = function () {
Expand Down
6 changes: 3 additions & 3 deletions src/Factories/TwigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ class TwigFactory {
private $cachePath;
private $locale;

public function __construct(array $config, string $cachePath, string $locale) {
public function __construct( array $config, string $cachePath, string $locale ) {
$this->config = $config;
$this->cachePath = $cachePath;
$this->locale = $locale;
}

public function newFileSystemLoader(): ? Twig_Loader_Filesystem {
public function newFileSystemLoader(): ?Twig_Loader_Filesystem {
if ( empty( $this->config['loaders']['filesystem'] ) ) {
return null;
}
Expand Down Expand Up @@ -84,6 +84,6 @@ public function newFilePrefixFilter( FilePrefixer $filePrefixer ) {
}

public function newTwigEnvironmentConfigurator() {
return new TwigEnvironmentConfigurator($this->config, $this->cachePath);
return new TwigEnvironmentConfigurator( $this->config, $this->cachePath );
}
}
2 changes: 2 additions & 0 deletions src/Infrastructure/PiwikEvents.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare( strict_types = 1 );

namespace WMDE\Fundraising\Frontend\Infrastructure;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Infrastructure/PiwikVariableCollector.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare( strict_types = 1 );

namespace WMDE\Fundraising\Frontend\Infrastructure;

use WMDE\Fundraising\Frontend\DonationContext\Domain\Model\Donation;
Expand Down
2 changes: 1 addition & 1 deletion src/Presentation/ContentPage/ContentNotFoundException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare( strict_types=1 );
declare( strict_types = 1 );

namespace WMDE\Fundraising\Frontend\Presentation\ContentPage;

Expand Down
2 changes: 1 addition & 1 deletion src/Presentation/ContentPage/PageNotFoundException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare( strict_types=1 );
declare( strict_types = 1 );

namespace WMDE\Fundraising\Frontend\Presentation\ContentPage;

Expand Down
2 changes: 1 addition & 1 deletion src/Presentation/ContentPage/PageSelector.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare( strict_types=1 );
declare( strict_types = 1 );

namespace WMDE\Fundraising\Frontend\Presentation\ContentPage;

Expand Down
2 changes: 2 additions & 0 deletions src/Presentation/DonationConfirmationPageSelector.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare( strict_types = 1 );

namespace WMDE\Fundraising\Frontend\Presentation;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Presentation/Presenters/CancelDonationHtmlPresenter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare( strict_types = 1 );

namespace WMDE\Fundraising\Frontend\Presentation\Presenters;

use WMDE\Fundraising\Frontend\DonationContext\UseCases\CancelDonation\CancelDonationResponse;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare( strict_types = 1 );

namespace WMDE\Fundraising\Frontend\Presentation\Presenters;

use WMDE\Fundraising\Frontend\MembershipContext\UseCases\CancelMembershipApplication\CancellationResponse;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare( strict_types = 1 );

namespace WMDE\Fundraising\Frontend\Presentation\Presenters;

use Symfony\Component\Translation\Translator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare( strict_types = 1 );

namespace WMDE\Fundraising\Frontend\Presentation\Presenters;

use WMDE\Fundraising\Frontend\DonationContext\Domain\Model\Donation;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare( strict_types = 1 );

namespace WMDE\Fundraising\Frontend\Presentation\Presenters;

use WMDE\Fundraising\Frontend\MembershipContext\Domain\Model\Applicant;
Expand Down
2 changes: 2 additions & 0 deletions src/Presentation/SelectedConfirmationPage.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare( strict_types = 1 );

namespace WMDE\Fundraising\Frontend\Presentation;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Presentation/TemplateTestCampaign.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare( strict_types = 1 );

namespace WMDE\Fundraising\Frontend\Presentation;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Presentation/TwigEnvironmentConfigurator.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare( strict_types=1 );
declare( strict_types = 1 );

namespace WMDE\Fundraising\Frontend\Presentation;

Expand Down
2 changes: 1 addition & 1 deletion src/Validation/TextPolicyValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private function getMatches( string $text, array $wordArray ): array {
return $matches[0];
}

private function hasBadWordNotMatchingWhiteWords( array $badMatches, array $whiteMatches ):bool {
private function hasBadWordNotMatchingWhiteWords( array $badMatches, array $whiteMatches ): bool {
return count(
array_udiff( $badMatches, $whiteMatches, function( $badMatch, $whiteMatch ) {
return !preg_match( $this->composeRegex( [ preg_quote( $badMatch, '#' ) ] ), $whiteMatch );
Expand Down
2 changes: 1 addition & 1 deletion tests/EdgeToEdge/TranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TranslatorTest extends WebRouteTestCase {
public function testGivenDefinedMessageKey_responseContainsTranslatedMessages() {
$client = $this->createClient(
[],
function (FunFunFactory $factory) {
function ( FunFunFactory $factory ) {
$factory->setTranslator( $this->newTranslator( [ 'page_not_found' => 'Seite nicht gefunden' ], 'de' ) );
}
);
Expand Down
Loading

0 comments on commit 8ca72db

Please sign in to comment.