jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/389953 )
Change subject: Clean up and slightly update .phpcs.xml rule set ...................................................................... Clean up and slightly update .phpcs.xml rule set * Use tab indention. * Add the sniff that disallows double quotes. * Replace now disallowed double quotes in the code. * Remove duplicates from the rule set that are already in the MediaWiki base rule set. * Remove duplicates from the exclude section on top. * Remove the useless name. It tends to be copy pasted, but doesn't serve a purpose. Change-Id: I96276c0ca59c60928459174888df405f5476d0ec --- M .phpcs.xml M src/JsonLdRdfWriter.php M tests/phpunit/JsonLdRdfWriterTest.php M tests/phpunit/RdfWriterTestBase.php 4 files changed, 58 insertions(+), 70 deletions(-) Approvals: Legoktm: Looks good to me, approved jenkins-bot: Verified diff --git a/.phpcs.xml b/.phpcs.xml index 31c2591..0fa259d 100644 --- a/.phpcs.xml +++ b/.phpcs.xml @@ -1,62 +1,50 @@ <?xml version="1.0"?> -<ruleset name="Purtle"> - <!-- See https://github.com/wikimedia/mediawiki-tools-codesniffer/blob/master/MediaWiki/ruleset.xml --> - <rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki"> +<ruleset> + <!-- See https://github.com/wikimedia/mediawiki-tools-codesniffer/blob/master/MediaWiki/ruleset.xml --> + <rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki"> <exclude name="MediaWiki.Commenting.FunctionComment.MissingDocumentationProtected" /> <exclude name="MediaWiki.Commenting.FunctionComment.MissingDocumentationPublic" /> <exclude name="MediaWiki.Commenting.FunctionComment.MissingParamComment" /> - <exclude name="MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment" /> - <exclude name="MediaWiki.Commenting.FunctionComment" /> - <exclude name="MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment" /> - </rule> + <exclude name="MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment" /> + </rule> - <rule ref="Generic.Files.InlineHTML" /> - <rule ref="Generic.Files.OneClassPerFile" /> - <rule ref="Generic.Files.OneInterfacePerFile" /> - <rule ref="Generic.Files.OneTraitPerFile" /> + <rule ref="Generic.Files.InlineHTML" /> - <rule ref="Generic.Metrics.CyclomaticComplexity"> - <exclude-pattern>RdfWriterFactory\.php</exclude-pattern> - </rule> - <rule ref="Generic.Metrics.NestingLevel" /> + <rule ref="Generic.Metrics.CyclomaticComplexity"> + <exclude-pattern>RdfWriterFactory\.php</exclude-pattern> + </rule> + <rule ref="Generic.Metrics.NestingLevel" /> - <rule ref="Generic.PHP.CharacterBeforePHPOpeningTag" /> + <rule ref="MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName"> + <!-- Exclude test methods like "testGivenInvalidInput_methodThrowsException". --> + <exclude-pattern>tests/phpunit/*Test*\.php</exclude-pattern> + </rule> - <rule ref="MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName"> - <!-- Exclude test methods like "testGivenInvalidInput_methodThrowsException". --> - <exclude-pattern>tests/phpunit/*Test*\.php</exclude-pattern> - </rule> + <rule ref="PSR1" /> + <rule ref="PSR1.Files.SideEffects.FoundWithSymbols"> + <exclude-pattern>Purtle\.php</exclude-pattern> + </rule> + <rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps"> + <!-- Exclude test methods like "testGivenInvalidInput_methodThrowsException". --> + <exclude-pattern>tests/phpunit/*Test*\.php</exclude-pattern> + </rule> - <rule ref="PSR1" /> - <rule ref="PSR1.Files.SideEffects.FoundWithSymbols"> - <exclude-pattern>Purtle\.php</exclude-pattern> - </rule> - <rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps"> - <!-- Exclude test methods like "testGivenInvalidInput_methodThrowsException". --> - <exclude-pattern>tests/phpunit/*Test*\.php</exclude-pattern> - </rule> + <rule ref="PSR2.Files" /> - <rule ref="PSR2.Files" /> - - <rule ref="Squiz.Classes.SelfMemberReference" /> <rule ref="Squiz.ControlStructures.ControlSignature" /> - <rule ref="Squiz.Functions.FunctionDuplicateArgument" /> - <rule ref="Squiz.Functions.GlobalFunction" /> - <rule ref="Squiz.Scope" /> - - <rule ref="Squiz.WhiteSpace.FunctionSpacing"> - <properties> - <property name="spacing" value="1" /> - </properties> - </rule> - <rule ref="Squiz.WhiteSpace.OperatorSpacing"> - <properties> - <property name="ignoreNewlines" value="true" /> - </properties> - </rule> + <rule ref="Squiz.Functions.FunctionDuplicateArgument" /> + <rule ref="Squiz.Functions.GlobalFunction" /> + <rule ref="Squiz.Scope" /> + <rule ref="Squiz.Strings.DoubleQuoteUsage"> + <exclude name="Squiz.Strings.DoubleQuoteUsage.ContainsVar" /> + </rule> + <rule ref="Squiz.WhiteSpace.FunctionSpacing"> + <properties> + <property name="spacing" value="1" /> + </properties> + </rule> <file>.</file> <arg name="extensions" value="php" /> <arg name="encoding" value="utf8" /> - <exclude-pattern type="relative">^vendor/</exclude-pattern> </ruleset> diff --git a/src/JsonLdRdfWriter.php b/src/JsonLdRdfWriter.php index 21df20b..ac90f6c 100644 --- a/src/JsonLdRdfWriter.php +++ b/src/JsonLdRdfWriter.php @@ -91,7 +91,7 @@ * The type internally used for "default type", which is a string or * otherwise default-coerced type. */ - const DEFAULT_TYPE = "@purtle@default@"; + const DEFAULT_TYPE = '@purtle@default@'; /** * @param string $role @@ -201,9 +201,9 @@ // Prefixes get priority over field names in @context $pred = $this->compactify( $base, $local ); if ( !isset( $this->context[ $local ] ) ) { - $this->context[ $local ] = [ "@id" => $pred ]; + $this->context[ $local ] = [ '@id' => $pred ]; } - if ( $this->context[ $local ][ "@id" ] === $pred ) { + if ( $this->context[ $local ][ '@id' ] === $pred ) { return $local; } return $pred; @@ -245,7 +245,7 @@ // Write @context field. $this->write( ",\n" ); $this->write( $this->encode( [ - "@context" => $this->context + '@context' => $this->context ], 0 ) ); } @@ -281,7 +281,7 @@ */ protected function writeSubject( $base, $local = null ) { $this->predicates = [ - "@id" => $this->compactify( $base, $local ) + '@id' => $this->compactify( $base, $local ) ]; } @@ -305,8 +305,8 @@ protected function writeResource( $base, $local = null ) { $pred = $this->getCurrentTerm(); $value = $this->compactify( $base, $local ); - $this->addTypedValue( "@id", $value, [ - "@id" => $value + $this->addTypedValue( '@id', $value, [ + '@id' => $value ], ( $pred === self::RDF_TYPE_IRI ) ); } @@ -319,8 +319,8 @@ $this->addTypedValue( self::DEFAULT_TYPE, $text ); } else { $expanded = [ - "@language" => $language, - "@value" => $text + '@language' => $language, + '@value' => $text ]; $this->addTypedValue( self::DEFAULT_TYPE, $expanded, $expanded ); } @@ -366,8 +366,8 @@ $type = $this->compactify( $typeBase, $typeLocal ); $literal = strval( $literal ); $this->addTypedValue( $type, $literal, [ - "@type" => $type, - "@value" => $literal + '@type' => $type, + '@value' => $literal ] ); } @@ -394,7 +394,7 @@ if ( !$forceExpand ) { $pred = $this->getCurrentTerm(); if ( $type === self::DEFAULT_TYPE ) { - if ( !isset( $this->context[ $pred ][ "@type" ] ) ) { + if ( !isset( $this->context[ $pred ][ '@type' ] ) ) { $this->defaulted[ $pred ] = true; } if ( isset( $this->defaulted[ $pred ] ) ) { @@ -405,17 +405,17 @@ if ( !isset( $this->context[ $pred ] ) ) { $this->context[ $pred ] = []; } - if ( !isset( $this->context[ $pred ][ "@type" ] ) ) { - $this->context[ $pred ][ "@type" ] = $type; + if ( !isset( $this->context[ $pred ][ '@type' ] ) ) { + $this->context[ $pred ][ '@type' ] = $type; } - if ( $this->context[ $pred ][ "@type" ] === $type ) { + if ( $this->context[ $pred ][ '@type' ] === $type ) { $this->values[] = $simpleVal; return; } } } if ( $expandedVal === null ) { - $this->values[] = [ "@value" => $simpleVal ]; + $this->values[] = [ '@value' => $simpleVal ]; } else { $this->values[] = $expandedVal; } @@ -425,9 +425,9 @@ $name = $this->getCurrentTerm(); if ( $name === self::RDF_TYPE_IRI ) { - $name = "@type"; + $name = '@type'; $this->values = array_map( function ( array $val ) { - return $val[ "@id" ]; + return $val[ '@id' ]; }, $this->values ); } if ( isset( $this->predicates[$name] ) ) { @@ -443,7 +443,7 @@ $cnt = count( $this->values ); if ( $cnt === 0 ) { - throw new LogicException( "finishPredicate can't be called without at least one value" ); + throw new LogicException( 'finishPredicate can\'t be called without at least one value' ); } elseif ( $cnt === 1 ) { $this->predicates[$name] = $this->values[0]; } else { diff --git a/tests/phpunit/JsonLdRdfWriterTest.php b/tests/phpunit/JsonLdRdfWriterTest.php index 4120c73..4eaa3d0 100644 --- a/tests/phpunit/JsonLdRdfWriterTest.php +++ b/tests/phpunit/JsonLdRdfWriterTest.php @@ -33,11 +33,11 @@ public function testEncode() { $writer = new JsonLdRdfWriter(); - $this->assertEquals( $writer->encode( "foo{bar}bat", 0 ), '"foo{bar}bat"' ); - $this->assertEquals( $writer->encode( [], 0 ), "" ); + $this->assertEquals( $writer->encode( 'foo{bar}bat', 0 ), '"foo{bar}bat"' ); + $this->assertEquals( $writer->encode( [], 0 ), '' ); $this->assertEquals( $writer->encode( [ - "@id" => "foo" - ], 0 ), " \"@id\": \"foo\"" ); + '@id' => 'foo' + ], 0 ), ' "@id": "foo"' ); $this->assertEquals( $writer->encode( [ 1, 2, 3 ], 0 ), " 1,\n 2,\n 3" diff --git a/tests/phpunit/RdfWriterTestBase.php b/tests/phpunit/RdfWriterTestBase.php index 6ea3145..9bf0f83 100644 --- a/tests/phpunit/RdfWriterTestBase.php +++ b/tests/phpunit/RdfWriterTestBase.php @@ -343,7 +343,7 @@ $writer->prefix( 'cc', 'http://creativecommons.org/ns#' ); $writer->start(); $writer->about( 'wikibase', 'Dump' ) - ->a( 'schema', "Dataset" ) + ->a( 'schema', 'Dataset' ) ->a( 'owl', 'Ontology' ) ->say( 'cc', 'license' )->is( 'http://creativecommons.org/publicdomain/zero/1.0/' ) ->say( 'schema', 'softwareVersion' )->value( '0.1.0' ) -- To view, visit https://gerrit.wikimedia.org/r/389953 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I96276c0ca59c60928459174888df405f5476d0ec Gerrit-PatchSet: 2 Gerrit-Project: purtle Gerrit-Branch: master Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.kr...@wikimedia.de> Gerrit-Reviewer: C. Scott Ananian <canan...@wikimedia.org> Gerrit-Reviewer: Legoktm <lego...@member.fsf.org> Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.kr...@wikimedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits