Skip to content

Commit

Permalink
Add PHPCS, PHPMD and coverage tag validation
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenDeDauw committed Nov 8, 2015
1 parent 909c783 commit 1697a65
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 4 deletions.
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ php:
- 7
- hhvm

sudo: false

install: travis_retry composer install

before_script: composer install --prefer-source

script: phpunit
script: composer ci

cache:
directories:
- $HOME/.composer/cache
30 changes: 29 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
"Wikibase",
"Wikidata",
"Dump",
"JSON"
"JSON",
"bz2"
],
"homepage": "https://github.com/JeroenDeDauw/JsonDumpReader",
"license": "GPL-2.0+",
"authors": [
{
Expand All @@ -19,6 +21,11 @@
"wikibase/data-model-serialization": "~1.1|~2.0"
},
"require-dev": {
"whatthejeff/nyancat-phpunit-resultprinter": "~1.2",
"ockcyp/covers-validator": "~0.2.0",
"squizlabs/php_codesniffer": "~2.3",
"phpmd/phpmd": "~2.3",

"data-values/iri": "~0.1",
"data-values/number": "~0.1",
"data-values/geo": "~1.0",
Expand All @@ -35,5 +42,26 @@
"branch-alias": {
"dev-master": "0.2.x-dev"
}
},
"scripts": {
"test": [
"composer validate --no-interaction",
"phpunit",
"vendor/bin/covers-validator"
],
"cs": [
"composer phpcs",
"composer phpmd"
],
"ci": [
"composer test",
"composer cs"
],
"phpcs": [
"vendor/bin/phpcs src/* tests/* --standard=phpcs.xml --extensions=php -sp"
],
"phpmd": [
"vendor/bin/phpmd src/,tests/ text phpmd.xml"
]
}
}
101 changes: 101 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0"?>
<!--
- https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
- https://github.com/squizlabs/PHP_CodeSniffer/tree/master/CodeSniffer/Standards
-->
<ruleset name="Replicator">
<rule ref="Generic.Classes" />
<rule ref="Generic.CodeAnalysis" />
<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter.Found">
<severity>0</severity>
</rule>
<rule ref="Generic.PHP.NoSilencedErrors.Discouraged">
<severity>0</severity>
</rule>

<rule ref="Generic.ControlStructures" />

<rule ref="Generic.Files.ByteOrderMark" />
<rule ref="Generic.Files.LineEndings" />
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="125" />
<property name="absoluteLineLimit" value="125" />
</properties>
</rule>
<rule ref="Generic.Files.OneClassPerFile" />

<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" />
<rule ref="Generic.NamingConventions.CamelCapsFunctionName.ScopeNotCamelCaps">
<severity>0</severity>
</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.NoSilencedErrors" />
<rule ref="Generic.PHP.SAPIUsage" />

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

<rule ref="PSR1" />
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
<severity>0</severity>
</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.WhiteSpace.CastSpacing" />
<rule ref="Squiz.WhiteSpace.LanguageConstructSpacing" />
<rule ref="Squiz.WhiteSpace.LogicalOperatorSpacing" />

<rule ref="Squiz.WhiteSpace.OperatorSpacing">
<properties>
<property name="ignoreNewlines" value="true" />
</properties>
</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" />
</ruleset>
39 changes: 39 additions & 0 deletions phpmd.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0"?>
<ruleset xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation=" http://pmd.sf.net/ruleset_xml_schema.xsd">


<rule ref="rulesets/codesize.xml">
<exclude name="TooManyPublicMethods" />
</rule>
<rule ref="rulesets/codesize.xml/TooManyPublicMethods">
<properties>
<property name="ignorepattern" value="(^(set|get|test))i" />
</properties>
</rule>

<rule ref="rulesets/controversial.xml">
<exclude name="CamelCaseMethodName" />
</rule>
<rule ref="rulesets/controversial.xml/CamelCaseMethodName">
<properties>
<property name="allow-underscore-test" value="true" />
</properties>
</rule>

<rule ref="rulesets/design.xml">
<exclude name="CouplingBetweenObjects" />
</rule>

<rule ref="rulesets/naming.xml">
<exclude name="ShortVariable" />
<exclude name="LongVariable" />
</rule>

<rule ref="rulesets/unusedcode.xml">
<exclude name="UnusedLocalVariable" />
<exclude name="UnusedFormalParameter" />
</rule>
</ruleset>
4 changes: 3 additions & 1 deletion src/JsonDumpIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ public function next() {
private function getNextFromJson() {
do {
$json = $this->dumpReader->nextJsonLine();
if ( $json === null ) return null;
if ( $json === null ) {
return null;
}

$data = json_decode( $json, true );
if ( $data === null ) {
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
die( 'You need to install this package with Composer before you can run the tests' );
}

require_once( __DIR__ . '/../vendor/autoload.php' );
require __DIR__ . '/../vendor/autoload.php';

0 comments on commit 1697a65

Please sign in to comment.