From 5515deb47810365aa2fc51406cd8905d307e6fa3 Mon Sep 17 00:00:00 2001 From: Marko Ilic Date: Mon, 10 Jun 2024 11:24:50 +0200 Subject: [PATCH] Update and fix composer.json, clear sniffs warnings and errors (#836) * update require-dev dependencies inside composer.json * update scripts part inside composer.jos, make phpcs, fix and lint working * chore (build): add composer fix command to makefile * remove exclude-pattern tab from phpcs configuration * fix sniff MediaWiki.WhiteSpace.SpaceyParenthesis reported by phpcs * fix sniff MediaWiki.WhiteSpace.MultipleEmptyLines reported by phpcs * fix sniff Squiz.WhiteSpace.FunctionOpeningBraceSpace reported by phpcs * fix (composer): exclude extensions from phpcs and lint * fix sniff MediaWiki.Commenting.FunctionComment reported by phpcs * fix sniff Universal.WhiteSpace.CommaSpacing reported by phpcs * fix sniff Squiz.WhiteSpace.SuperfluousWhitespace reported by phpcs * fix sniff PSR2.ControlStructures.SwitchDeclaration reported by phpcs * fix sniff MediaWiki.PHPUnit.MockBoilerplate reported by phpcs * fix sniff Generic.Files.LineEndings reported by phpcs * fix sniff PSR2.Files.EndFileNewline reported by phpcs * fix sniff Squiz.ControlStructures.ControlSignature reported by phpcs * fix sniff Squiz.Classes.SelfMemberReference reported by phpcs * fix sniff MediaWiki.Commenting.PhpunitAnnotations reported by phpcs * fix sniff Generic.WhiteSpace.DisallowSpaceIndent reported by phpcs * fix sniff MediaWiki.Commenting.RedundantVarName reported by phpcs * fix sniff MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment reported by phpcs * fix sniff Generic.Functions.OpeningFunctionBraceKernighanRitchie reported by phpcs * fix sniff MediaWiki.Commenting.DocComment reported by phpcs * fix sniff MediaWiki.Commenting.FunctionComment.ParamNameNoMatch reported by phpcs * fix sniff MediaWiki.Commenting.FunctionComment.SpacingAfter reported by phpcs * fix sniff MediaWiki.Commenting.FunctionComment.WrongStyle reported by phpcs * fix sniff Squiz.Scope.MethodScope.Missing reported by phpcs * fix sniff Generic.ControlStructures.InlineControlStructure.NotAllowed reported by phpcs * fix sniff Generic.CodeAnalysis.AssignmentInCondition.Found reported by phpcs * fix sniff MediaWiki.Commenting.PropertyDocumentation.MissingVarType reported by phpcs * reverse the changes for Generic.CodeAnalysis.AssignmentInCondition.Found, exclude them * fix sniff Generic.WhiteSpace.ScopeIndent.Incorrect reported by phpcs * fix sniff Universal.Lists.DisallowLongListSyntax reported by phpcs * fix sniff MediaWiki.Commenting.FunctionAnnotations.UnrecognizedAnnotation reported by phpcs * fix sniff Generic.PHP.LowerCaseKeyword.Found reported by phpcs * fix sniff MediaWiki.Commenting.MissingCovers.MissingCovers reported by phpcs * fix sniff MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment reported by phpcs * fix sniff MediaWiki.Commenting.PhpunitAnnotations.NotClass reported by phpcs * fix sniff MediaWiki.Usage.ExtendClassUsage.FunctionConfigUsage reported by phpcs * fix sniff Squiz.Operators.ValidLogicalOperators.NotAllowed reported by phpcs * reverse previous commit * fix sniff MediaWiki.Commenting.FunctionComment.ParamNameNoCaseMatch reported by phpcs * fix sniff Squiz.ControlStructures.ControlSignature.SpaceAfterCloseBrace reported by phpcs * fix sniff Generic.WhiteSpace.ScopeIndent.IncorrectExact reported by phpcs * fix sniff PSR2.Classes.PropertyDeclaration.Multiple reported by phpcs * fix sniff MediaWiki.Commenting.DocComment.SyntaxAlignedDocClose reported by phpcs * fix sniff PSR2.ControlStructures.ElseIfDeclaration.NotAllowed reported by phpcs * fix sniff Generic.Arrays.DisallowLongArraySyntax.Found reported by phpcs * fix sniff MediaWiki.Commenting.FunctionComment.ExtraParamComment reported by phpcs * fix sniff Squiz.PHP.NonExecutableCode.Unreachable reported by phpcs * fix sniff MediaWiki.Commenting.FunctionComment.MissingReturnType reported by phpcs * fix sniff PSR2.ControlStructures.SwitchDeclaration.TerminatingComment reported by phpcs * fix sniff MediaWiki.Commenting.PropertyDocumentation.TypeTypeHintVar reported by phpcs * fix sniff PSR2.ControlStructures.SwitchDeclaration.WrongOpenercase reported by phpcs * fix sniff MediaWiki.Commenting.LicenseComment.LicenceTag reported by phpcs * fix sniff PSR2.Namespaces.NamespaceDeclaration.BlankLineAfter reported by phpcs * fix sniff MediaWiki.Usage.StaticClosure.StaticClosure reported by phpcs * fix sniff MediaWiki.VariableAnalysis.UnusedGlobalVariables.UnusedGlobal$smwgQMaxLimit reported by phpcs * fix sniff Squiz.WhiteSpace.OperatorSpacing.SpacingAfter reported by phpcs * fix sniff MediaWiki.WhiteSpace.SpaceAfterClosure.NoWhitespaceAfterClosure reported by phpcs * fix sniff Squiz.WhiteSpace.SemicolonSpacing.Incorrect reported by phpcs * fix sniff Squiz.WhiteSpace.OperatorSpacing.SpacingBefore reported by phpcs * fix sniff MediaWiki.Usage.DeprecatedGlobalVariables.Deprecated$wgTitle reported by phpcs * fix sniff Universal.UseStatements.NoUselessAliases.Found reported by phpcs * fix sniff MediaWiki.WhiteSpace.SpaceBeforeClassBrace.NoSpaceBeforeBrace reported by phpcs * fix sniff MediaWiki.NamingConventions.ValidGlobalName.allowedPrefix reported by phpcs * fix sniff MediaWiki.Commenting.FunctionComment.MissingParamName reported by phpcs * fix sniff MediaWiki.Usage.DeprecatedGlobalVariables.Deprecated$wgContLang reported by phpcs * fix sniff MediaWiki.Classes.UnusedUseStatement.UnusedUse reported by phpcs * fix sniff MediaWiki.Classes.UnsortedUseStatements.UnsortedUse reported by phpc * fix sniff PSR12.Properties.ConstantVisibility.NotFound reported by phpcs * add exclude and rule tags to phpcs.xml --- .phpcs.xml | 24 +- DefaultSettings.php | 5 +- Resources.php | 4 +- SemanticResultFormats.parser.php | 30 +- SemanticResultFormats.php | 4 +- SemanticResultFormats.utils.php | 2 +- build | 2 +- composer.json | 33 +- formats/Exhibit/SRF_Exhibit.php | 108 +++-- formats/Gantt/src/Gantt.php | 1 - formats/Gantt/src/GanttSection.php | 5 +- formats/JitGraph/SRF_JitGraph.php | 40 +- formats/Prolog/PrologPrinter.php | 371 +++++++++--------- formats/array/SRF_Array.php | 104 ++--- formats/array/SRF_Hash.php | 13 +- formats/calendar/SRFC_HistoricalDate.php | 10 +- formats/calendar/SRF_Calendar.php | 26 +- formats/carousel/Carousel.php | 61 ++- formats/d3/SRF_D3Chart.php | 2 +- formats/dataframe/DataframePrinter.php | 361 +++++++++-------- formats/datatables/Api.php | 57 +-- formats/datatables/DataTables.php | 103 +++-- formats/datatables/Hooks.php | 17 +- formats/datatables/SearchPanes.php | 89 ++--- formats/dygraphs/SRF_Dygraphs.php | 6 +- formats/filtered/src/Filtered.php | 10 +- .../filtered/src/Filters/DistanceFilter.php | 9 +- formats/filtered/src/Filters/NumberFilter.php | 4 +- formats/filtered/src/ResultItem.php | 10 +- formats/filtered/src/View/CalendarView.php | 4 +- formats/filtered/src/View/ListView.php | 30 +- formats/filtered/src/View/MapView.php | 6 +- formats/filtered/src/View/TableView.php | 4 +- formats/filtered/src/View/View.php | 6 +- formats/gallery/Gallery.php | 35 +- formats/googlecharts/SRF_GoogleBar.php | 19 +- formats/googlecharts/SRF_GooglePie.php | 3 +- formats/graphviz/SRF_Process.php | 161 ++++---- formats/incoming/SRF_Incoming.php | 2 +- formats/jqplot/SRF_jqPlot.php | 5 +- formats/jqplot/SRF_jqPlotSeries.php | 12 +- formats/math/SRF_Math.php | 31 +- formats/media/MediaPlayer.php | 10 +- formats/slideshow/SRF_SlideShowApi.php | 4 +- formats/spreadsheet/SpreadsheetPrinter.php | 4 +- formats/tagcloud/TagCloud.php | 12 +- formats/time/SRF_Time.php | 6 +- formats/timeline/SRF_Timeline.php | 83 ++-- formats/timeseries/SRF_Timeseries.php | 16 +- formats/tree/TreeNodeVisitor.php | 2 +- formats/tree/TreeResultPrinter.php | 3 +- formats/valuerank/SRF_ValueRank.php | 3 +- formats/widget/SRF_ListWidget.php | 1 - src/BibTex/BibTexFileExportPrinter.php | 11 +- src/BibTex/Item.php | 5 +- src/Graph/GraphFormatter.php | 25 +- src/Graph/GraphNode.php | 2 +- src/Graph/GraphOptions.php | 2 +- src/Graph/GraphPrinter.php | 17 +- src/Outline/ListTreeBuilder.php | 15 +- src/Outline/OutlineItem.php | 10 +- src/Outline/OutlineTree.php | 6 - src/Outline/TemplateBuilder.php | 11 +- src/ResourceFormatter.php | 11 +- src/iCalendar/IcalFormatter.php | 3 - src/iCalendar/IcalTimezoneFormatter.php | 3 +- src/iCalendar/iCalendarFileExportPrinter.php | 11 +- src/vCard/Email.php | 3 +- src/vCard/Tel.php | 6 +- src/vCard/vCard.php | 2 +- src/vCard/vCardFileExportPrinter.php | 4 +- .../Integration/I18nJsonFileIntegrityTest.php | 1 + .../JsonTestCaseScriptRunnerTest.php | 2 +- tests/phpunit/Integration/ResourcesTest.php | 6 +- .../BibTex/BibTexFileExportPrinterTest.php | 8 +- .../phpunit/Unit/Filtered/ResultItemTest.php | 2 +- tests/phpunit/Unit/Formats/GalleryTest.php | 20 +- tests/phpunit/Unit/Formats/PrologTest.php | 60 +-- .../phpunit/Unit/Formats/SpreadsheetTest.php | 10 +- tests/phpunit/Unit/Formats/TreeTest.php | 7 +- tests/phpunit/Unit/Formats/ValueRankTest.php | 3 + .../phpunit/Unit/Graph/GraphFormatterTest.php | 22 +- tests/phpunit/Unit/Graph/GraphNodeTest.php | 1 - .../Unit/Outline/OutlineResultPrinterTest.php | 22 +- .../phpunit/Unit/iCalendar/DateParserTest.php | 10 +- .../Unit/vCard/vCardFileExportPrinterTest.php | 8 +- 86 files changed, 1205 insertions(+), 1097 deletions(-) diff --git a/.phpcs.xml b/.phpcs.xml index 51fb5e835..10f250a27 100644 --- a/.phpcs.xml +++ b/.phpcs.xml @@ -6,16 +6,34 @@ - - + + + + + + + + + + + + + + + + + + 0 + . - /(vendor|conf|extensions)/ + /(vendor|conf)/ + extensions/* diff --git a/DefaultSettings.php b/DefaultSettings.php index 31bb3d76b..c3b762fab 100644 --- a/DefaultSettings.php +++ b/DefaultSettings.php @@ -91,9 +91,10 @@ // Load hash format only if HashTables extension is initialised, otherwise 'Array' format is enough // FIXME: According to the INSTALL file only formats should be enabled, that "do not require further software to be installed (besides SMW)" +// Version < 1.0 alpha if ( isset( $GLOBALS['wgAutoloadClasses']['ExtHashTables'] ) && defined( 'ExtHashTables::VERSION' ) && version_compare( ExtHashTables::VERSION, '0.999', '>=' ) - || isset( $GLOBALS['wgHashTables'] ) // Version < 1.0 alpha + || isset( $GLOBALS['wgHashTables'] ) ) { $GLOBALS['srfgFormats'][] = 'hash'; } @@ -136,7 +137,7 @@ 'cc210', 'cc252', 'cc267', - 'cc294' , + 'cc294', 'cc303', 'cc327', 'ylgn', diff --git a/Resources.php b/Resources.php index 8fa5a6638..a204dff65 100644 --- a/Resources.php +++ b/Resources.php @@ -11,7 +11,7 @@ */ $moduleTemplate = [ - 'localBasePath' => __DIR__ , + 'localBasePath' => __DIR__, 'remoteExtPath' => 'SemanticResultFormats' ]; @@ -1017,7 +1017,7 @@ 'ext.srf.datatables.v2.module' => $moduleTemplate + [ 'scripts' => [ - 'resources/jquery/datatables/object_hash.js', + 'resources/jquery/datatables/object_hash.js', 'resources/jquery/datatables/jquery.mark.min.js', 'resources/jquery/datatables/datatables.mark.min.js', 'resources/jquery/datatables/datatables.min.js', diff --git a/SemanticResultFormats.parser.php b/SemanticResultFormats.parser.php index 207a11011..3ab687a08 100644 --- a/SemanticResultFormats.parser.php +++ b/SemanticResultFormats.parser.php @@ -15,24 +15,26 @@ */ class SRFParserFunctions { - static function registerFunctions( &$parser ) { + public static function registerFunctions( &$parser ) { $parser->setFunctionHook( 'calendarstartdate', [ 'SRFParserFunctions', 'runCalendarStartDate' ] ); $parser->setFunctionHook( 'calendarenddate', [ 'SRFParserFunctions', 'runCalendarEndDate' ] ); return true; } - static function runCalendarStartDate( &$parser, $calendar_type = 'month', $calendar_start_day = null, $calendar_days = 7, $default_year = null, $default_month = null, $default_day = null ) { - if ( $calendar_type == '' ) { $calendar_type = 'month'; + public static function runCalendarStartDate( &$parser, $calendar_type = 'month', $calendar_start_day = null, $calendar_days = 7, $default_year = null, $default_month = null, $default_day = null ) { + if ( $calendar_type == '' ) { + $calendar_type = 'month'; } - list( $lower_date, $upper_date, $query_date ) = + [ $lower_date, $upper_date, $query_date ] = self::getBoundaryDates( $calendar_type, $calendar_start_day, $calendar_days, $default_year, $default_month, $default_day ); return date( "Y", $lower_date ) . '-' . date( "m", $lower_date ) . '-' . date( "d", $lower_date ); } - static function runCalendarEndDate( &$parser, $calendar_type = 'month', $calendar_start_day = null, $calendar_days = 7, $default_year = null, $default_month = null, $default_day = null ) { - if ( $calendar_type == '' ) { $calendar_type = 'month'; + public static function runCalendarEndDate( &$parser, $calendar_type = 'month', $calendar_start_day = null, $calendar_days = 7, $default_year = null, $default_month = null, $default_day = null ) { + if ( $calendar_type == '' ) { + $calendar_type = 'month'; } - list( $lower_date, $upper_date, $query_date ) = + [ $lower_date, $upper_date, $query_date ] = self::getBoundaryDates( $calendar_type, $calendar_start_day, $calendar_days, $default_year, $default_month, $default_day ); return date( "Y", $upper_date ) . '-' . date( "m", $upper_date ) . '-' . date( "d", $upper_date ); } @@ -60,15 +62,19 @@ static function runCalendarEndDate( &$parser, $calendar_type = 'month', $calenda * the year/month/day to be queried. * */ - static function getBoundaryDates( $calendar_type = 'month', $calendar_start_day = null, $calendar_days = 7, $default_year = null, $default_month = null, $default_day = null ) { - if ( $calendar_type == 'month' ) { $calendar_start_day = 0; + public static function getBoundaryDates( $calendar_type = 'month', $calendar_start_day = null, $calendar_days = 7, $default_year = null, $default_month = null, $default_day = null ) { + if ( $calendar_type == 'month' ) { + $calendar_start_day = 0; } - if ( $default_year == null ) { $default_year = date( "Y", time() ); + if ( $default_year == null ) { + $default_year = date( "Y", time() ); } - if ( $default_month == null ) { $default_month = date( "n", time() ); + if ( $default_month == null ) { + $default_month = date( "n", time() ); } - if ( $default_day == null ) { $default_day = date( "j", time() ); + if ( $default_day == null ) { + $default_day = date( "j", time() ); } global $wgRequest; diff --git a/SemanticResultFormats.php b/SemanticResultFormats.php index c17988a10..7214b13de 100644 --- a/SemanticResultFormats.php +++ b/SemanticResultFormats.php @@ -43,7 +43,7 @@ public static function initExtension( $credits = [] ) { $GLOBALS['wgExtensionMessagesFiles']['SemanticResultFormats'] = __DIR__ . '/SemanticResultFormats.i18n.php'; $GLOBALS['wgExtensionMessagesFiles']['SemanticResultFormatsMagic'] = __DIR__ . '/SemanticResultFormats.i18n.magic.php'; - $GLOBALS['srfgIP'] = __DIR__; + $GLOBALS['wgSrfgIP'] = __DIR__; $GLOBALS['wgResourceModules'] = array_merge( $GLOBALS['wgResourceModules'], include __DIR__ . "/Resources.php" ); } @@ -161,7 +161,7 @@ public static function onExtensionFunction() { 'incoming' => 'SRFIncoming', 'media' => 'SRF\MediaPlayer', 'datatables' => 'SRF\DataTables', - 'carousel' => 'SRF\Carousel', + 'carousel' => 'SRF\Carousel', 'gantt' => 'SRF\Gantt\GanttPrinter', 'prolog' => 'SRF\Prolog\PrologPrinter', 'dataframe' => 'SRF\dataframe\DataframePrinter', diff --git a/SemanticResultFormats.utils.php b/SemanticResultFormats.utils.php index 459e972fe..6b29a450e 100644 --- a/SemanticResultFormats.utils.php +++ b/SemanticResultFormats.utils.php @@ -43,7 +43,7 @@ public static function addGlobalJSVariables() { } /** - * @brief Returns semantic search link for the current query + * Returns semantic search link for the current query * * Generate a link to access the current ask query * diff --git a/build b/build index 9eb0faa27..282106ed8 160000 --- a/build +++ b/build @@ -1 +1 @@ -Subproject commit 9eb0faa2760621cd548362d354566815fd3f089b +Subproject commit 282106ed84adc2512054942c9c51128d98f45412 diff --git a/composer.json b/composer.json index d688dd181..4a65860b6 100644 --- a/composer.json +++ b/composer.json @@ -83,30 +83,33 @@ }, "scripts":{ "test": [ + "@analyze", "@phpunit" ], "test-coverage": [ + "@analyze", "@phpunit-coverage" ], - "phpunit": "php ${MW_INSTALL_PATH:-../..}/tests/phpunit/phpunit.php -c phpunit.xml.dist", - "phpunit-coverage": "php ${MW_INSTALL_PATH:-../..}/tests/phpunit/phpunit.php -c phpunit.xml.dist --testdox --coverage-text --coverage-html coverage/php --coverage-clover coverage/php/coverage.xml", - "integration": "composer phpunit -- --testsuite=semantic-result-formats-integration", - "lint": [ - "@parallel-lint", - "minus-x check .", - "@phpcs" + "analyze": [ + "@lint", + "@phpcs", + "@minus-x" ], "fix": [ - "minus-x fix .", - "phpcbf" + "@phpcs-fix" ], - "phpcs": "phpcs -sp", - "parallel-lint": "parallel-lint . --exclude vendor --exclude node_modules --exclude conf" + "phpunit": "php ${MW_INSTALL_PATH:-../..}/tests/phpunit/phpunit.php -c phpunit.xml.dist", + "phpunit-coverage": "php ${MW_INSTALL_PATH:-../..}/tests/phpunit/phpunit.php -c phpunit.xml.dist --testdox --coverage-text --coverage-html coverage/php --coverage-clover coverage/php/coverage.xml", + "integration": "composer phpunit -- --testsuite=semantic-result-formats-integration", + "phpcs": "phpcs -ps -d memory_limit=2G", + "phpcs-fix": "phpcbf -p", + "lint": "parallel-lint . --exclude vendor --exclude node_modules --exclude extensions", + "minus-x": "minus-x check ." }, "require-dev": { - "mediawiki/mediawiki-codesniffer": "38.0.0", - "mediawiki/minus-x": "1.1.1", - "php-parallel-lint/php-console-highlighter": "0.5.0", - "php-parallel-lint/php-parallel-lint": "1.3.1" + "mediawiki/mediawiki-codesniffer": "43.0.0", + "mediawiki/minus-x": "1.1.3", + "php-parallel-lint/php-console-highlighter": "1.0.0", + "php-parallel-lint/php-parallel-lint": "1.4.0" } } diff --git a/formats/Exhibit/SRF_Exhibit.php b/formats/Exhibit/SRF_Exhibit.php index c51548517..b89aa3206 100644 --- a/formats/Exhibit/SRF_Exhibit.php +++ b/formats/Exhibit/SRF_Exhibit.php @@ -18,22 +18,32 @@ class SRFExhibit extends SMWResultPrinter { // /mapping between SMW's and Exhibit's the data types protected $m_types = [ "_wpg" => "text", "_num" => "number", "_dat" => "date", "_geo" => "text", "_uri" => "url" ]; + // not sufficient since there might be multiple pages rendered within one PHP run; but good enough now + protected static $exhibitRunningNumber = 0; - protected static $exhibitRunningNumber = 0; // not sufficient since there might be multiple pages rendered within one PHP run; but good enough now - - // /overwrite function to allow execution of result printer even if no results are available (in case remote query yields no results in local wiki) + /** + * overwrite function to allow execution of result printer even if no results are available + * (in case remote query yields no results in local wiki) + * + */ public function getResult( $results, $params, $outputmode ) { $this->readParameters( $params, $outputmode ); $result = $this->getResultText( $results, $outputmode ); return $result; } - // /function aligns the format of SMW's property names to Exhibit's format + /** + * function aligns the format of SMW's property names to Exhibit's format + * + */ protected function encodePropertyName( $property ) { return strtolower( str_replace( " ", "_", trim( $property ) ) ); } - // /Tries to determine the namespace in the event it got lost + /** + * Tries to determine the namespace in the event it got lost + * + */ protected function determineNamespace( $res ) { $row = $res->getNext(); if ( $row != null ) { @@ -53,7 +63,7 @@ protected function determineNamespace( $res ) { } protected function getResultText( SMWQueryResult $res, $outputmode ) { - global $smwgIQRunningNumber, $wgScriptPath, $wgGoogleMapsKey, $srfgScriptPath; + global $wgSmIQRunningNumber, $wgScriptPath, $wgGoogleMapsKey, $wgSrfgScriptPath; if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) { SMWOutputs::requireHeadItem( 'exhibit-compat', Html::linkedScript( "$wgScriptPath/common/wikibits.js" ) ); @@ -86,7 +96,8 @@ protected function getResultText( SMWQueryResult $res, $outputmode ) { if ( array_key_exists( 'callback', $this->params - ) ) { // check if a special name for the callback function is set, if not stick with 'callback' + ) ) { + // check if a special name for the callback function is set, if not stick with 'callback' $callbackfunc = $this->params['callback']; } else { $callbackfunc = 'callback'; @@ -99,7 +110,7 @@ protected function getResultText( SMWQueryResult $res, $outputmode ) { $link->setParameter( $callbackfunc, 'callback' ); $link = $link->getText( 2, $this->mLinker ); - list( $link, $trash ) = explode( '|', $link ); + [ $link, $trash ] = explode( '|', $link ); $link = str_replace( '[[:', '', $link ); $newheader .= str_replace( '$1', $link, $extlinkpattern ); @@ -129,12 +140,12 @@ protected function getResultText( SMWQueryResult $res, $outputmode ) { array_unshift( $colstack, 'label' ); if ( self::$exhibitRunningNumber == 0 ) { - $sourcesrc = "var ex_sources = { source" . ( $smwgIQRunningNumber - 1 ) . ": { id: 'querytable" . $smwgIQRunningNumber . "' , columns: '" . implode( + $sourcesrc = "var ex_sources = { source" . ( $wgSmIQRunningNumber - 1 ) . ": { id: 'querytable" . $wgSmIQRunningNumber . "' , columns: '" . implode( ',', $colstack ) . "'.split(','), hideTable: '1', type: 'Item', label: 'Item', pluralLabel: 'Items' } };"; } else { - $sourcesrc = "sources.source" . $smwgIQRunningNumber . " = { id: 'querytable" . $smwgIQRunningNumber . "' , columns: '" . implode( + $sourcesrc = "sources.source" . $wgSmIQRunningNumber . " = { id: 'querytable" . $wgSmIQRunningNumber . "' , columns: '" . implode( ',', $colstack ) . "'.split(','), hideTable: '1', type: 'Item', label: 'Item', pluralLabel: 'Items' };"; @@ -155,9 +166,11 @@ protected function getResultText( SMWQueryResult $res, $outputmode ) { } foreach ( $facets as $facet ) { $facet = trim( $facet ); - if ( strtolower( $facet ) == "search" ) { // special facet (text search) + if ( strtolower( $facet ) == "search" ) { + // special facet (text search) $facetstack[] = ' facet' . $facetcounter++ . ': { position : "right", innerHTML: \'ex:role="facet" ex:showMissing="false" ex:facetClass="TextSearch" ex:facetLabel="' . $facet . '"\'}'; - } else { // usual facet + } else { + // usual facet foreach ( $res->getPrintRequests() as $pr ) { if ( $this->encodePropertyName( $pr->getLabel() ) == $this->encodePropertyName( $facet ) ) { switch ( $pr->getTypeID() ) { @@ -195,32 +208,37 @@ protected function getResultText( SMWQueryResult $res, $outputmode ) { foreach ( $views as $view ) { switch ( trim( $view ) ) { - case 'tabular':// table view (the columns are automatically defined by the selected properties) + case 'tabular': + // table view (the columns are automatically defined by the selected properties) $thstack = []; foreach ( $res->getPrintRequests() as $pr ) { $thstack[] = "." . $this->encodePropertyName( $pr->getLabel() ); } array_shift( $thstack ); array_unshift( $thstack, '.label' ); - $stylesrc = 'var myStyler = function(table, database) {table.className=\'smwtable\';};'; // assign SMWtable CSS to Exhibit tabular view + // assign SMWtable CSS to Exhibit tabular view + $stylesrc = 'var myStyler = function(table, database) {table.className=\'smwtable\';};'; $viewstack[] = 'ex:role=\'view\' ex:viewClass=\'Tabular\' ex:showSummary=\'false\' ex:sortAscending=\'true\' ex:tableStyler=\'myStyler\' ex:label=\'Table\' ex:columns=\'' . implode( ',', $thstack ) . '\' ex:sortAscending=\'false\''; break; - case 'timeline':// timeline view + case 'timeline': + // timeline view $timeline = true; $exparams = [ 'start', 'end', 'proxy', - 'colorkey' ]; // parameters expecting an Exhibit graph expression + 'colorkey' ]; + // parameters expecting an Exhibit graph expression $usparams = [ 'timelineheight', 'topbandheight', 'bottombandheight', 'bottombandunit', - 'topbandunit' ]; // parametes expecting a textual or numeric value + 'topbandunit' ]; + // parametes expecting a textual or numeric value $tlparams = []; foreach ( $exparams as $param ) { if ( array_key_exists( $param, $this->params ) ) { @@ -239,7 +257,8 @@ protected function getResultText( SMWQueryResult $res, $outputmode ) { if ( !array_key_exists( 'start', $this->params - ) ) {// find out if a start and/or end date is specified + ) ) { + // find out if a start and/or end date is specified $dates = []; foreach ( $res->getPrintRequests() as $pr ) { if ( $pr->getTypeID() == '_dat' ) { @@ -261,7 +280,8 @@ protected function getResultText( SMWQueryResult $res, $outputmode ) { $tlparams ); break; - case 'map':// map view + case 'map': + // map view if ( isset( $wgGoogleMapsKey ) ) { $map = true; $exparams = [ 'latlng', 'colorkey' ]; @@ -291,7 +311,8 @@ protected function getResultText( SMWQueryResult $res, $outputmode ) { if ( !array_key_exists( 'start', $this->params ) && !array_key_exists( 'end', $this->params - ) ) { // find out if a geographic coordinate is available + ) ) { + // find out if a geographic coordinate is available foreach ( $res->getPrintRequests() as $pr ) { if ( $pr->getTypeID() == '_geo' ) { $mapparams[] = 'ex:latlng=\'.' . $this->encodePropertyName( @@ -308,7 +329,8 @@ protected function getResultText( SMWQueryResult $res, $outputmode ) { } break; default: - case 'tiles':// tile view + case 'tiles': + // tile view $sortstring = ''; if ( array_key_exists( 'sort', $this->params ) ) { $sortfields = explode( ",", $this->params['sort'] ); @@ -343,7 +365,8 @@ protected function getResultText( SMWQueryResult $res, $outputmode ) { if ( array_key_exists( 'lens', $this->params - ) ) {// a customized lens is specified via the lens parameter within the query + ) ) { + // a customized lens is specified via the lens parameter within the query $lenstitle = Title::newFromText( "Template:" . $this->params['lens'] ); $lensarticle = new Article( $lenstitle ); $lenswikitext = $lensarticle->getContent(); @@ -407,14 +430,15 @@ protected function getResultText( SMWQueryResult $res, $outputmode ) { $parser = MediaWikiServices::getInstance()->getParser(); $lenshtml = $parser->internalParse( $lenswikitext - );// $parser->parse($lenswikitext, $lenstitle, new ParserOptions(), true, true)->getText(); - + ); + // $parser->parse($lenswikitext, $lenstitle, new ParserOptions(), true, true)->getText(); $lenssrc = "var ex_lens = '" . str_replace( "\n", "", $lenshtml ) . "';ex_lenscounter =" . $lenscounter . ";ex_linkcounter=" . $linkcounter . ";ex_imagecounter=" . $imagecounter . ";"; - } else {// generic lens (creates links to further content (property-pages, pages about values) + } else { + // generic lens (creates links to further content (property-pages, pages about values) foreach ( $res->getPrintRequests() as $pr ) { if ( $remote ) { $wikiurl = str_replace( "$1", "", $extlinkpattern ); @@ -469,7 +493,8 @@ protected function getResultText( SMWQueryResult $res, $outputmode ) { // create a URL pointing to the corresponding JSON feed $label = ''; $JSONlink = $res->getQueryLink( $label ); - if ( $this->getSearchLabel( SMW_OUTPUT_WIKI ) != '' ) { // used as a file name + if ( $this->getSearchLabel( SMW_OUTPUT_WIKI ) != '' ) { + // used as a file name $link->setParameter( $this->getSearchLabel( SMW_OUTPUT_WIKI ), 'searchlabel' ); } if ( array_key_exists( 'limit', $this->params ) ) { @@ -485,7 +510,7 @@ protected function getResultText( SMWQueryResult $res, $outputmode ) { // To run Exhibit some links to the scripts of the API need to be included in the header - $ExhibitScriptSrc1 = ''; - $ExhibitScriptSrc2 = ''; - $CSSSrc = ''; - - SMWOutputs::requireHeadItem( 'CSS', $CSSSrc ); // include CSS - SMWOutputs::requireHeadItem( 'EXHIBIT1', $ExhibitScriptSrc1 ); // include Exhibit API + $ExhibitScriptSrc2 = ''; + $CSSSrc = ''; + // include CSS + SMWOutputs::requireHeadItem( 'CSS', $CSSSrc ); + // include Exhibit API + SMWOutputs::requireHeadItem( 'EXHIBIT1', $ExhibitScriptSrc1 ); SMWOutputs::requireHeadItem( 'EXHIBIT2', $ExhibitScriptSrc2 - ); // includes javascript overwriting the Exhibit start-up functions - SMWOutputs::requireHeadItem( 'SOURCES' . $smwgIQRunningNumber, $sourcesrc );// include sources variable - SMWOutputs::requireHeadItem( 'VIEWSFACETS', $headervars );// include views and facets variable + ); + // includes javascript overwriting the Exhibit start-up functions, include sources variable + SMWOutputs::requireHeadItem( 'SOURCES' . $wgSmIQRunningNumber, $sourcesrc ); + // include views and facets variable + SMWOutputs::requireHeadItem( 'VIEWSFACETS', $headervars ); if ( !$remote ) { // print input table // print header - $result = "\n"; - if ( $this->mShowHeaders ) { // building headers + $result = "
\n"; + if ( $this->mShowHeaders ) { + // building headers $result .= "\t\n"; foreach ( $res->getPrintRequests() as $pr ) { if ( $pr->getText( $outputmode, $this->getLinker( 0 ) ) == '' ) { @@ -597,8 +626,9 @@ protected function getResultText( SMWQueryResult $res, $outputmode ) { if ( self::$exhibitRunningNumber == 0 ) { $result .= "
"; - } // print placeholder (just print it one time) - $this->isHTML = ( $outputmode == SMW_OUTPUT_HTML ); // yes, our code can be viewed as HTML if requested, no more parsing needed + } + // print placeholder (just print it one time) + $this->isHTML = ( $outputmode == SMW_OUTPUT_HTML ); self::$exhibitRunningNumber++; return $result; } diff --git a/formats/Gantt/src/Gantt.php b/formats/Gantt/src/Gantt.php index f53e27bad..1e9972eee 100644 --- a/formats/Gantt/src/Gantt.php +++ b/formats/Gantt/src/Gantt.php @@ -81,7 +81,6 @@ private function getTasks() { * @param string $endDate * */ - public function addTask( $taskID, $taskTitle, $status, $priority, $startDate, $endDate ) { $task = new GanttTask(); $task->setID( $taskID ); diff --git a/formats/Gantt/src/GanttSection.php b/formats/Gantt/src/GanttSection.php index ba8160f14..a2f298722 100644 --- a/formats/Gantt/src/GanttSection.php +++ b/formats/Gantt/src/GanttSection.php @@ -55,7 +55,10 @@ public function getTasks() { return $this->mTasks; } - // If we reorder the tasks we need to reset it with the ordered tasks + /** + * If we reorder the tasks we need to reset it with the ordered tasks + * + */ public function setTasks( $tasks ) { $this->mTasks = $tasks; } diff --git a/formats/JitGraph/SRF_JitGraph.php b/formats/JitGraph/SRF_JitGraph.php index a69379b94..81c610f2c 100644 --- a/formats/JitGraph/SRF_JitGraph.php +++ b/formats/JitGraph/SRF_JitGraph.php @@ -36,8 +36,10 @@ class SRFJitGraph extends SMWResultPrinter { 'red' => '#CF2A2A', 'green' => '#558800', 'blue' => '#005588' ]; - protected $m_rootNodeColor = '#CF2A2A'; // Red - protected $m_graphNodeColor = '#005588'; // Blue + // Red + protected $m_rootNodeColor = '#CF2A2A'; + // Blue + protected $m_graphNodeColor = '#005588'; protected $m_settings = [ "divID" => "infovis", @@ -142,7 +144,8 @@ public function getName() { } protected function getResultText( SMWQueryResult $res, $outputmode ) { - global $wgTitle, $wgOut; + global $wgOut; + $title = RequestContext::getMain()->getTitle(); if ( class_exists( 'ResourceLoader' ) ) { $wgOut->addModules( 'ext.srf.jitgraph' ); @@ -169,7 +172,7 @@ protected function getResultText( SMWQueryResult $res, $outputmode ) { $firstcolvalue = $object->getShortText( $outputmode ); // Title of the page where the result format is being displayed - $thisPageTitle = $wgTitle->getPrefixedText(); + $thisPageTitle = $title->getPrefixedText(); // This little block adds the name of the current edge to the list later used to compile the graph legend $req = $field->getPrintRequest(); @@ -253,16 +256,20 @@ protected function getResultText( SMWQueryResult $res, $outputmode ) { $firstcol = false; } - $json = substr( $json, 0, -1 ); // Trim the comma after the last item in the list - $json .= "]},"; // close adjacencies array + // Trim the comma after the last item in the list + $json = substr( $json, 0, -1 ); + // close adjacencies array + $json .= "]},"; - //Append the leaf nodes. - //$jsonLeafs = substr($jsonLeafs,0,-1); // Trim the comma after the last item in the list + // Append the leaf nodes. + // $jsonLeafs = substr($jsonLeafs,0,-1); // Trim the comma after the last item in the list $json .= $jsonLeafs; $jsonLeafs = ""; } - $json = substr( $json, 0, -1 ); // Trim the comma after the last item in the list - $json .= "]"; // close the json object array + // Trim the comma after the last item in the list + $json = substr( $json, 0, -1 ); + // close the json object array + $json .= "]"; $result = ''; @@ -271,7 +278,8 @@ protected function getResultText( SMWQueryResult $res, $outputmode ) { } $d_id = rand( 1000, 9999 ); - $divID = 'infovis-' . $d_id; // generate a random id to have the ability to display multiple graphs on a single page. + // generate a random id to have the ability to display multiple graphs on a single page. + $divID = 'infovis-' . $d_id; $this->m_settings['d_id'] = $d_id; $this->m_settings['divID'] = $divID; @@ -306,26 +314,26 @@ protected function includeJS() { // $wgOut->addModules( 'ext.srf.jitgraph' ); - global $srfgScriptPath; + global $wgSrfgScriptPath; SMWOutputs::requireHeadItem( 'smw_jgcss', - '' ); SMWOutputs::requireHeadItem( 'smw_jgloader', - '' ); SMWOutputs::requireHeadItem( 'smw_jg', - '' ); SMWOutputs::requireHeadItem( 'smw_jghelper', - '' ); } diff --git a/formats/Prolog/PrologPrinter.php b/formats/Prolog/PrologPrinter.php index 24b05b2b4..bbcb9f686 100644 --- a/formats/Prolog/PrologPrinter.php +++ b/formats/Prolog/PrologPrinter.php @@ -11,198 +11,195 @@ */ class PrologPrinter extends FileExportPrinter { - const HEADER_ROW_OFFSET = 1; - - protected $fileFormats = [ - 'pl' => [ - 'writer' => 'pl', - 'mimetype' => 'text/prolog', - 'extension' => '.pl', - ], - 'pro' => [ - 'writer' => 'pl', - 'mimetype' => 'text/prolog', - 'extension' => '.pro', - ], - ]; - - protected $fileFormat; - - /** - * Output a human readable label for this printer. - * - * @see ResultPrinter::getName - * - * {@inheritDoc} - */ - public function getName() { - return $this->msg( 'srf-printername-prolog' ); - } - - /** - * @see ExportPrinter::getMimeType() - * - * @since 1.8 - * - * @param SMWQueryResult $queryResult - * - * @return string - */ - public function getMimeType( SMWQueryResult $queryResult ) { - return $this->fileFormat[ 'mimetype' ]; - } - - /** - * @see ExportPrinter::getFileName - * - * @param SMWQueryResult $queryResult - * - * @return string - */ - public function getFileName( SMWQueryResult $queryResult ) { - return ( $this->params[ 'filename' ] ?: base_convert( uniqid(), 16, 36 ) ) . $this->fileFormat[ 'extension' ]; - } - - /** - * @see ExportPrinter::outputAsFile - * - * @param SMWQueryResult $queryResult - * @param array $params - */ - public function outputAsFile( SMWQueryResult $queryResult, array $params ) - { - if ( array_key_exists( 'fileformat', $params) && array_key_exists( $params[ 'fileformat' ]->getValue(), $this->fileFormats )) { + public const HEADER_ROW_OFFSET = 1; + + protected $fileFormats = [ + 'pl' => [ + 'writer' => 'pl', + 'mimetype' => 'text/prolog', + 'extension' => '.pl', + ], + 'pro' => [ + 'writer' => 'pl', + 'mimetype' => 'text/prolog', + 'extension' => '.pro', + ], + ]; + + protected $fileFormat; + + /** + * Output a human readable label for this printer. + * + * @see ResultPrinter::getName + * + * {@inheritDoc} + */ + public function getName() { + return $this->msg( 'srf-printername-prolog' ); + } + + /** + * @see ExportPrinter::getMimeType() + * + * @since 1.8 + * + * @param SMWQueryResult $queryResult + * + * @return string + */ + public function getMimeType( SMWQueryResult $queryResult ) { + return $this->fileFormat[ 'mimetype' ]; + } + + /** + * @see ExportPrinter::getFileName + * + * @param SMWQueryResult $queryResult + * + * @return string + */ + public function getFileName( SMWQueryResult $queryResult ) { + return ( $this->params[ 'filename' ] ?: base_convert( uniqid(), 16, 36 ) ) . $this->fileFormat[ 'extension' ]; + } + + /** + * @see ExportPrinter::outputAsFile + * + * @param SMWQueryResult $queryResult + * @param array $params + */ + public function outputAsFile( SMWQueryResult $queryResult, array $params ) { + if ( array_key_exists( 'fileformat', $params ) && array_key_exists( $params[ 'fileformat' ]->getValue(), $this->fileFormats ) ) { $this->fileFormat = $this->fileFormats[ $params[ 'fileformat' ]->getValue() ]; } else { $this->fileFormat = $this->fileFormats[ 'pl' ]; } parent::outputAsFile( $queryResult, $params ); - } - - /** - * Defines the list of available parameters to an individual result - * printer. - * - * @see ResultPrinter::getParamDefinitions - * - * {@inheritDoc} - */ - public function getParamDefinitions( array $definitions ) { - $params = parent::getParamDefinitions( $definitions ); - - $definitions[ 'searchlabel' ]->setDefault( wfMessage( 'srf-prolog-link' )->inContentLanguage()->text() ); - - $params[ 'filename' ] = [ - 'type' => 'string', - 'name' => 'filename', - 'default' => '', - 'message' => 'srf-paramdesc-prolog-filename', - ]; - - $params[ 'fileformat' ] = [ - 'type' => 'string', - 'name' => 'fileformat', - 'default' => 'pl', - 'tolower' => true, - 'message' => 'srf-paramdesc-prolog-fileformat', - ]; - - $params[ 'pname' ] = [ - 'type' => 'string', - 'name' => 'pname', - 'default' => 'predicate', - 'tolower' => true, - 'message' => 'srf-paramdesc-prolog-pname', - ]; - - $params[ 'navalue' ] = [ - 'type' => 'string', - 'name' => 'navalue', - 'default' => "'NA'", - 'message' => 'srf-paramdesc-prolog-navalue', - ]; - - return $params; - } - - /** - * This method gets the query result object and is supposed to return - * whatever output the format creates. For example, in the list format, it - * goes through all results and constructs an HTML list, which is then - * returned. Looping through the result object is somewhat complex, and - * requires some understanding of the `QueryResult` class. - * - * @see ResultPrinter::getResultText - * - * {@inheritDoc} - */ - protected function getResultText( SMWQueryResult $queryResult, $outputMode ) { - - if ( $outputMode === SMW_OUTPUT_FILE ) { - return $this->getResultFileContents( $queryResult ); - } - - $this->isHTML = ( $outputMode === SMW_OUTPUT_HTML ); - return $this->getLink( $queryResult, $outputMode )->getText( $outputMode, $this->mLinker ); - } - - /** - * @param SMWQueryResult $queryResult - * - * @return string - */ - protected function getResultFileContents( SMWQueryResult $queryResult ) - { - $res = ''; - /*if ($this->params['rownames']) - $res .= 'row.names=T, ';*/ - - $preds = []; - while ($resultRow = $queryResult->getNext()) { - - $subject = ''; - $i = 0; - foreach ($resultRow as $resultField) { - if ($i === 0) - $subject = $dataItems = $resultField->getContent()[0]; - else { - $propertyLabel = $resultField->getPrintRequest()->getLabel(); - - //$subjectLabel = $resultField->getResultSubject()->getTitle()->getFullText(); - $dataItems = $resultField->getContent(); - - if (count($dataItems) > 1) { - $values = []; - - while ($value = $resultField->getNextText(SMW_OUTPUT_FILE)) - $values[] = $value; - - $rowData = "['" . implode("', '", $values) . "']"; - } - else { - $nextDataValue = $resultField->getNextDataValue(); - if ($nextDataValue !== false) { - if ($nextDataValue instanceof \SMWNumberValue) - $rowData = $nextDataValue; - else if ($nextDataValue instanceof \SMWTimeValue) - $rowData = "'" . $nextDataValue->getISO8601Date() . "'"; - else { - $nextDataValue = str_replace("'", "\'", $nextDataValue); - $rowData = "'$nextDataValue'"; - } - } else - $rowData = $this->params['navalue']; - } - $preds[] = $this->params['pname'] . "('$subject', '$propertyLabel', $rowData)."; - } - - $i++; - } - } - - $res = implode("\n", $preds); - return $res; - } + } + + /** + * Defines the list of available parameters to an individual result + * printer. + * + * @see ResultPrinter::getParamDefinitions + * + * {@inheritDoc} + */ + public function getParamDefinitions( array $definitions ) { + $params = parent::getParamDefinitions( $definitions ); + + $definitions[ 'searchlabel' ]->setDefault( wfMessage( 'srf-prolog-link' )->inContentLanguage()->text() ); + + $params[ 'filename' ] = [ + 'type' => 'string', + 'name' => 'filename', + 'default' => '', + 'message' => 'srf-paramdesc-prolog-filename', + ]; + + $params[ 'fileformat' ] = [ + 'type' => 'string', + 'name' => 'fileformat', + 'default' => 'pl', + 'tolower' => true, + 'message' => 'srf-paramdesc-prolog-fileformat', + ]; + + $params[ 'pname' ] = [ + 'type' => 'string', + 'name' => 'pname', + 'default' => 'predicate', + 'tolower' => true, + 'message' => 'srf-paramdesc-prolog-pname', + ]; + + $params[ 'navalue' ] = [ + 'type' => 'string', + 'name' => 'navalue', + 'default' => "'NA'", + 'message' => 'srf-paramdesc-prolog-navalue', + ]; + + return $params; + } + + /** + * This method gets the query result object and is supposed to return + * whatever output the format creates. For example, in the list format, it + * goes through all results and constructs an HTML list, which is then + * returned. Looping through the result object is somewhat complex, and + * requires some understanding of the `QueryResult` class. + * + * @see ResultPrinter::getResultText + * + * {@inheritDoc} + */ + protected function getResultText( SMWQueryResult $queryResult, $outputMode ) { + if ( $outputMode === SMW_OUTPUT_FILE ) { + return $this->getResultFileContents( $queryResult ); + } + + $this->isHTML = ( $outputMode === SMW_OUTPUT_HTML ); + return $this->getLink( $queryResult, $outputMode )->getText( $outputMode, $this->mLinker ); + } + + /** + * @param SMWQueryResult $queryResult + * + * @return string + */ + protected function getResultFileContents( SMWQueryResult $queryResult ) { + $res = ''; + /*if ($this->params['rownames']) + $res .= 'row.names=T, ';*/ + + $preds = []; + while ( $resultRow = $queryResult->getNext() ) { + + $subject = ''; + $i = 0; + foreach ( $resultRow as $resultField ) { + if ( $i === 0 ) { + $subject = $dataItems = $resultField->getContent()[0]; + } else { + $propertyLabel = $resultField->getPrintRequest()->getLabel(); + + // $subjectLabel = $resultField->getResultSubject()->getTitle()->getFullText(); + $dataItems = $resultField->getContent(); + + if ( count( $dataItems ) > 1 ) { + $values = []; + + while ( $value = $resultField->getNextText( SMW_OUTPUT_FILE ) ) { + $values[] = $value; + } + $rowData = "['" . implode( "', '", $values ) . "']"; + } else { + $nextDataValue = $resultField->getNextDataValue(); + if ( $nextDataValue !== false ) { + if ( $nextDataValue instanceof \SMWNumberValue ) { + $rowData = $nextDataValue; + } elseif ( $nextDataValue instanceof \SMWTimeValue ) { + $rowData = "'" . $nextDataValue->getISO8601Date() . "'"; + } else { + $nextDataValue = str_replace( "'", "\'", $nextDataValue ); + $rowData = "'$nextDataValue'"; + } + } else { + $rowData = $this->params['navalue']; + } + } + $preds[] = $this->params['pname'] . "('$subject', '$propertyLabel', $rowData)."; + } + + $i++; + } + } + + $res = implode( "\n", $preds ); + return $res; + } } diff --git a/formats/array/SRF_Array.php b/formats/array/SRF_Array.php index 48a8b3751..91404f4d9 100644 --- a/formats/array/SRF_Array.php +++ b/formats/array/SRF_Array.php @@ -53,14 +53,13 @@ public function getName() { return wfMessage( 'srf_printername_' . $this->mFormat )->text(); } - /* - // By overwriting this function, we disable default searchlabel handling? - public function getResult( SMWQueryResult $results, array $params, $outputmode ) { - $this->handleParameters( $params, $outputmode ); - return $this->getResultText( $results, $outputmode ); - } - */ - + /** + * By overwriting this function, we disable default searchlabel handling? + * public function getResult( SMWQueryResult $results, array $params, $outputmode ) { + * $this->handleParameters( $params, $outputmode ); + * return $this->getResultText( $results, $outputmode ); + * } + */ protected function getResultText( SMWQueryResult $res, $outputmode ) { /* * @todo @@ -83,7 +82,8 @@ protected function getResultText( SMWQueryResult $res, $outputmode ) { $isPageTitle = !$this->mMainLabelHack; // for each property on that page: - foreach ( $row as $field ) { // $row is array(), $field of type SMWResultArray + // $row is array(), $field of type SMWResultArray + foreach ( $row as $field ) { $manyValue_items = []; $isMissingProperty = false; @@ -94,8 +94,7 @@ protected function getResultText( SMWQueryResult $res, $outputmode ) { $delivery = $this->deliverMissingProperty( $field ); $manyValue_items = $this->fillDeliveryArray( $manyValue_items, $delivery ); $isMissingProperty = true; - } else // otherwise collect property value (potentially many values): - { + } else { while ( $obj = $field->getNextDataValue() ) { $value_items = []; @@ -105,14 +104,13 @@ protected function getResultText( SMWQueryResult $res, $outputmode ) { if ( $isPageTitle ) { if ( !$this->mShowPageTitles ) { $isPageTitle = false; - continue 2; // next property + continue 2; } $value_items = $this->fillDeliveryArray( $value_items, $this->deliverPageTitle( $obj, $this->mLinkFirst ) ); - } // handle record values: - elseif ( $obj instanceof SMWRecordValue ) { + } elseif ( $obj instanceof SMWRecordValue ) { $recordItems = $obj->getDataItems(); // walk all single values of the record set: foreach ( $recordItems as $dataItem ) { @@ -124,17 +122,16 @@ protected function getResultText( SMWQueryResult $res, $outputmode ) { ); } $isRecord = true; - } // handle normal data values: - else { - $value_items = $this->fillDeliveryArray( - $value_items, - $this->deliverSingleValue( $obj, $this->mLinkOthers ) - ); - } + } else { + $value_items = $this->fillDeliveryArray( + $value_items, + $this->deliverSingleValue( $obj, $this->mLinkOthers ) + ); + } $delivery = $this->deliverSingleManyValuesData( $value_items, $isRecord, $isPageTitle ); $manyValue_items = $this->fillDeliveryArray( $manyValue_items, $delivery ); } - } // foreach... + } $delivery = $this->deliverPropertiesManyValues( $manyValue_items, $isMissingProperty, @@ -142,19 +139,25 @@ protected function getResultText( SMWQueryResult $res, $outputmode ) { $field ); $perProperty_items = $this->fillDeliveryArray( $perProperty_items, $delivery ); - $isPageTitle = false; // next one could be record or normal value - } // foreach... + // next one could be record or normal value + $isPageTitle = false; + } $delivery = $this->deliverPageProperties( $perProperty_items ); $perPage_items = $this->fillDeliveryArray( $perPage_items, $delivery ); - } // while... + } $output = $this->deliverQueryResultPages( $perPage_items ); return $output; } + /** + * Method fillDeliveryArray + * + */ protected function fillDeliveryArray( $array = [], $value = null ) { - if ( $value !== null ) { // don't create any empty entries + // don't create any empty entries + if ( $value !== null ) { $array[] = $value; } return $array; @@ -169,30 +172,39 @@ protected function deliverRecordField( $value, $link = false ) { return $this->deliverSingleValue( $value, $link ); } elseif ( $this->mHideRecordGaps ) { return null; - } // hide gap - else { + } else { return ''; - } // empty string will make sure that record value separators are generated + } } protected function deliverSingleValue( $value, $link = false ) { // return trim( $value->getShortWikiText( $link ) ); return trim( Sanitizer::decodeCharReferences( $value->getShortWikiText( $link ) ) - ); // decode: better for further processing with array extension + ); } - // Property not declared on a page: + /** + * Method deliverMissingProperty + * + * @param SMWResultArray $field + */ protected function deliverMissingProperty( SMWResultArray $field ) { if ( $this->mHidePropertyGaps ) { return null; } else { return ''; - } // empty string will make sure that array separator will be generated + } /** @ToDo: System for Default values?... * */ } - // represented by an array of record fields or just a single array value: + /** + * Method deliverSingleManyValuesData + * + * @param $value_items + * @param $containsRecord + * @param $isPageTitle + */ protected function deliverSingleManyValuesData( $value_items, $containsRecord, $isPageTitle ) { if ( empty( $value_items ) ) { return null; @@ -224,7 +236,8 @@ protected function deliverPageProperties( $perProperty_items ) { protected function deliverQueryResultPages( $perPage_items ) { if ( $this->mArrayName !== null ) { - $this->createArray( $perPage_items ); // create Array + // create Array + $this->createArray( $perPage_items ); return ''; } else { return implode( $this->mSep, $perPage_items ); @@ -277,8 +290,8 @@ protected function initializeCfgValue( $dfltVal, $dfltCacheKey ) { if ( $cache === null ) { // cache can't be initialized, propably function-reference in userconfig // but format is not used in inline context, use fallback in this case: - global $srfgArraySepTextualFallbacks; - $cache = $srfgArraySepTextualFallbacks[$dfltCacheKey]; + global $wgSrfgArraySepTextualFallbacks; + $cache = $wgSrfgArraySepTextualFallbacks[$dfltCacheKey]; } } return $cache; @@ -296,7 +309,7 @@ protected function getCfgSepText( $obj ) { $params = $obj['args']; } else { $params = []; - } // no arguments + } // create title of page whose text should be used as separator: $obj = Title::newFromText( $obj[0], ( array_key_exists( 1, $obj ) ? $obj[1] : NS_MAIN ) ); @@ -306,7 +319,7 @@ protected function getCfgSepText( $obj ) { } elseif ( $obj instanceof Article ) { $article = $obj; } else { - return $obj; // only text + return $obj; } /* @@ -349,7 +362,8 @@ protected function handleParameters( array $params, $outputmode ) { $this->mArrayName = trim( $params['name'] ); $this->createArray( [] - ); // create empty array in case we get no result so we won't have an undefined array in the end. + ); + // create empty array in case we get no result so we won't have an undefined array in the end. } // if mainlabel set to '-', this will cause the titles not to appear, so make sure we catch this! @@ -425,32 +439,32 @@ public function getParamDefinitions( array $definitions ) { ]; // separators (default values are defined in the following globals:) - global $srfgArraySep, $srfgArrayPropSep, $srfgArrayManySep, $srfgArrayRecordSep, $srfgArrayHeaderSep; + global $wgSrfgArraySep, $wgSrfgArrayPropSep, $wgSrfgArrayManySep, $wgSrfgArrayRecordSep, $wgSrfgArrayHeaderSep; $params['sep'] = [ 'message' => 'smw-paramdesc-sep', - 'default' => $this->initializeCfgValue( $srfgArraySep, 'sep' ), + 'default' => $this->initializeCfgValue( $wgSrfgArraySep, 'sep' ), ]; $params['propsep'] = [ 'message' => 'srf_paramdesc_propsep', - 'default' => $this->initializeCfgValue( $srfgArrayPropSep, 'propsep' ), + 'default' => $this->initializeCfgValue( $wgSrfgArrayPropSep, 'propsep' ), ]; $params['manysep'] = [ 'message' => 'srf_paramdesc_manysep', - 'default' => $this->initializeCfgValue( $srfgArrayManySep, 'manysep' ), + 'default' => $this->initializeCfgValue( $wgSrfgArrayManySep, 'manysep' ), ]; $params['recordsep'] = [ 'message' => 'srf_paramdesc_recordsep', - 'default' => $this->initializeCfgValue( $srfgArrayRecordSep, 'recordsep' ), + 'default' => $this->initializeCfgValue( $wgSrfgArrayRecordSep, 'recordsep' ), 'aliases' => [ 'narysep', 'rcrdsep', 'recsep' ], ]; $params['headersep'] = [ 'message' => 'srf_paramdesc_headersep', - 'default' => $this->initializeCfgValue( $srfgArrayHeaderSep, 'headersep' ), + 'default' => $this->initializeCfgValue( $wgSrfgArrayHeaderSep, 'headersep' ), 'aliases' => [ 'narysep', 'rcrdsep', 'recsep' ], ]; diff --git a/formats/array/SRF_Hash.php b/formats/array/SRF_Hash.php index 1087eae60..1315fd0e7 100644 --- a/formats/array/SRF_Hash.php +++ b/formats/array/SRF_Hash.php @@ -19,8 +19,10 @@ class SRFHash extends SRFArray { protected $mLastPageTitle; protected function deliverPageTitle( $value, $link = false ) { - $this->mLastPageTitle = $this->deliverSingleValue( $value, $link ); // remember the page title - return null; // don't add page title into property list + // remember the page title + $this->mLastPageTitle = $this->deliverSingleValue( $value, $link ); + // don't add page title into property list + return null; } protected function deliverPageProperties( $perProperty_items ) { @@ -33,7 +35,8 @@ protected function deliverPageProperties( $perProperty_items ) { protected function deliverQueryResultPages( $perPage_items ) { $hash = []; foreach ( $perPage_items as $page ) { - $hash[$page[0]] = $page[1]; // name of page as key, Properties as value + // name of page as key, Properties as value + $hash[$page[0]] = $page[1]; } return parent::deliverQueryResultPages( $hash ); } @@ -80,8 +83,8 @@ protected function handleParameters( array $params, $outputmode ) { */ public function getParamDefinitions( array $definitions ) { $params = parent::getParamDefinitions( $definitions ); - - unset( $params['pagetitle'] ); // page title is Hash key, otherwise, just use Array format! + // page title is Hash key, otherwise, just use Array format! + unset( $params['pagetitle'] ); $params['name']['message'] = 'srf_paramdesc_hashname'; return $params; diff --git a/formats/calendar/SRFC_HistoricalDate.php b/formats/calendar/SRFC_HistoricalDate.php index bd3212975..29f6f3c06 100644 --- a/formats/calendar/SRFC_HistoricalDate.php +++ b/formats/calendar/SRFC_HistoricalDate.php @@ -22,11 +22,13 @@ */ class SRFCHistoricalDate { - const GREGORIAN_EPOCH = 1721425.5; // equivalent to 1 AD + // equivalent to 1 AD + public const GREGORIAN_EPOCH = 1721425.5; - protected $m_date; // the Julian day + // the Julian day + protected $m_date; - function create( $year, $month, $day ) { + public function create( $year, $month, $day ) { if ( $year < 1582 || ( $year == 1582 && ( $month < 10 || ( $month == 10 && $day < 15 ) ) ) ) { $this->createFromJulian( $year, $month, $day ); @@ -84,7 +86,7 @@ public function getDayOfWeek() { return ( floor( $this->m_date + 1.5 ) % 7 ); } - static function daysInMonth( $year, $month ) { + public static function daysInMonth( $year, $month ) { if ( $month == 4 || $month == 6 || $month == 9 || $month == 11 ) { return 30; } diff --git a/formats/calendar/SRF_Calendar.php b/formats/calendar/SRF_Calendar.php index 355812729..e05ffe5c9 100644 --- a/formats/calendar/SRF_Calendar.php +++ b/formats/calendar/SRF_Calendar.php @@ -308,16 +308,16 @@ protected static function intToMonth( $int ) { )->inContentLanguage()->text(); } - function formatDateStr( $object ) { + public function formatDateStr( $object ) { // For some reason, getMonth() and getDay() sometimes return a // number with a leading zero - get rid of it using (int) return $object->getYear() . '-' . (int)$object->getMonth() . '-' . (int)$object->getDay(); } - function displayCalendar( $events ) { - global $srfgFirstDayOfWeek; - global $srfgScriptPath; + public function displayCalendar( $events ) { + global $wgSrfgFirstDayOfWeek; + global $wgSrfgScriptPath; $context = RequestContext::getMain(); $request = $context->getRequest(); @@ -332,7 +332,7 @@ function displayCalendar( $events ) { 'rel' => 'stylesheet', 'type' => 'text/css', 'media' => 'screen, print', - 'href' => $srfgScriptPath + 'href' => $wgSrfgScriptPath . '/formats/calendar/resources/ext.srf.calendar.css' ] ); @@ -385,16 +385,16 @@ function displayCalendar( $events ) { 6 => wfMessage( 'friday' )->text(), 7 => wfMessage( 'saturday' )->text() ]; - if ( empty( $srfgFirstDayOfWeek ) ) { + if ( empty( $wgSrfgFirstDayOfWeek ) ) { $firstDayOfWeek = 1; $lastDayOfWeek = 7; } else { $firstDayOfWeek = - array_search( $srfgFirstDayOfWeek, $weekDayNames ); + array_search( $wgSrfgFirstDayOfWeek, $weekDayNames ); if ( $firstDayOfWeek === false ) { - // Bad value for $srfgFirstDayOfWeek! - print 'Warning: Bad value for $srfgFirstDayOfWeek "' . - '(' . $srfgFirstDayOfWeek . '")'; + // Bad value for $wgSrfgFirstDayOfWeek! + print 'Warning: Bad value for $wgSrfgFirstDayOfWeek "' . + '(' . $wgSrfgFirstDayOfWeek . '")'; $firstDayOfWeek = 1; } if ( $firstDayOfWeek == 1 ) { @@ -516,10 +516,10 @@ function displayCalendar( $events ) {
'; }, $fields ) ) . "\n\n>"; - $nodeLinkURL = null; // the value at the top is already hyperlinked. + $nodeLinkURL = null; + // the value at the top is already hyperlinked. } else { if ( $nodeLabel ) { // Label, if any, is enclosed with "". diff --git a/src/Graph/GraphNode.php b/src/Graph/GraphNode.php index 48b80e75c..9828573b3 100644 --- a/src/Graph/GraphNode.php +++ b/src/Graph/GraphNode.php @@ -9,7 +9,7 @@ class GraphNode { private $fields = []; /** - * @var string $id : Node ID including namespace + * @param string $id : Node ID including namespace */ public function __construct( $id ) { $this->id = $id; diff --git a/src/Graph/GraphOptions.php b/src/Graph/GraphOptions.php index 88e0fe06e..f1ddd6e68 100644 --- a/src/Graph/GraphOptions.php +++ b/src/Graph/GraphOptions.php @@ -50,7 +50,7 @@ public function __construct( $options ) { public function getGraphName(): string { // Remove all special characters from the string to prevent the digraph from being // invalid and causing an error. - return preg_replace('/[^A-Za-z0-9 ]/', '', $this->graphName ); + return preg_replace( '/[^A-Za-z0-9 ]/', '', $this->graphName ); } public function getGraphSize(): string { diff --git a/src/Graph/GraphPrinter.php b/src/Graph/GraphPrinter.php index b6453d425..6f841069b 100644 --- a/src/Graph/GraphPrinter.php +++ b/src/Graph/GraphPrinter.php @@ -3,11 +3,11 @@ namespace SRF\Graph; use Html; -Use MediaWiki\MediaWikiServices; +use MediaWiki\MediaWikiServices; +use SMW\Query\PrintRequest; use SMW\Query\Result\ResultArray; use SMW\ResultPrinter; use SMWQueryResult; -use SMW\Query\PrintRequest; /** * SMW result printer for graphs using graphViz. @@ -28,7 +28,7 @@ class GraphPrinter extends ResultPrinter { // @see https://github.com/SemanticMediaWiki/SemanticMediaWiki/pull/4273 // Implement `ResultPrinterDependency` once SMW 3.1 becomes mandatory - const NODELABEL_DISPLAYTITLE = 'displaytitle'; + public const NODELABEL_DISPLAYTITLE = 'displaytitle'; public static $NODE_LABELS = [ self::NODELABEL_DISPLAYTITLE, ]; @@ -200,12 +200,13 @@ protected function processResultRow( array $row ) { $request = $result_array->getPrintRequest(); $type = $request->getTypeID(); // Whether this printout should be shown as an edge. - $show_as_edge = !$this->options->showGraphFields() // no fields at all. - || in_array( $type, self::PAGETYPES ) // property of the type 'Page'. - || $request->isMode( PrintRequest::PRINT_CHAIN ); // property chain, treated like 'Page'. + // no fields at all. + $show_as_edge = !$this->options->showGraphFields() + || in_array( $type, self::PAGETYPES ) + || $request->isMode( PrintRequest::PRINT_CHAIN ); // Loop through all values of a multivalue field. - while ( ( /* SMWWikiPageValue */ $object = $result_array->getNextDataValue() ) !== false ) { + while ( ( $object = $result_array->getNextDataValue() ) !== false ) { if ( $show_as_edge ) { if ( !$node && !$object->getProperty() ) { // The graph node for the current record has not been created, @@ -233,7 +234,7 @@ protected function processResultRow( array $row ) { } // Add the node, if any, its parent nodes and fields for non-Page properties to the current edge. if ( $node ) { - foreach( $parents as $parent ) { + foreach ( $parents as $parent ) { $node->addParentNode( $parent['predicate'], $parent['object'] ); // @TODO: add explicit nodes with hyperlinks to every parent node not added as '?', but only once. } diff --git a/src/Outline/ListTreeBuilder.php b/src/Outline/ListTreeBuilder.php index de3bc4069..58da564ce 100644 --- a/src/Outline/ListTreeBuilder.php +++ b/src/Outline/ListTreeBuilder.php @@ -13,9 +13,6 @@ */ class ListTreeBuilder { - /** - * @var - */ private $params = []; /** @@ -42,7 +39,7 @@ public function setLinker( $linker ) { /** * @since 3.1 * - * @param OutlineTree $tree + * @param OutlineTree $outlineTree * * @return string */ @@ -103,7 +100,8 @@ private function tree( $outline_tree, $level = 0 ) { private function item( $item ) { $first_col = true; - $found_values = false; // has anything but the first column been printed? + // has anything but the first column been printed? + $found_values = false; $result = ""; foreach ( $item->row as $resultArray ) { @@ -125,7 +123,8 @@ private function item( $item ) { $resultArray->reset(); while ( ( $dv = $resultArray->getNextDataValue() ) !== false ) { - if ( !$first_col && !$found_values ) { // first values after first column + if ( !$first_col && !$found_values ) { + // first values after first column $result .= ' ('; $found_values = true; } elseif ( $found_values || !$first_value ) { @@ -133,7 +132,8 @@ private function item( $item ) { $result .= ', '; } - if ( $first_value ) { // first value in any column, print header + if ( $first_value ) { + // first value in any column, print header $first_value = false; if ( $this->params['showHeaders'] && ( '' != $printRequest->getLabel() ) ) { $result .= $printRequest->getText( SMW_OUTPUT_WIKI, $linker ) . ' '; @@ -141,7 +141,6 @@ private function item( $item ) { } $dataItem = $dv->getDataItem(); - if ( $linker === null && $dataItem->getDIType() === DataItem::TYPE_WIKIPAGE && ( $caption = $dv->getDisplayTitle() ) !== '' ) { $dv->setCaption( $caption ); } diff --git a/src/Outline/OutlineItem.php b/src/Outline/OutlineItem.php index d18a9f5c5..8f7427327 100644 --- a/src/Outline/OutlineItem.php +++ b/src/Outline/OutlineItem.php @@ -11,14 +11,8 @@ */ class OutlineItem { - /** - * @var type - */ public $row; - /** - * @var - */ private $vals; /** @@ -34,7 +28,7 @@ public function __construct( $row ) { /** * @since 3.1 * - * @param $name + * @param $key * @param $value */ public function addFieldValue( $key, $value ) { @@ -48,7 +42,7 @@ public function addFieldValue( $key, $value ) { /** * @since 3.1 * - * @param $row + * @param $key */ public function getFieldValues( $key ) { if ( array_key_exists( $key, $this->vals ) ) { diff --git a/src/Outline/OutlineTree.php b/src/Outline/OutlineTree.php index eb2116679..bd6628495 100644 --- a/src/Outline/OutlineTree.php +++ b/src/Outline/OutlineTree.php @@ -10,14 +10,8 @@ */ class OutlineTree { - /** - * @var - */ public $tree; - /** - * @var - */ public $items; /** diff --git a/src/Outline/TemplateBuilder.php b/src/Outline/TemplateBuilder.php index 971102753..d4b117069 100644 --- a/src/Outline/TemplateBuilder.php +++ b/src/Outline/TemplateBuilder.php @@ -12,9 +12,6 @@ */ class TemplateBuilder { - /** - * @var - */ private $params = []; /** @@ -46,7 +43,7 @@ public function setLinker( $linker ) { /** * @since 3.1 * - * @param OutlineTree $tree + * @param OutlineTree $outlineTree * * @return string */ @@ -71,7 +68,7 @@ private function tree( $outlineTree, $level = 0 ) { $this->template .= $this->open( $this->params['template'] . "-header" ); $this->template .= $this->parameter( $property, $key ); $this->template .= $this->parameter( "#outlinelevel", $level ); - $this->template .= $this->parameter( "#itemcount", $node->leafCount ); + $this->template .= $this->parameter( "#itemcount", $node->leafCount ); $this->template .= $this->parameter( "#userparam", $this->params['userparam'] ); $this->template .= $this->close(); $this->template .= "
"; @@ -158,14 +155,14 @@ private function close() { return "}}"; } - function getIntroTemplate(): string { + public function getIntroTemplate(): string { if ( $this->params['introtemplate'] === '' ) { return ""; } return $this->open( $this->params['introtemplate'] ) . $this->close(); } - function getOutroTemplate(): string { + public function getOutroTemplate(): string { if ( $this->params['outrotemplate'] === '' ) { return ""; } diff --git a/src/ResourceFormatter.php b/src/ResourceFormatter.php index 0d62380f3..21b1b7818 100644 --- a/src/ResourceFormatter.php +++ b/src/ResourceFormatter.php @@ -2,11 +2,10 @@ namespace SRF; -use Html; use RequestContext; +use SMW\Query\PrintRequest; use SMWOutputs as ResourceManager; use SMWQueryResult as QueryResult; -use SMW\Query\PrintRequest; use SRFUtils; /** @@ -82,20 +81,19 @@ public static function encode( $id, $data ) { * @return array */ private static function appendPreferredPropertyLabel( $printRequests, $ask ) { - // @see formats/calendar/resources/ext.srf.formats.eventcalendar.js // method "init" - // + // // var datePropertyList = _calendar.api.query.printouts.search.type( // data.query.ask.printouts, // data.query.result.printrequests, // ['_dat'] ); - // + // // and search.type.normalize in resources/ext.srf.api.query.js // which calls getTypeId in resources/ext.srf.api.results.js // and expects that the printrequest label and printouts custom label // retrieved from the below, match - // + // // @TODO all this method can be removed as long as the issue // can be fixed at SMW level: PrintRequest's Serializer -> doSerializeProp @@ -151,4 +149,3 @@ public static function getData( QueryResult $queryResult, $outputMode, $paramete } } - diff --git a/src/iCalendar/IcalFormatter.php b/src/iCalendar/IcalFormatter.php index b40a6c253..fc09c37dd 100644 --- a/src/iCalendar/IcalFormatter.php +++ b/src/iCalendar/IcalFormatter.php @@ -25,9 +25,6 @@ class IcalFormatter { */ private $description; - /** - * @var - */ private $events = []; /** diff --git a/src/iCalendar/IcalTimezoneFormatter.php b/src/iCalendar/IcalTimezoneFormatter.php index 33adeac29..cd2421f60 100644 --- a/src/iCalendar/IcalTimezoneFormatter.php +++ b/src/iCalendar/IcalTimezoneFormatter.php @@ -80,8 +80,7 @@ public function calcTransitions( $from = null, $to = null ) { foreach ( $this->localTimezones as $timezone ) { try { $dateTimezone = new DateTimeZone( $timezone ); - } - catch ( Exception $e ) { + } catch ( Exception $e ) { continue; } diff --git a/src/iCalendar/iCalendarFileExportPrinter.php b/src/iCalendar/iCalendarFileExportPrinter.php index a14ef245d..fb2d96d3d 100644 --- a/src/iCalendar/iCalendarFileExportPrinter.php +++ b/src/iCalendar/iCalendarFileExportPrinter.php @@ -204,7 +204,8 @@ private function getIcalLink( QueryResult $res, $outputMode ) { if ( array_key_exists( 'limit', $this->params ) ) { $link->setParameter( $this->params['limit'], 'limit' ); - } else { // use a reasonable default limit + } else { + // use a reasonable default limit $link->setParameter( 20, 'limit' ); } @@ -219,12 +220,12 @@ private function getIcalLink( QueryResult $res, $outputMode ) { * * @param ResultArray[] $row * - * @return + * @return array */ private function getEventParams( array $row ) { $result = ''; - - $subject = $row[0]->getResultSubject(); // get the object + // get the object + $subject = $row[0]->getResultSubject(); $dataValue = DataValueFactory::getInstance()->newDataValueByItem( $subject, null ); $params = [ @@ -234,7 +235,7 @@ private function getEventParams( array $row ) { $params['from'] = null; $params['to'] = null; - foreach ( $row as /* SMWResultArray */ $field ) { + foreach ( $row as $field ) { $this->filterField( $field, $params ); } diff --git a/src/vCard/Email.php b/src/vCard/Email.php index 6cae62932..554277537 100644 --- a/src/vCard/Email.php +++ b/src/vCard/Email.php @@ -32,7 +32,8 @@ class Email { */ public function __construct( $type, $emailaddress ) { $this->type = $type; - $this->emailaddress = $emailaddress; // no escape, normally not needed anyway + // no escape, normally not needed anyway + $this->emailaddress = $emailaddress; } /** diff --git a/src/vCard/Tel.php b/src/vCard/Tel.php index 6985f8f7f..98fd10d85 100644 --- a/src/vCard/Tel.php +++ b/src/vCard/Tel.php @@ -31,8 +31,10 @@ class Tel { * @param string $telnumber */ public function __construct( $type, $telnumber ) { - $this->type = $type; // may be a vCard value list using ",", no escaping - $this->telnumber = vCard::escape( $telnumber ); // escape to be sure + // may be a vCard value list using ",", no escaping + $this->type = $type; + // escape to be sure + $this->telnumber = vCard::escape( $telnumber ); } /** diff --git a/src/vCard/vCard.php b/src/vCard/vCard.php index c96bc3f02..386b9a575 100644 --- a/src/vCard/vCard.php +++ b/src/vCard/vCard.php @@ -206,7 +206,7 @@ private function prepareCard( $vcard ) { $vcard['label'] = self::escape( $vcard['label'] ); // read firstname and lastname, or guess it from other names that are given - if ( $vcard['firstname'] . $vcard['lastname'] == '' ) { // guessing needed + if ( $vcard['firstname'] . $vcard['lastname'] == '' ) { $nameparts = explode( ' ', $vcard['label'] ); // Accepted forms for guessing: // "Lastname" diff --git a/src/vCard/vCardFileExportPrinter.php b/src/vCard/vCardFileExportPrinter.php index 3ff407878..551e3e044 100644 --- a/src/vCard/vCardFileExportPrinter.php +++ b/src/vCard/vCardFileExportPrinter.php @@ -132,7 +132,8 @@ private function getVCardLink( QueryResult $res, $outputMode ) { if ( array_key_exists( 'limit', $this->params ) ) { $link->setParameter( $this->params['limit'], 'limit' ); - } else { // use a reasonable default limit + } else { + // use a reasonable default limit $link->setParameter( 20, 'limit' ); } @@ -286,6 +287,7 @@ private function mapField( $field, $vCard, &$tels, &$addresses, &$emails ) { break; case "category": $vCard->set( 'category', $this->getFieldCommaList( $field ) ); + break; case "email": while ( $value = $field->getNextDataValue() ) { $emails[] = new Email( 'INTERNET', $value->getShortWikiText() ); diff --git a/tests/phpunit/Integration/I18nJsonFileIntegrityTest.php b/tests/phpunit/Integration/I18nJsonFileIntegrityTest.php index 6812a4587..7c2eb1779 100644 --- a/tests/phpunit/Integration/I18nJsonFileIntegrityTest.php +++ b/tests/phpunit/Integration/I18nJsonFileIntegrityTest.php @@ -19,6 +19,7 @@ class I18nJsonFileIntegrityTest extends \PHPUnit\Framework\TestCase { use PHPUnitCompat; /** + * @covers I18nJsonFileIntegrity * @dataProvider i18nFileProvider */ public function testI18NJsonDecodeEncode( $file ) { diff --git a/tests/phpunit/Integration/JSONScript/JsonTestCaseScriptRunnerTest.php b/tests/phpunit/Integration/JSONScript/JsonTestCaseScriptRunnerTest.php index 8dc018d37..e069067f6 100644 --- a/tests/phpunit/Integration/JSONScript/JsonTestCaseScriptRunnerTest.php +++ b/tests/phpunit/Integration/JSONScript/JsonTestCaseScriptRunnerTest.php @@ -53,7 +53,7 @@ public function checkMermaidDependency( $val, &$reason ) { return false; } - list( $compare, $requiredVersion ) = explode( ' ', $val ); + [ $compare, $requiredVersion ] = explode( ' ', $val ); $version = ExtensionRegistry::getInstance()->getAllThings()['Mermaid']['version']; if ( !version_compare( $version, $requiredVersion, $compare ) ) { diff --git a/tests/phpunit/Integration/ResourcesTest.php b/tests/phpunit/Integration/ResourcesTest.php index 2a2afb11a..cf9e73bb1 100644 --- a/tests/phpunit/Integration/ResourcesTest.php +++ b/tests/phpunit/Integration/ResourcesTest.php @@ -28,8 +28,8 @@ class ResourcesTest extends \PHPUnit\Framework\TestCase { * @return array */ private function getSRFResourceModules() { - global $srfgIP; - return include $srfgIP . '/' . 'Resources.php'; + global $wgSrfgIP; + return include $wgSrfgIP . '/' . 'Resources.php'; } public function moduleDataProvider() { @@ -48,6 +48,7 @@ public function moduleDataProvider() { } /** + * @covers Recources * @dataProvider moduleDataProvider */ public function testModulesScriptsFilesAreAccessible( $modules, ResourceLoader $resourceLoader, $context ) { @@ -59,6 +60,7 @@ public function testModulesScriptsFilesAreAccessible( $modules, ResourceLoader $ } /** + * @covers Recources * Test styles accessibility * * @dataProvider moduleDataProvider diff --git a/tests/phpunit/Unit/BibTex/BibTexFileExportPrinterTest.php b/tests/phpunit/Unit/BibTex/BibTexFileExportPrinterTest.php index d584bd886..48406a689 100644 --- a/tests/phpunit/Unit/BibTex/BibTexFileExportPrinterTest.php +++ b/tests/phpunit/Unit/BibTex/BibTexFileExportPrinterTest.php @@ -115,15 +115,15 @@ private function newMockQueryResultWithLink() { $queryResult->expects( $this->any() ) ->method( 'getErrors' ) - ->will( $this->returnValue( [] ) ); + ->willReturn( [] ); $queryResult->expects( $this->any() ) ->method( 'getCount' ) - ->will( $this->returnValue( 1 ) ); + ->willReturn( 1 ); $queryResult->expects( $this->once() ) ->method( 'getQueryLink' ) - ->will( $this->returnValue( $this->newInfoLinkStub() ) ); + ->willReturn( $this->newInfoLinkStub() ); return $queryResult; } @@ -135,7 +135,7 @@ private function newInfoLinkStub() { $link->expects( $this->any() ) ->method( 'getText' ) - ->will( $this->returnValue( 'foo_link' ) ); + ->willReturn( 'foo_link' ); return $link; } diff --git a/tests/phpunit/Unit/Filtered/ResultItemTest.php b/tests/phpunit/Unit/Filtered/ResultItemTest.php index 860b2a109..b72275916 100644 --- a/tests/phpunit/Unit/Filtered/ResultItemTest.php +++ b/tests/phpunit/Unit/Filtered/ResultItemTest.php @@ -25,7 +25,7 @@ class ResultItemTest extends \PHPUnit\Framework\TestCase { public function testArray_representation_is_JSON_serializable_for_UCA_collation_Issue568() { // TODO When SRF will only support MW 1.37+, remove this backward compatibility switch - if( method_exists( '\MediaWiki\MediaWikiServices', 'getCollationFactory' ) ) { + if ( method_exists( '\MediaWiki\MediaWikiServices', 'getCollationFactory' ) ) { $collation = MediaWikiServices::getInstance()->getCollationFactory()->makeCollation( "uca-de-u-kn" ); } else { $collation = Collation::factory( "uca-de-u-kn" ); diff --git a/tests/phpunit/Unit/Formats/GalleryTest.php b/tests/phpunit/Unit/Formats/GalleryTest.php index d0482371b..c533892e7 100644 --- a/tests/phpunit/Unit/Formats/GalleryTest.php +++ b/tests/phpunit/Unit/Formats/GalleryTest.php @@ -42,7 +42,7 @@ protected function setUp(): void { $this->title->expects( $this->any() ) ->method( 'getNamespace' ) - ->will( $this->returnValue( NS_MAIN ) ); + ->willReturn( NS_MAIN ); } /** @@ -67,6 +67,9 @@ public function getClass() { return 'SRF\Gallery'; } + /** + * @covers Gallery getName + */ public function testGetName() { $instance = new Gallery( 'gallery' @@ -75,6 +78,9 @@ public function testGetName() { $this->assertIsString( $instance->getName() ); } + /** + * @covers Gallery buildResult + */ public function testBuildResult() { $instance = new Gallery( 'gallery' @@ -87,11 +93,11 @@ public function testBuildResult() { $widget->expects( $this->any() ) ->method( 'getName' ) - ->will( $this->returnValue( 'widget' ) ); + ->willReturn( 'widget' ); $widget->expects( $this->any() ) ->method( 'getValue' ) - ->will( $this->returnValue( 'carousel' ) ); + ->willReturn( 'carousel' ); $intro = $this->getMockBuilder( '\stdClass' ) ->disableOriginalConstructor() @@ -100,11 +106,11 @@ public function testBuildResult() { $intro->expects( $this->any() ) ->method( 'getName' ) - ->will( $this->returnValue( 'intro' ) ); + ->willReturn( 'intro' ); $intro->expects( $this->any() ) ->method( 'getValue' ) - ->will( $this->returnValue( '' ); $parameters = [ $widget, diff --git a/tests/phpunit/Unit/Formats/PrologTest.php b/tests/phpunit/Unit/Formats/PrologTest.php index 1ef9a58da..a73b98356 100644 --- a/tests/phpunit/Unit/Formats/PrologTest.php +++ b/tests/phpunit/Unit/Formats/PrologTest.php @@ -1,30 +1,30 @@ -getMockBuilder( '\SMWInfolink' ) ->disableOriginalConstructor() @@ -33,15 +37,15 @@ public function testLink() { $queryResult->expects( $this->once() ) ->method( 'getQueryLink' ) - ->will( $this->returnValue( $link ) ); + ->willReturn( $link ); $queryResult->expects( $this->any() ) ->method( 'getCount' ) - ->will( $this->returnValue( 1 ) ); + ->willReturn( 1 ); $queryResult->expects( $this->any() ) ->method( 'getErrors' ) - ->will( $this->returnValue( [] ) ); + ->willReturn( [] ); $instance = new SpreadsheetPrinter( 'csv' ); $instance->getResult( $queryResult, [], SMW_OUTPUT_WIKI ); diff --git a/tests/phpunit/Unit/Formats/TreeTest.php b/tests/phpunit/Unit/Formats/TreeTest.php index b1955ba82..1c2aa1994 100644 --- a/tests/phpunit/Unit/Formats/TreeTest.php +++ b/tests/phpunit/Unit/Formats/TreeTest.php @@ -68,6 +68,7 @@ public function getClass() { } /** + * @covers Tree getResult_NoParentProperty */ public function testGetResult_NoParentProperty() { $this->prepareGlobalState(); @@ -80,7 +81,7 @@ public function testGetResult_NoParentProperty() { $queryResult->expects( $this->once() ) ->method( 'addErrors' ) - ->will( $this->returnValue( null ) ); + ->willReturn( null ); $params = SMWQueryProcessor::getProcessedParams( [ 'format' => 'tree' ], [] ); @@ -109,7 +110,7 @@ protected function prepareGlobalState() { $parserOutput->expects( $this->any() ) ->method( 'getHeadItems' ) - ->will( $this->returnValue( [] ) ); + ->willReturn( [] ); $parser = $this->getMockBuilder( '\Parser' ) ->disableOriginalConstructor() @@ -117,7 +118,7 @@ protected function prepareGlobalState() { $parser->expects( $this->any() ) ->method( 'parse' ) - ->will( $this->returnValue( $parserOutput ) ); + ->willReturn( $parserOutput ); $title = $this->getMockBuilder( '\Title' ) ->disableOriginalConstructor() diff --git a/tests/phpunit/Unit/Formats/ValueRankTest.php b/tests/phpunit/Unit/Formats/ValueRankTest.php index 9dca99d5a..86214adb9 100644 --- a/tests/phpunit/Unit/Formats/ValueRankTest.php +++ b/tests/phpunit/Unit/Formats/ValueRankTest.php @@ -48,6 +48,9 @@ public function getClass() { return 'SRFValueRank'; } + /** + * @covers ValueRank + */ public function testGetName() { $instance = new SRFValueRank( 'valuerank' diff --git a/tests/phpunit/Unit/Graph/GraphFormatterTest.php b/tests/phpunit/Unit/Graph/GraphFormatterTest.php index e8f5903d3..5c47b8c34 100644 --- a/tests/phpunit/Unit/Graph/GraphFormatterTest.php +++ b/tests/phpunit/Unit/Graph/GraphFormatterTest.php @@ -16,10 +16,11 @@ */ class GraphFormatterTest extends \PHPUnit\Framework\TestCase { - /** @var array $cases An array of test cases. */ + /** @var array An array of test cases. */ private $cases = [ 'Simple' => [ - 'params' => [ 'graphfields' => false ], // @see https://www.semantic-mediawiki.org/wiki/Help:Graph_format + // @see https://www.semantic-mediawiki.org/wiki/Help:Graph_format + 'params' => [ 'graphfields' => false ], 'nodes' => [ [ 'name' => 'Team:Alpha', 'label' => 'Alpha', 'parents' => [ [ 'predicate' => 'Casted', 'object' => 'Person:Alexander Gesinn' ] @@ -49,7 +50,8 @@ class GraphFormatterTest extends \PHPUnit\Framework\TestCase { SIMPLE ], 'With fields' => [ - 'params' => [ 'graphfields' => true ], // @see https://www.semantic-mediawiki.org/wiki/Help:Graph_format + // @see https://www.semantic-mediawiki.org/wiki/Help:Graph_format + 'params' => [ 'graphfields' => true ], 'nodes' => [ [ 'name' => 'Team:Alpha', 'label' => 'Alpha', 'parents' => [ [ 'predicate' => 'Casted', 'object' => 'Person:Alexander Gesinn' ] @@ -114,11 +116,11 @@ class GraphFormatterTest extends \PHPUnit\Framework\TestCase { /** * Create a complete graph for the test case. - * @var array $case + * @param array $case * @return GraphFormatter */ private static function graph( array $case ): GraphFormatter { - $graph = new GraphFormatter( new GraphOptions( GraphFormatterTest::BASE_PARAMS + $case['params'] ) ); + $graph = new GraphFormatter( new GraphOptions( self::BASE_PARAMS + $case['params'] ) ); $nodes = []; foreach ( $case['nodes'] as $node ) { $graph_node = new GraphNode( $node['name'] ); @@ -151,7 +153,7 @@ public function provideCanConstruct(): array { } /** - * @covers GraphFormatter::__construct() + * @covers \SRF\Graph\GraphFormatter::__construct() * @dataProvider provideCanConstruct * @param array $params * @return void @@ -181,7 +183,7 @@ public function provideGetWordWrappedText(): array { } /** - * @covers GraphFormatter::getWordWrappedText() + * @covers \SRF\Graph\GraphFormatter::getWordWrappedText() * @dataProvider provideGetWordWrappedText * @param string $unwrapped * @param string $wrapped @@ -189,7 +191,7 @@ public function provideGetWordWrappedText(): array { */ public function testGetWordWrappedText( $unwrapped, $wrapped ) { $formatter = new GraphFormatter( - new GraphOptions( GraphFormatterTest::BASE_PARAMS + ['graphfields' => false] ) + new GraphOptions( self::BASE_PARAMS + [ 'graphfields' => false ] ) ); $this->assertEquals( $wrapped, $formatter->getWordWrappedText( $unwrapped, 10 ) ); } @@ -206,7 +208,7 @@ public function provideGetGraphLegend(): array { } /** - * @covers GraphFormatter::getGraphLegend() + * @covers \SRF\Graph\GraphFormatter::getGraphLegend() * @dataProvider provideGetGraphLegend * @param array $params * @param string $expected The expected legend. @@ -228,7 +230,7 @@ public function provideBuildGraph(): array { } /** - * @covers GraphFormatter::buildGraph() + * @covers \SRF\Graph\GraphFormatter::buildGraph() * @dataProvider provideBuildGraph * @param array $params * @param string $expected The expected DOT code. diff --git a/tests/phpunit/Unit/Graph/GraphNodeTest.php b/tests/phpunit/Unit/Graph/GraphNodeTest.php index 095bd218d..b1f4b0c7a 100644 --- a/tests/phpunit/Unit/Graph/GraphNodeTest.php +++ b/tests/phpunit/Unit/Graph/GraphNodeTest.php @@ -13,7 +13,6 @@ * * @author Sebastian Schmid < sebastian.schmid@gesinn.it > */ - class GraphNodeTest extends \PHPUnit\Framework\TestCase { public function testCanConstruct() { diff --git a/tests/phpunit/Unit/Outline/OutlineResultPrinterTest.php b/tests/phpunit/Unit/Outline/OutlineResultPrinterTest.php index 602808321..e4b192928 100644 --- a/tests/phpunit/Unit/Outline/OutlineResultPrinterTest.php +++ b/tests/phpunit/Unit/Outline/OutlineResultPrinterTest.php @@ -40,15 +40,15 @@ public function testGetResult_LinkOnNonFileOutput() { $link->expects( $this->any() ) ->method( 'getText' ) - ->will( $this->returnValue( 'foo_link' ) ); + ->willReturn( 'foo_link' ); $this->queryResult->expects( $this->any() ) ->method( 'getErrors' ) - ->will( $this->returnValue( [] ) ); + ->willReturn( [] ); $this->queryResult->expects( $this->any() ) ->method( 'getCount' ) - ->will( $this->returnValue( 1 ) ); + ->willReturn( 1 ); $instance = new OutlineResultPrinter( 'outline' @@ -62,11 +62,11 @@ public function testGetResult_LinkOnNonFileOutput() { $outlineproperties->expects( $this->any() ) ->method( 'getName' ) - ->will( $this->returnValue( 'outlineproperties' ) ); + ->willReturn( 'outlineproperties' ); $outlineproperties->expects( $this->any() ) ->method( 'getValue' ) - ->will( $this->returnValue( [] ) ); + ->willReturn( [] ); $template = $this->getMockBuilder( '\stdClass' ) ->disableOriginalConstructor() @@ -75,11 +75,11 @@ public function testGetResult_LinkOnNonFileOutput() { $template->expects( $this->any() ) ->method( 'getName' ) - ->will( $this->returnValue( 'template' ) ); + ->willReturn( 'template' ); $template->expects( $this->any() ) ->method( 'getValue' ) - ->will( $this->returnValue( '' ) ); + ->willReturn( '' ); $introtemplate = $this->getMockBuilder( '\stdClass' ) ->disableOriginalConstructor() @@ -88,11 +88,11 @@ public function testGetResult_LinkOnNonFileOutput() { $introtemplate->expects( $this->any() ) ->method( 'getName' ) - ->will( $this->returnValue( 'introtemplate' ) ); + ->willReturn( 'introtemplate' ); $introtemplate->expects( $this->any() ) ->method( 'getValue' ) - ->will( $this->returnValue( '' ) ); + ->willReturn( '' ); $outrotemplate = $this->getMockBuilder( '\stdClass' ) ->disableOriginalConstructor() @@ -101,11 +101,11 @@ public function testGetResult_LinkOnNonFileOutput() { $outrotemplate->expects( $this->any() ) ->method( 'getName' ) - ->will( $this->returnValue( 'outrotemplate' ) ); + ->willReturn( 'outrotemplate' ); $outrotemplate->expects( $this->any() ) ->method( 'getValue' ) - ->will( $this->returnValue( '' ) ); + ->willReturn( '' ); $parameters = [ $outlineproperties, diff --git a/tests/phpunit/Unit/iCalendar/DateParserTest.php b/tests/phpunit/Unit/iCalendar/DateParserTest.php index a58cebde1..d67a434af 100644 --- a/tests/phpunit/Unit/iCalendar/DateParserTest.php +++ b/tests/phpunit/Unit/iCalendar/DateParserTest.php @@ -20,7 +20,7 @@ public function testParseDate_Year() { $timeValue->expects( $this->any() ) ->method( 'getYear' ) - ->will( $this->returnValue( 2000 ) ); + ->willReturn( 2000 ); $instance = new DateParser(); @@ -35,19 +35,19 @@ public function testParseDate_Year_Month_Day_Time() { $timeValue->expects( $this->any() ) ->method( 'getYear' ) - ->will( $this->returnValue( 2000 ) ); + ->willReturn( 2000 ); $timeValue->expects( $this->any() ) ->method( 'getMonth' ) - ->will( $this->returnValue( 12 ) ); + ->willReturn( 12 ); $timeValue->expects( $this->any() ) ->method( 'getDay' ) - ->will( $this->returnValue( 12 ) ); + ->willReturn( 12 ); $timeValue->expects( $this->any() ) ->method( 'getTimeString' ) - ->will( $this->returnValue( '12:01:01' ) ); + ->willReturn( '12:01:01' ); $instance = new DateParser(); diff --git a/tests/phpunit/Unit/vCard/vCardFileExportPrinterTest.php b/tests/phpunit/Unit/vCard/vCardFileExportPrinterTest.php index 7266777a5..3a31b0403 100644 --- a/tests/phpunit/Unit/vCard/vCardFileExportPrinterTest.php +++ b/tests/phpunit/Unit/vCard/vCardFileExportPrinterTest.php @@ -73,19 +73,19 @@ public function testGetResult_LinkOnNonFileOutput() { $link->expects( $this->any() ) ->method( 'getText' ) - ->will( $this->returnValue( 'foo_link' ) ); + ->willReturn( 'foo_link' ); $this->queryResult->expects( $this->any() ) ->method( 'getErrors' ) - ->will( $this->returnValue( [] ) ); + ->willReturn( [] ); $this->queryResult->expects( $this->any() ) ->method( 'getCount' ) - ->will( $this->returnValue( 1 ) ); + ->willReturn( 1 ); $this->queryResult->expects( $this->once() ) ->method( 'getQueryLink' ) - ->will( $this->returnValue( $link ) ); + ->willReturn( $link ); $instance = new vCardFileExportPrinter( 'vcard'