Skip to content

Commit

Permalink
Add phpcs to build stages
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Mar 5, 2018
1 parent 35344aa commit fed7512
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ tests/PersistentCollections/*
phpunit.xml
composer.lock
vendor/
.phpcs-cache
phpcs.xml
10 changes: 8 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,17 @@ jobs:
- composer update --prefer-lowest

- stage: Code Quality
php: 7.2
env: SERVER_VERSION="3.6" KEY_ID="2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5"
php: 7.1
env: STATIC_ANALYSIS SERVER_VERSION="3.6" KEY_ID="2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5"
script:
- vendor/bin/phpstan analyse -l 1 lib

- stage: Code Quality
php: 7.1
env: CODING_STANDARDS SERVER_VERSION="3.6" KEY_ID="2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5"
script:
- vendor/bin/phpcs

before_install:
- mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{,.disabled} || echo "xdebug not available"
- sudo apt-key adv --keyserver ${KEY_SERVER} --recv ${KEY_ID}
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"require-dev": {
"phpunit/phpunit": "^7.0",
"jmikola/geojson": "^1.0",
"phpstan/phpstan": "^0.9.2"
"phpstan/phpstan": "^0.9.2",
"doctrine/coding-standard": "^4.0"
},
"autoload": {
"psr-0": { "Doctrine\\ODM\\MongoDB": "lib/" }
Expand Down
80 changes: 80 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0"?>
<ruleset>
<arg name="basepath" value="."/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors" />

<!-- Ignore warnings and show progress of the run -->
<arg value="np"/>

<file>lib</file>
<file>tests</file>
<file>tools</file>

<exclude-pattern>tests/Proxies*</exclude-pattern>
<exclude-pattern>tests/Hydrators*</exclude-pattern>
<exclude-pattern>tests/PersistentCollections*</exclude-pattern>

<rule ref="Doctrine">
<!-- Traversable type hints often end up as mixed[], so we skip them for now -->
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversablePropertyTypeHintSpecification" />
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableParameterTypeHintSpecification" />
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification" />

<!-- Will cause BC breaks to method signatures - disabled for now -->
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint" />
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint" />

<exclude name="Generic.Formatting.MultipleStatementAlignment" />

<!-- Disabled due to the large number of false positives in 4.4.4 -->
<exclude name="SlevomatCodingStandard.Namespaces.UnusedUses.MismatchingCaseSensitivity" />

<!-- Disabled to avoid class renaming - to be handled in a separate PR -->
<exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming" />
<exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming" />
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming" />

<!-- The following rules are intended to be enabled one-by-one to have reviewable diffs -->

<exclude name="Generic.CodeAnalysis.EmptyStatement.DetectedFOREACH" />
<exclude name="Generic.CodeAnalysis.EmptyStatement.DetectedIF" />
<exclude name="Generic.NamingConventions.UpperCaseConstantName.ConstantNotUpperCase" />
<exclude name="Generic.PHP.ForbiddenFunctions.Found" />
<exclude name="Generic.PHP.ForbiddenFunctions.FoundWithAlternative" />
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" />
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps" />
<exclude name="PSR2.ControlStructures.SwitchDeclaration.WrongOpenercase" />
<exclude name="SlevomatCodingStandard.Commenting.RequireOneLinePropertyDocComment" />
<exclude name="SlevomatCodingStandard.ControlStructures.AssignmentInCondition.AssignmentInCondition" />
<exclude name="SlevomatCodingStandard.ControlStructures.EarlyExit" />
<exclude name="SlevomatCodingStandard.Classes.UnusedPrivateElements.UnusedMethod" />
<exclude name="SlevomatCodingStandard.Classes.UnusedPrivateElements.UnusedProperty" />
<exclude name="SlevomatCodingStandard.Classes.UnusedPrivateElements.WriteOnlyProperty" />
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingPropertyTypeHint" />
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" />
<exclude name="Squiz.Commenting.FunctionComment.ThrowsNotCapital" />
<exclude name="Squiz.Commenting.FunctionComment.ThrowsNoFullStop" />
<exclude name="Squiz.Commenting.FunctionComment.WrongStyle" />
<exclude name="Squiz.Classes.ClassFileName.NoMatch" />
<exclude name="Squiz.Scope.MethodScope.Missing" />
<exclude name="Squiz.Strings.DoubleQuoteUsage.ContainsVar" />
</rule>

<!-- Require no space around colon in return types -->
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing">
<properties>
<property name="spacesCountBeforeColon" value="0"/>
</properties>
</rule>

<rule ref="Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase">
<exclude-pattern>lib/Doctrine/ODM/MongoDB/Events.php</exclude-pattern>
</rule>

<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>
</ruleset>

0 comments on commit fed7512

Please sign in to comment.