From 44c3389d5a77f303ebfee93fc9c04ed147383e20 Mon Sep 17 00:00:00 2001 From: Universal Omega <54654040+Universal-Omega@users.noreply.github.com> Date: Fri, 11 Mar 2022 13:35:51 -0700 Subject: [PATCH] Add `use` statements (#64) --- .gitignore | 1 + includes/PortableInfoboxHooks.php | 3 +- includes/controllers/ApiPortableInfobox.php | 9 ++-- .../PortableInfoboxParserTagController.php | 12 +++-- .../Helpers/FileNamespaceSanitizeHelper.php | 5 +- .../Helpers/InfoboxParamsValidator.php | 5 +- .../Helpers/PortableInfoboxDataBag.php | 4 -- .../Helpers/PortableInfoboxImagesHelper.php | 14 ++--- .../Helpers/PortableInfoboxParsingHelper.php | 34 +++++++----- .../Helpers/PortableInfoboxTemplateEngine.php | 9 ++-- includes/services/Parser/ExternalParser.php | 1 + .../Parser/MediaWikiParserService.php | 20 ++++--- includes/services/Parser/Nodes/Node.php | 29 +++++----- includes/services/Parser/Nodes/NodeAudio.php | 1 + includes/services/Parser/Nodes/NodeData.php | 1 + .../services/Parser/Nodes/NodeFactory.php | 13 ++--- includes/services/Parser/Nodes/NodeGroup.php | 1 + includes/services/Parser/Nodes/NodeHeader.php | 1 + includes/services/Parser/Nodes/NodeImage.php | 1 + .../services/Parser/Nodes/NodeInfobox.php | 1 + includes/services/Parser/Nodes/NodeMedia.php | 24 +++++---- .../services/Parser/Nodes/NodeNavigation.php | 1 + includes/services/Parser/Nodes/NodePanel.php | 1 + .../services/Parser/Nodes/NodeSection.php | 1 + includes/services/Parser/Nodes/NodeTitle.php | 1 + .../Parser/Nodes/NodeUnimplemented.php | 5 +- includes/services/Parser/Nodes/NodeVideo.php | 1 + includes/services/Parser/SimpleParser.php | 1 + includes/services/Parser/XmlParser.php | 7 ++- .../PortableInfoboxErrorRenderService.php | 2 +- .../SpecialPortableInfoboxBuilder.php | 4 +- tests/phpunit/InfoboxParamsValidatorTest.php | 12 +++-- tests/phpunit/MediaWikiParserTest.php | 7 +-- .../PortableInfoboxRenderServiceTest.php | 5 +- .../PortableInfoboxTemplateEngineTest.php | 10 ++-- tests/phpunit/XmlParserTest.php | 9 ++-- .../FileNamespaceSanitizeHelperTest.php | 2 +- .../PortableInfoboxImagesHelperTest.php | 2 +- .../PortableInfoboxParsingHelperTest.php | 6 ++- tests/phpunit/nodes/NodeDataTest.php | 54 ++++++++++--------- tests/phpunit/nodes/NodeFactoryTest.php | 25 +++++---- tests/phpunit/nodes/NodeGroupTest.php | 20 ++++--- tests/phpunit/nodes/NodeHeaderTest.php | 12 +++-- tests/phpunit/nodes/NodeInfoboxTest.php | 9 ++-- tests/phpunit/nodes/NodeMediaTest.php | 30 ++++++----- tests/phpunit/nodes/NodeNavigationTest.php | 14 +++-- tests/phpunit/nodes/NodeTitleTest.php | 10 ++-- tests/phpunit/nodes/NodeUnimplementedTest.php | 8 +-- 48 files changed, 277 insertions(+), 171 deletions(-) diff --git a/.gitignore b/.gitignore index ff72e2d..e794f92 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /composer.lock /vendor +.github/* diff --git a/includes/PortableInfoboxHooks.php b/includes/PortableInfoboxHooks.php index 09a7cf8..9d1e7fd 100644 --- a/includes/PortableInfoboxHooks.php +++ b/includes/PortableInfoboxHooks.php @@ -2,6 +2,7 @@ use MediaWiki\MediaWikiServices; use MediaWiki\Revision\RenderedRevision; +use PortableInfobox\Helpers\PortableInfoboxDataBag; class PortableInfoboxHooks { @@ -14,7 +15,7 @@ class PortableInfoboxHooks { public static function onBeforeParserrenderImageGallery( Parser &$parser, ImageGalleryBase &$gallery ) { - PortableInfobox\Helpers\PortableInfoboxDataBag::getInstance()->setGallery( + PortableInfoboxDataBag::getInstance()->setGallery( // @phan-suppress-next-line PhanDeprecatedProperty Parser::MARKER_PREFIX . '-gallery-' . sprintf( '%08X', $parser->mMarkerIndex - 1 ) . Parser::MARKER_SUFFIX, diff --git a/includes/controllers/ApiPortableInfobox.php b/includes/controllers/ApiPortableInfobox.php index 696eadd..792639a 100644 --- a/includes/controllers/ApiPortableInfobox.php +++ b/includes/controllers/ApiPortableInfobox.php @@ -1,6 +1,9 @@ render( $text, $parser, $frame ); $this->getResult()->addValue( null, $this->getModuleName(), [ 'text' => [ '*' => $output ] ] ); - } catch ( \PortableInfobox\Parser\Nodes\UnimplementedNodeException $e ) { + } catch ( UnimplementedNodeException $e ) { $this->dieWithError( $this->msg( 'portable-infobox-unimplemented-infobox-tag', [ $e->getMessage() ] )->escaped(), 'notimplemented' ); - } catch ( \PortableInfobox\Parser\XmlMarkupParseErrorException $e ) { + } catch ( XmlMarkupParseErrorException $e ) { $this->dieWithError( $this->msg( 'portable-infobox-xml-parse-error' )->text(), 'badxml' ); - } catch ( \PortableInfobox\Helpers\InvalidInfoboxParamsException $e ) { + } catch ( InvalidInfoboxParamsException $e ) { $this->dieWithError( $this->msg( 'portable-infobox-xml-parse-error-infobox-tag-attribute-unsupported', diff --git a/includes/controllers/PortableInfoboxParserTagController.php b/includes/controllers/PortableInfoboxParserTagController.php index 7808a8d..23cd04f 100644 --- a/includes/controllers/PortableInfoboxParserTagController.php +++ b/includes/controllers/PortableInfoboxParserTagController.php @@ -3,7 +3,9 @@ use MediaWiki\MediaWikiServices; use PortableInfobox\Helpers\InfoboxParamsValidator; use PortableInfobox\Helpers\InvalidInfoboxParamsException; -use PortableInfobox\Parser\Nodes; +use PortableInfobox\Parser\MediaWikiParserService; +use PortableInfobox\Parser\Nodes\NodeFactory; +use PortableInfobox\Parser\Nodes\NodeInfobox; use PortableInfobox\Parser\Nodes\UnimplementedNodeException; use PortableInfobox\Parser\XmlMarkupParseErrorException; @@ -89,14 +91,14 @@ class PortableInfoboxParserTagController { */ public function prepareInfobox( $markup, Parser $parser, PPFrame $frame, $params = null ) { $frameArguments = $frame->getArguments(); - $infoboxNode = Nodes\NodeFactory::newFromXML( $markup, $frameArguments ?: [] ); + $infoboxNode = NodeFactory::newFromXML( $markup, $frameArguments ?: [] ); $infoboxNode->setExternalParser( - new PortableInfobox\Parser\MediaWikiParserService( $parser, $frame ) + new MediaWikiParserService( $parser, $frame ) ); // get params if not overridden if ( !isset( $params ) ) { - $params = ( $infoboxNode instanceof Nodes\NodeInfobox ) ? $infoboxNode->getParams() : []; + $params = ( $infoboxNode instanceof NodeInfobox ) ? $infoboxNode->getParams() : []; } $this->getParamsValidator()->validateParams( $params ); @@ -148,7 +150,7 @@ class PortableInfoboxParserTagController { return [ $renderedValue, 'markerType' => 'nowiki' ]; } - protected function saveToParserOutput( \ParserOutput $parserOutput, Nodes\NodeInfobox $raw ) { + protected function saveToParserOutput( ParserOutput $parserOutput, NodeInfobox $raw ) { // parser output stores this in page_props table, // therefore we can reuse the data in data provider service // (see: PortableInfoboxDataService.class.php) diff --git a/includes/services/Helpers/FileNamespaceSanitizeHelper.php b/includes/services/Helpers/FileNamespaceSanitizeHelper.php index ab88066..b9af992 100644 --- a/includes/services/Helpers/FileNamespaceSanitizeHelper.php +++ b/includes/services/Helpers/FileNamespaceSanitizeHelper.php @@ -2,6 +2,7 @@ namespace PortableInfobox\Helpers; +use Language; use MediaWiki\MediaWikiServices; // original class & authors: @@ -25,7 +26,7 @@ class FileNamespaceSanitizeHelper { } /** - * @param \Language $contLang + * @param Language $contLang * Used as local cache for getting string to remove */ private function getFilePrefixRegex( $contLang ) { @@ -65,7 +66,7 @@ class FileNamespaceSanitizeHelper { /** * @param string $filename - * @param \Language $contLang + * @param Language $contLang * * @return mixed */ diff --git a/includes/services/Helpers/InfoboxParamsValidator.php b/includes/services/Helpers/InfoboxParamsValidator.php index 04ce048..d32cee0 100644 --- a/includes/services/Helpers/InfoboxParamsValidator.php +++ b/includes/services/Helpers/InfoboxParamsValidator.php @@ -1,6 +1,9 @@ getRepoGroup(); $file = $repoGroup->findFile( $file ); } - if ( $file instanceof \File && $file->exists() ) { + if ( $file instanceof File && $file->exists() ) { return $file; } diff --git a/includes/services/Helpers/PortableInfoboxParsingHelper.php b/includes/services/Helpers/PortableInfoboxParsingHelper.php index 45adbfc..038093a 100644 --- a/includes/services/Helpers/PortableInfoboxParsingHelper.php +++ b/includes/services/Helpers/PortableInfoboxParsingHelper.php @@ -2,8 +2,14 @@ namespace PortableInfobox\Helpers; +use Exception; use MediaWiki\Logger\LoggerFactory; use MediaWiki\MediaWikiServices; +use ParserOptions; +use PortableInfoboxDataService; +use PortableInfoboxParserTagController; +use RequestContext; +use Title; class PortableInfoboxParsingHelper { @@ -11,25 +17,25 @@ class PortableInfoboxParsingHelper { protected $logger; public function __construct() { - $this->parserTagController = \PortableInfoboxParserTagController::getInstance(); + $this->parserTagController = PortableInfoboxParserTagController::getInstance(); $this->logger = LoggerFactory::getInstance( 'PortableInfobox' ); } /** * Try to find out if infobox got "hidden" inside includeonly tag. Parse it if that's the case. * - * @param \Title $title + * @param Title $title * * @return mixed false when no infoboxes found, Array with infoboxes on success */ - public function parseIncludeonlyInfoboxes( \Title $title ) { + public function parseIncludeonlyInfoboxes( Title $title ) { // for templates we need to check for include tags $templateText = $this->fetchArticleContent( $title ); if ( $templateText ) { $parser = MediaWikiServices::getInstance()->getParser(); $parser->setPage( $title ); - $parserOptions = \ParserOptions::newFromAnon(); + $parserOptions = ParserOptions::newFromAnon(); $parser->setOptions( $parserOptions ); $frame = $parser->getPreprocessor()->newFrame(); @@ -40,13 +46,13 @@ class PortableInfoboxParsingHelper { foreach ( $infoboxes as $infobox ) { try { $this->parserTagController->prepareInfobox( $infobox, $parser, $frame ); - } catch ( \Exception $e ) { + } catch ( Exception $e ) { $this->logger->info( 'Invalid infobox syntax' ); } } return json_decode( - $parser->getOutput()->getProperty( \PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME ), + $parser->getOutput()->getProperty( PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME ), true ); } @@ -54,25 +60,25 @@ class PortableInfoboxParsingHelper { return false; } - public function reparseArticle( \Title $title ) { + public function reparseArticle( Title $title ) { $parser = MediaWikiServices::getInstance()->getParser(); - $user = \RequestContext::getMain()->getUser(); + $user = RequestContext::getMain()->getUser(); - $parserOptions = new \ParserOptions( $user ); + $parserOptions = new ParserOptions( $user ); $parser->parse( $this->fetchArticleContent( $title ), $title, $parserOptions ); return json_decode( - $parser->getOutput()->getProperty( \PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME ), + $parser->getOutput()->getProperty( PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME ), true ); } /** - * @param \Title $title + * @param Title $title * * @return string */ - protected function fetchArticleContent( \Title $title ) { + protected function fetchArticleContent( Title $title ) { if ( $title->exists() ) { // @phan-suppress-next-line PhanDeprecatedFunction $content = MediaWikiServices::getInstance() @@ -86,10 +92,10 @@ class PortableInfoboxParsingHelper { } /** - * @param \Title $title + * @param Title $title * @return string[] array of strings (infobox markups) */ - public function getMarkup( \Title $title ) { + public function getMarkup( Title $title ) { $content = $this->fetchArticleContent( $title ); return $this->getInfoboxes( $content ); } diff --git a/includes/services/Helpers/PortableInfoboxTemplateEngine.php b/includes/services/Helpers/PortableInfoboxTemplateEngine.php index d591784..dda01a6 100644 --- a/includes/services/Helpers/PortableInfoboxTemplateEngine.php +++ b/includes/services/Helpers/PortableInfoboxTemplateEngine.php @@ -2,8 +2,11 @@ namespace PortableInfobox\Helpers; +use Closure; +use LightnCandy\LightnCandy; use MediaWiki\Logger\LoggerFactory; use MediaWiki\MediaWikiServices; +use PortableInfoboxParserTagController; class PortableInfoboxTemplateEngine { private const CACHE_TTL = 86400; @@ -31,7 +34,7 @@ class PortableInfoboxTemplateEngine { public function __construct() { if ( !isset( self::$lightncandy ) ) { - self::$lightncandy = \LightnCandy\LightnCandy::class; + self::$lightncandy = LightnCandy::class; self::$compileFlags = self::$lightncandy::FLAG_BESTPERFORMANCE | self::$lightncandy::FLAG_PARENT | self::$lightncandy::FLAG_HANDLEBARS; } @@ -60,7 +63,7 @@ class PortableInfoboxTemplateEngine { * Returns a template renderer * * @param string $type Template type - * @return \Closure + * @return Closure */ public function getRenderer( $type ) { global $wgPortableInfoboxCacheRenderers; @@ -70,7 +73,7 @@ class PortableInfoboxTemplateEngine { if ( $wgPortableInfoboxCacheRenderers ) { $cachekey = self::$memcache->makeKey( - __CLASS__, \PortableInfoboxParserTagController::PARSER_TAG_VERSION, $type + __CLASS__, PortableInfoboxParserTagController::PARSER_TAG_VERSION, $type ); $template = self::$memcache->getWithSetCallback( $cachekey, self::CACHE_TTL, static function () use ( $path ) { diff --git a/includes/services/Parser/ExternalParser.php b/includes/services/Parser/ExternalParser.php index abbe5d8..ae25935 100644 --- a/includes/services/Parser/ExternalParser.php +++ b/includes/services/Parser/ExternalParser.php @@ -1,4 +1,5 @@ parser = $parser; $this->frame = $frame; - if ( $wgPortableInfoboxUseTidy && class_exists( '\MediaWiki\Tidy\RemexDriver' ) ) { + if ( $wgPortableInfoboxUseTidy && class_exists( RemexDriver::class ) ) { global $wgTidyConfig; $wgTidyConfig = [ @@ -49,7 +55,7 @@ class MediaWikiParserService implements ExternalParser { } // @phan-suppress-next-line PhanAccessMethodInternal - $output = \BlockLevelPass::doBlockLevels( $parsed, false ); + $output = BlockLevelPass::doBlockLevels( $parsed, false ); $ready = $this->parser->getStripState()->unstripBoth( $output ); // @phan-suppress-next-line PhanDeprecatedFunction @@ -76,7 +82,7 @@ class MediaWikiParserService implements ExternalParser { /** * Add image to parser output for later usage * - * @param \Title $title + * @param Title $title */ public function addImage( $title ) { $repoGroup = MediaWikiServices::getInstance()->getRepoGroup(); @@ -87,11 +93,11 @@ class MediaWikiParserService implements ExternalParser { $this->parser->getOutput()->addImage( $title->getDBkey(), $tmstmp, $sha1 ); // Pass PI images to PageImages extension if available (Popups and og:image) - if ( \method_exists( - '\PageImages\Hooks\ParserFileProcessingHookHandlers', 'onParserMakeImageParams' + if ( method_exists( + ParserFileProcessingHookHandlers::class, 'onParserMakeImageParams' ) ) { $params = []; - \PageImages\Hooks\ParserFileProcessingHookHandlers::onParserMakeImageParams( + ParserFileProcessingHookHandlers::onParserMakeImageParams( $title, $file, $params, $this->parser ); } diff --git a/includes/services/Parser/Nodes/Node.php b/includes/services/Parser/Nodes/Node.php index 66e584f..75f4776 100644 --- a/includes/services/Parser/Nodes/Node.php +++ b/includes/services/Parser/Nodes/Node.php @@ -1,8 +1,11 @@ xmlNode = $xmlNode; $this->infoboxData = $infoboxData; } @@ -43,7 +46,7 @@ class Node { $metadata = []; $sources = $this->getSources(); $sourcesLength = count( $sources ); - $baseLabel = \Sanitizer::stripAllTags( + $baseLabel = Sanitizer::stripAllTags( $this->getInnerValue( $this->xmlNode->{self::LABEL_TAG_NAME} ) ); @@ -196,7 +199,7 @@ class Node { }, $this->getChildNodes() ); } - protected function getValueWithDefault( \SimpleXMLElement $xmlNode ) { + protected function getValueWithDefault( SimpleXMLElement $xmlNode ) { $value = $this->extractDataFromSource( $xmlNode ); $isEmpty = $value === null || $value === ''; if ( $isEmpty && $xmlNode->{self::DEFAULT_TAG_NAME} ) { @@ -209,7 +212,7 @@ class Node { return $value; } - protected function getRawValueWithDefault( \SimpleXMLElement $xmlNode ) { + protected function getRawValueWithDefault( SimpleXMLElement $xmlNode ) { $value = $this->getRawInfoboxData( $this->getXmlAttribute( $xmlNode, self::DATA_SRC_ATTR_NAME ) ); if ( !$value && $xmlNode->{self::DEFAULT_TAG_NAME} ) { $value = $this->getExternalParser()->replaceVariables( @@ -220,17 +223,17 @@ class Node { return $value; } - protected function getValueWithData( \SimpleXMLElement $xmlNode ) { + protected function getValueWithData( SimpleXMLElement $xmlNode ) { $value = $this->extractDataFromSource( $xmlNode ); return $value ?: $this->getInnerValue( $xmlNode ); } - protected function getInnerValue( \SimpleXMLElement $xmlNode ) { + protected function getInnerValue( SimpleXMLElement $xmlNode ) { return $this->getExternalParser()->parseRecursive( (string)$xmlNode ); } - protected function getXmlAttribute( \SimpleXMLElement $xmlNode, $attribute ) { + protected function getXmlAttribute( SimpleXMLElement $xmlNode, $attribute ) { return ( isset( $xmlNode[$attribute] ) ) ? (string)$xmlNode[$attribute] : null; } @@ -244,11 +247,11 @@ class Node { } /** - * @param \SimpleXMLElement $xmlNode + * @param SimpleXMLElement $xmlNode * * @return mixed */ - protected function extractDataFromSource( \SimpleXMLElement $xmlNode ) { + protected function extractDataFromSource( SimpleXMLElement $xmlNode ) { $source = $this->getXmlAttribute( $xmlNode, self::DATA_SRC_ATTR_NAME ); return ( !empty( $source ) || $source == '0' ) ? $this->getInfoboxData( $source ) @@ -256,11 +259,11 @@ class Node { } /** - * @param \SimpleXMLElement $xmlNode + * @param SimpleXMLElement $xmlNode * * @return array */ - protected function extractSourcesFromNode( \SimpleXMLElement $xmlNode ) { + protected function extractSourcesFromNode( SimpleXMLElement $xmlNode ) { $sources = $this->hasPrimarySource( $xmlNode ) ? [ $this->getXmlAttribute( $xmlNode, self::DATA_SRC_ATTR_NAME ) ] : []; @@ -274,11 +277,11 @@ class Node { return $sources; } - protected function hasPrimarySource( \SimpleXMLElement $xmlNode ) { + protected function hasPrimarySource( SimpleXMLElement $xmlNode ) { return (bool)$this->getXmlAttribute( $xmlNode, self::DATA_SRC_ATTR_NAME ); } - protected function matchVariables( \SimpleXMLElement $node, array $source ) { + protected function matchVariables( SimpleXMLElement $node, array $source ) { preg_match_all( self::EXTRACT_SOURCE_REGEX, (string)$node, $sources ); return array_unique( array_merge( $source, $sources[1] ) ); diff --git a/includes/services/Parser/Nodes/NodeAudio.php b/includes/services/Parser/Nodes/NodeAudio.php index 73d7363..0f524f3 100644 --- a/includes/services/Parser/Nodes/NodeAudio.php +++ b/includes/services/Parser/Nodes/NodeAudio.php @@ -1,4 +1,5 @@ getName(); - $className = 'PortableInfobox\\Parser\\Nodes\\' . 'Node' . - mb_convert_case( mb_strtolower( $tagType ), MB_CASE_TITLE ); + $className = Node::class . mb_convert_case( mb_strtolower( $tagType ), MB_CASE_TITLE ); if ( class_exists( $className ) ) { - /* @var $instance \PortableInfobox\Parser\Nodes\Node */ + /* @var $instance Node */ $instance = new $className( $xmlNode, $data ); if ( $instance instanceof Node ) { diff --git a/includes/services/Parser/Nodes/NodeGroup.php b/includes/services/Parser/Nodes/NodeGroup.php index 2582748..f2c1c26 100644 --- a/includes/services/Parser/Nodes/NodeGroup.php +++ b/includes/services/Parser/Nodes/NodeGroup.php @@ -1,4 +1,5 @@ query( '//div[@class=\'tabbertab\']' ); foreach ( $divs as $div ) { if ( preg_match( '# src="(?:[^"]*/)?(?:\d+px-)?([^"]*?)"#', $doc->saveXml( $div ), $out ) ) { @@ -137,14 +143,14 @@ class NodeMedia extends Node { */ private function getImageData( $title, $alt, $caption ) { $helper = $this->getImageHelper(); - $titleObj = $title instanceof \Title ? $title : $this->getImageAsTitleObject( $title ); + $titleObj = $title instanceof Title ? $title : $this->getImageAsTitleObject( $title ); $fileObj = $helper->getFile( $titleObj ); if ( !isset( $fileObj ) || !$this->isTypeAllowed( $fileObj->getMediaType() ) ) { return []; } - if ( $titleObj instanceof \Title ) { + if ( $titleObj instanceof Title ) { $this->getExternalParser()->addImage( $titleObj ); } @@ -164,8 +170,8 @@ class NodeMedia extends Node { if ( $image['isImage'] ) { $image = array_merge( $image, $helper->extendImageData( $fileObj, - \PortableInfoboxRenderService::DEFAULT_DESKTOP_THUMBNAIL_WIDTH, - \PortableInfoboxRenderService::DEFAULT_DESKTOP_INFOBOX_WIDTH + PortableInfoboxRenderService::DEFAULT_DESKTOP_THUMBNAIL_WIDTH, + PortableInfoboxRenderService::DEFAULT_DESKTOP_INFOBOX_WIDTH ) ); } @@ -199,7 +205,7 @@ class NodeMedia extends Node { private function getImageAsTitleObject( $imageName ) { $contLang = MediaWikiServices::getInstance()->getContentLanguage(); - $title = \Title::makeTitleSafe( + $title = Title::makeTitleSafe( NS_FILE, FileNamespaceSanitizeHelper::getInstance()->sanitizeImageFileName( $imageName, $contLang ) ); @@ -216,7 +222,7 @@ class NodeMedia extends Node { /** * Returns image url for given image title - * @param \File|null $file + * @param File|null $file * @return string url or '' if image doesn't exist */ public function resolveImageUrl( $file ) { diff --git a/includes/services/Parser/Nodes/NodeNavigation.php b/includes/services/Parser/Nodes/NodeNavigation.php index e155362..ed0e9c4 100644 --- a/includes/services/Parser/Nodes/NodeNavigation.php +++ b/includes/services/Parser/Nodes/NodeNavigation.php @@ -1,4 +1,5 @@ 'XML_ERR_TAG_NOT_FINISHED' ]; - /* @var $templateEngine PortableInfobox\Helpers\PortableInfoboxTemplateEngine */ + /* @var $templateEngine PortableInfoboxTemplateEngine */ private $templateEngine; public function __construct( $errorList ) { diff --git a/includes/specials/SpecialPortableInfoboxBuilder.php b/includes/specials/SpecialPortableInfoboxBuilder.php index 780d93f..5ec5513 100644 --- a/includes/specials/SpecialPortableInfoboxBuilder.php +++ b/includes/specials/SpecialPortableInfoboxBuilder.php @@ -1,5 +1,7 @@ getConfig()->get( 'NamespaceProtection' )[NS_TEMPLATE][0] ?? ''; @@ -17,7 +19,7 @@ class SpecialPortableInfoboxBuilder extends SpecialPage { $out->addModules( [ 'ext.PortableInfobox.styles', 'ext.PortableInfoboxBuilder' ] ); $out->addHTML( '
' . - new OOUI\ProgressBarWidget( [ 'progress' => false ] ) . + new ProgressBarWidget( [ 'progress' => false ] ) . '
' ); } diff --git a/tests/phpunit/InfoboxParamsValidatorTest.php b/tests/phpunit/InfoboxParamsValidatorTest.php index 05f2bc4..14b9246 100644 --- a/tests/phpunit/InfoboxParamsValidatorTest.php +++ b/tests/phpunit/InfoboxParamsValidatorTest.php @@ -1,15 +1,19 @@ InfoboxParamsValidator = new PortableInfobox\Helpers\InfoboxParamsValidator(); + $this->InfoboxParamsValidator = new InfoboxParamsValidator(); } protected function tearDown(): void { @@ -22,7 +26,7 @@ class InfoboxParamsValidatorTest extends MediaWikiIntegrationTestCase { * @dataProvider infoboxParamsFailValidationDataProvider */ public function testInfoboxParamsFailValidation( $params ) { - $this->expectException( PortableInfobox\Helpers\InvalidInfoboxParamsException::class ); + $this->expectException( InvalidInfoboxParamsException::class ); $this->InfoboxParamsValidator->validateParams( $params ); } diff --git a/tests/phpunit/MediaWikiParserTest.php b/tests/phpunit/MediaWikiParserTest.php index e7a0e85..a0c5773 100644 --- a/tests/phpunit/MediaWikiParserTest.php +++ b/tests/phpunit/MediaWikiParserTest.php @@ -1,10 +1,11 @@ "; - $result = \BlockLevelPass::doBlockLevels( $aside, true ); + $result = BlockLevelPass::doBlockLevels( $aside, true ); $this->assertEquals( $aside, $result ); } @@ -54,7 +55,7 @@ class MediaWikiParserTest extends MediaWikiIntegrationTestCase { */ public function testWrapper( $wikitext, $params, $newline ) { $frame = $this->parser->getPreprocessor()->newCustomFrame( $params ); - $wrapper = new PortableInfobox\Parser\MediaWikiParserService( $this->parser, $frame ); + $wrapper = new MediaWikiParserService( $this->parser, $frame ); $output = $wrapper->parseRecursive( $wikitext ); diff --git a/tests/phpunit/PortableInfoboxRenderServiceTest.php b/tests/phpunit/PortableInfoboxRenderServiceTest.php index b387f82..50cdd63 100644 --- a/tests/phpunit/PortableInfoboxRenderServiceTest.php +++ b/tests/phpunit/PortableInfoboxRenderServiceTest.php @@ -2,6 +2,7 @@ /** * @group PortableInfobox * @covers PortableInfoboxRenderService + * @coversDefaultClass PortableInfoboxRenderService */ class PortableInfoboxRenderServiceTest extends MediaWikiIntegrationTestCase { @@ -23,8 +24,8 @@ class PortableInfoboxRenderServiceTest extends MediaWikiIntegrationTestCase { } /** - * @covers PortableInfoboxRenderService::renderInfobox - * @covers PortableInfobox\Helpers\PortableInfoboxTemplateEngine + * @covers ::renderInfobox + * @covers \PortableInfobox\Helpers\PortableInfoboxTemplateEngine * @param $input * @param $expectedOutput * @param $description diff --git a/tests/phpunit/PortableInfoboxTemplateEngineTest.php b/tests/phpunit/PortableInfoboxTemplateEngineTest.php index e0f0cb6..1c97377 100644 --- a/tests/phpunit/PortableInfoboxTemplateEngineTest.php +++ b/tests/phpunit/PortableInfoboxTemplateEngineTest.php @@ -1,18 +1,22 @@ assertEquals( $result, - PortableInfobox\Helpers\PortableInfoboxTemplateEngine::isSupportedType( $type ), + PortableInfoboxTemplateEngine::isSupportedType( $type ), $description ); } diff --git a/tests/phpunit/XmlParserTest.php b/tests/phpunit/XmlParserTest.php index 41c1097..d5e34b1 100644 --- a/tests/phpunit/XmlParserTest.php +++ b/tests/phpunit/XmlParserTest.php @@ -1,14 +1,17 @@ <{$tag}>{$content}"; - $result = PortableInfobox\Parser\XmlParser::parseXmlString( $markup ); + $result = XmlParser::parseXmlString( $markup ); $this->assertEquals( $content, (string)$result->{$tag} ); } @@ -25,7 +28,7 @@ class XmlParserTest extends MediaWikiIntegrationTestCase { * @dataProvider entitiesTestDataProvider */ public function testHTMLEntities( $markup, $expectedResult ) { - $result = PortableInfobox\Parser\XmlParser::parseXmlString( $markup ); + $result = XmlParser::parseXmlString( $markup ); $this->assertEquals( $expectedResult, $result[ 0 ] ); } diff --git a/tests/phpunit/helpers/FileNamespaceSanitizeHelperTest.php b/tests/phpunit/helpers/FileNamespaceSanitizeHelperTest.php index ada887d..ad740a0 100644 --- a/tests/phpunit/helpers/FileNamespaceSanitizeHelperTest.php +++ b/tests/phpunit/helpers/FileNamespaceSanitizeHelperTest.php @@ -5,7 +5,7 @@ use PortableInfobox\Helpers\FileNamespaceSanitizeHelper; /** * @group PortableInfobox - * @covers PortableInfobox\Helpers\FileNamespaceSanitizeHelper + * @covers \PortableInfobox\Helpers\FileNamespaceSanitizeHelper */ class FileNamespaceSanitizeHelperTest extends MediaWikiIntegrationTestCase { /** @var FileNamespaceSanitizeHelper $fileNamespaceSanitizeHelper */ diff --git a/tests/phpunit/helpers/PortableInfoboxImagesHelperTest.php b/tests/phpunit/helpers/PortableInfoboxImagesHelperTest.php index 9b09060..d94b864 100644 --- a/tests/phpunit/helpers/PortableInfoboxImagesHelperTest.php +++ b/tests/phpunit/helpers/PortableInfoboxImagesHelperTest.php @@ -4,7 +4,7 @@ use PortableInfobox\Helpers\PortableInfoboxImagesHelper; /** * @group PortableInfobox - * @covers PortableInfobox\Helpers\PortableInfoboxImagesHelper + * @covers \PortableInfobox\Helpers\PortableInfoboxImagesHelper */ class PortableInfoboxImagesHelperTest extends MediaWikiIntegrationTestCase { private $helper; diff --git a/tests/phpunit/helpers/PortableInfoboxParsingHelperTest.php b/tests/phpunit/helpers/PortableInfoboxParsingHelperTest.php index 5c55426..926a6ff 100644 --- a/tests/phpunit/helpers/PortableInfoboxParsingHelperTest.php +++ b/tests/phpunit/helpers/PortableInfoboxParsingHelperTest.php @@ -1,9 +1,11 @@ getMockBuilder( PortableInfobox\Helpers\PortableInfoboxParsingHelper::class ) + $helper = $this->getMockBuilder( PortableInfoboxParsingHelper::class ) ->setMethods( [ 'fetchArticleContent' ] ) ->getMock(); $helper->expects( $this->once() ) diff --git a/tests/phpunit/nodes/NodeDataTest.php b/tests/phpunit/nodes/NodeDataTest.php index ff322fb..1e2c748 100644 --- a/tests/phpunit/nodes/NodeDataTest.php +++ b/tests/phpunit/nodes/NodeDataTest.php @@ -1,12 +1,18 @@ assertEquals( $expected, $node->getSources() ); } @@ -77,7 +83,7 @@ class NodeDataTest extends MediaWikiIntegrationTestCase { } /** - * @covers PortableInfobox\Parser\Nodes\Node::getSourcesMetadata + * @covers ::getSourcesMetadata * @dataProvider sourcesMetadataDataProvider * * @param $markup @@ -85,7 +91,7 @@ class NodeDataTest extends MediaWikiIntegrationTestCase { * @param $expected */ public function testSourcesMetadata( $markup, $params, $expected ) { - $node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params ); + $node = NodeFactory::newFromXML( $markup, $params ); $this->assertEquals( $expected, $node->getSourcesMetadata() ); } @@ -332,8 +338,8 @@ class NodeDataTest extends MediaWikiIntegrationTestCase { } /** - * @covers PortableInfobox\Parser\Nodes\Node::getMetadata - * @covers PortableInfobox\Parser\Nodes\NodeInfobox::getMetadata + * @covers ::getMetadata + * @covers \PortableInfobox\Parser\Nodes\NodeInfobox::getMetadata * @dataProvider metadataDataProvider * * @param $markup @@ -341,7 +347,7 @@ class NodeDataTest extends MediaWikiIntegrationTestCase { * @param $expected */ public function testMetadata( $markup, $params, $expected ) { - $node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params ); + $node = NodeFactory::newFromXML( $markup, $params ); $this->assertEquals( $expected, $node->getMetadata() ); } @@ -493,28 +499,28 @@ class NodeDataTest extends MediaWikiIntegrationTestCase { } /** - * @covers PortableInfobox\Parser\Nodes\Node::getExternalParser - * @covers PortableInfobox\Parser\Nodes\Node::setExternalParser + * @covers ::getExternalParser + * @covers ::setExternalParser * @dataProvider parserTestDataProvider * * @param $parser * @param $expected */ public function testExternalParserSetUp( $parser, $expected ) { - $node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( '', [] ); + $node = NodeFactory::newFromXML( '', [] ); $this->assertEquals( $expected, $node->setExternalParser( $parser )->getExternalParser() ); } public function parserTestDataProvider() { return [ - [ null, new PortableInfobox\Parser\SimpleParser() ], - [ new PortableInfobox\Parser\SimpleParser(), new PortableInfobox\Parser\SimpleParser() ] + [ null, new SimpleParser() ], + [ new SimpleParser(), new SimpleParser() ] ]; } /** - * @covers PortableInfobox\Parser\Nodes\NodeData::getData + * @covers \PortableInfobox\Parser\Nodes\NodeData::getData * @dataProvider dataProvider * * @param $markup @@ -522,7 +528,7 @@ class NodeDataTest extends MediaWikiIntegrationTestCase { * @param $expected */ public function testData( $markup, $params, $expected ) { - $node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params ); + $node = NodeFactory::newFromXML( $markup, $params ); $this->assertEquals( $expected, $node->getData() ); } @@ -727,9 +733,9 @@ class NodeDataTest extends MediaWikiIntegrationTestCase { } /** - * @covers PortableInfobox\Parser\Nodes\Node::getRenderData - * @covers PortableInfobox\Parser\Nodes\NodeData::getLayout - * @covers PortableInfobox\Parser\Nodes\NodeData::getSpan + * @covers ::getRenderData + * @covers \PortableInfobox\Parser\Nodes\NodeData::getLayout + * @covers \PortableInfobox\Parser\Nodes\NodeData::getSpan * @dataProvider dataRenderProvider * * @param $markup @@ -737,7 +743,7 @@ class NodeDataTest extends MediaWikiIntegrationTestCase { * @param $expected */ public function testRenderData( $markup, $params, $expected ) { - $node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params ); + $node = NodeFactory::newFromXML( $markup, $params ); $this->assertEquals( $expected, $node->getRenderData() ); } @@ -853,7 +859,7 @@ class NodeDataTest extends MediaWikiIntegrationTestCase { } /** - * @covers PortableInfobox\Parser\Nodes\Node::isType + * @covers ::isType * @dataProvider isTypeDataProvider * * @param $markup @@ -861,7 +867,7 @@ class NodeDataTest extends MediaWikiIntegrationTestCase { * @param $expected */ public function testIsType( $markup, $typeToCheck, $expected ) { - $node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, [] ); + $node = NodeFactory::newFromXML( $markup, [] ); $this->assertEquals( $expected, $node->isType( $typeToCheck ) ); } @@ -875,14 +881,14 @@ class NodeDataTest extends MediaWikiIntegrationTestCase { } /** - * @covers PortableInfobox\Parser\Nodes\Node::getType + * @covers ::getType * @dataProvider typeDataProvider * * @param $markup * @param $expected */ public function testType( $markup, $expected ) { - $node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, [] ); + $node = NodeFactory::newFromXML( $markup, [] ); $this->assertEquals( $expected, $node->getType() ); } @@ -901,7 +907,7 @@ class NodeDataTest extends MediaWikiIntegrationTestCase { $string = ''; $xml = simplexml_load_string( $string ); - $node = new PortableInfobox\Parser\Nodes\NodeData( $xml, [ 'season' => $season ] ); + $node = new NodeData( $xml, [ 'season' => $season ] ); $nodeData = $node->getData(); $this->assertTrue( $node->isEmpty( $nodeData ) == $expectedOutput ); } diff --git a/tests/phpunit/nodes/NodeFactoryTest.php b/tests/phpunit/nodes/NodeFactoryTest.php index 09447b0..2336707 100644 --- a/tests/phpunit/nodes/NodeFactoryTest.php +++ b/tests/phpunit/nodes/NodeFactoryTest.php @@ -1,10 +1,17 @@ assertEquals( $expected, get_class( $node ) ); } @@ -35,23 +42,23 @@ class NodeFactoryTest extends MediaWikiIntegrationTestCase { return [ [ '', - PortableInfobox\Parser\Nodes\NodeInfobox::class + NodeInfobox::class ], [ '', - PortableInfobox\Parser\Nodes\NodeData::class + NodeData::class ], [ '', - PortableInfobox\Parser\Nodes\NodeMedia::class + NodeMedia::class ], [ '', - PortableInfobox\Parser\Nodes\NodeImage::class + NodeImage::class ], [ '', - PortableInfobox\Parser\Nodes\NodeUnimplemented::class + NodeUnimplemented::class ] ]; } diff --git a/tests/phpunit/nodes/NodeGroupTest.php b/tests/phpunit/nodes/NodeGroupTest.php index 6919990..6c10c47 100644 --- a/tests/phpunit/nodes/NodeGroupTest.php +++ b/tests/phpunit/nodes/NodeGroupTest.php @@ -1,19 +1,23 @@ assertEquals( $expected, $node->getData()['collapse'] ); } @@ -27,15 +31,15 @@ class NodeGroupTest extends MediaWikiIntegrationTestCase { } /** - * @covers PortableInfobox\Parser\Nodes\NodeGroup::getData - * @covers PortableInfobox\Parser\Nodes\NodeGroup::getRenderData + * @covers ::getData + * @covers ::getRenderData * @dataProvider groupNodeRowItemsTestProvider * * @param $markup * @param $expected */ public function testNodeGroupRowItems( $markup, $expected ) { - $node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup ); + $node = NodeFactory::newFromXML( $markup ); $this->assertEquals( $expected, $node->getData()['row-items'] ); $this->assertEquals( $expected, $node->getRenderData()['data']['row-items'] ); } @@ -51,7 +55,7 @@ class NodeGroupTest extends MediaWikiIntegrationTestCase { } /** - * @covers PortableInfobox\Parser\Nodes\NodeGroup::getData + * @covers ::getData * @dataProvider groupNodeTestProvider * * @param $markup @@ -59,7 +63,7 @@ class NodeGroupTest extends MediaWikiIntegrationTestCase { * @param $expected */ public function testNodeGroup( $markup, $params, $expected ) { - $node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params ); + $node = NodeFactory::newFromXML( $markup, $params ); $this->assertEquals( $expected, $node->getData() ); } diff --git a/tests/phpunit/nodes/NodeHeaderTest.php b/tests/phpunit/nodes/NodeHeaderTest.php index 294028e..ed2a5a3 100644 --- a/tests/phpunit/nodes/NodeHeaderTest.php +++ b/tests/phpunit/nodes/NodeHeaderTest.php @@ -1,20 +1,24 @@ assertEquals( $expected, $node->getData() ); } diff --git a/tests/phpunit/nodes/NodeInfoboxTest.php b/tests/phpunit/nodes/NodeInfoboxTest.php index e7fe0c0..6a21afb 100644 --- a/tests/phpunit/nodes/NodeInfoboxTest.php +++ b/tests/phpunit/nodes/NodeInfoboxTest.php @@ -1,20 +1,23 @@ assertEquals( $expected, $node->getParams() ); } diff --git a/tests/phpunit/nodes/NodeMediaTest.php b/tests/phpunit/nodes/NodeMediaTest.php index a4bfc5b..731dc6a 100644 --- a/tests/phpunit/nodes/NodeMediaTest.php +++ b/tests/phpunit/nodes/NodeMediaTest.php @@ -4,16 +4,18 @@ use PortableInfobox\Helpers\PortableInfoboxDataBag; use PortableInfobox\Helpers\PortableInfoboxImagesHelper; use PortableInfobox\Parser\Nodes\NodeFactory; use PortableInfobox\Parser\Nodes\NodeMedia; +use PortableInfobox\Parser\XmlMarkupParseErrorException; /** * @group PortableInfobox - * @covers PortableInfobox\Parser\Nodes\NodeMedia + * @covers \PortableInfobox\Parser\Nodes\NodeMedia + * @coversDefaultClass \PortableInfobox\Parser\Nodes\NodeMedia */ class NodeMediaTest extends MediaWikiIntegrationTestCase { /** - * @covers PortableInfobox\Parser\Nodes\NodeMedia::getGalleryData - * @covers PortableInfobox\Helpers\PortableInfoboxDataBag + * @covers ::getGalleryData + * @covers \PortableInfobox\Helpers\PortableInfoboxDataBag * @dataProvider galleryDataProvider * @param $marker * @param $expected @@ -83,7 +85,7 @@ class NodeMediaTest extends MediaWikiIntegrationTestCase { } /** - * @covers PortableInfobox\Parser\Nodes\NodeMedia::getTabberData + * @covers ::getTabberData */ public function testTabberData() { $input = '
' . @@ -98,7 +100,7 @@ class NodeMediaTest extends MediaWikiIntegrationTestCase { } /** - * @covers PortableInfobox\Parser\Nodes\NodeMedia::getMarkers + * @covers ::getMarkers * @dataProvider markersProvider * @param $ext * @param $value @@ -131,7 +133,7 @@ class NodeMediaTest extends MediaWikiIntegrationTestCase { } /** - * @covers PortableInfobox\Parser\Nodes\NodeMedia::getData + * @covers ::getData * @dataProvider dataProvider * * @param $markup @@ -298,7 +300,7 @@ class NodeMediaTest extends MediaWikiIntegrationTestCase { } /** - * @covers PortableInfobox\Parser\Nodes\NodeMedia::isEmpty + * @covers ::isEmpty * @dataProvider isEmptyProvider * * @param $markup @@ -318,7 +320,7 @@ class NodeMediaTest extends MediaWikiIntegrationTestCase { } /** - * @covers PortableInfobox\Parser\Nodes\NodeMedia::getSources + * @covers ::getSources * @dataProvider sourcesProvider * * @param $markup @@ -388,19 +390,19 @@ class NodeMediaTest extends MediaWikiIntegrationTestCase { } /** - * @covers PortableInfobox\Parser\Nodes\NodeMedia::isTypeAllowed - * @covers PortableInfobox\Parser\Nodes\NodeAudio - * @covers PortableInfobox\Parser\Nodes\NodeImage - * @covers PortableInfobox\Parser\Nodes\NodeVideo + * @covers ::isTypeAllowed + * @covers \PortableInfobox\Parser\Nodes\NodeAudio + * @covers \PortableInfobox\Parser\Nodes\NodeImage + * @covers \PortableInfobox\Parser\Nodes\NodeVideo * @dataProvider isTypeAllowedProvider * @param $markup * @param $expected - * @throws PortableInfobox\Parser\XmlMarkupParseErrorException + * @throws XmlMarkupParseErrorException */ public function testIsTypeAllowed( $markup, $expected ) { $types = [ MEDIATYPE_BITMAP, MEDIATYPE_DRAWING, MEDIATYPE_VIDEO, MEDIATYPE_AUDIO, 'unknown' ]; - $node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, [] ); + $node = NodeFactory::newFromXML( $markup, [] ); $reflection = new ReflectionClass( $node ); $reflection_method = $reflection->getMethod( 'isTypeAllowed' ); diff --git a/tests/phpunit/nodes/NodeNavigationTest.php b/tests/phpunit/nodes/NodeNavigationTest.php index 69bee1b..eb8a52d 100644 --- a/tests/phpunit/nodes/NodeNavigationTest.php +++ b/tests/phpunit/nodes/NodeNavigationTest.php @@ -1,20 +1,24 @@ assertEquals( $expected, $node->getData() ); } @@ -45,7 +49,7 @@ class NodeNavigationTest extends MediaWikiIntegrationTestCase { */ public function testIsEmpty( $string, $expectedOutput ) { $xml = simplexml_load_string( $string ); - $node = new PortableInfobox\Parser\Nodes\NodeNavigation( $xml, [] ); + $node = new NodeNavigation( $xml, [] ); $data = $node->getData(); $this->assertTrue( $node->isEmpty( $data ) == $expectedOutput ); } diff --git a/tests/phpunit/nodes/NodeTitleTest.php b/tests/phpunit/nodes/NodeTitleTest.php index 35cd364..1ff7f19 100644 --- a/tests/phpunit/nodes/NodeTitleTest.php +++ b/tests/phpunit/nodes/NodeTitleTest.php @@ -1,12 +1,16 @@ assertEquals( $expected, $node->getData() ); } diff --git a/tests/phpunit/nodes/NodeUnimplementedTest.php b/tests/phpunit/nodes/NodeUnimplementedTest.php index 4886ed6..be24b2f 100644 --- a/tests/phpunit/nodes/NodeUnimplementedTest.php +++ b/tests/phpunit/nodes/NodeUnimplementedTest.php @@ -1,18 +1,20 @@ expectException( PortableInfobox\Parser\Nodes\UnimplementedNodeException::class ); + $this->expectException( UnimplementedNodeException::class ); ( new NodeUnimplemented( - PortableInfobox\Parser\XmlParser::parseXmlString( "" ), + XmlParser::parseXmlString( "" ), [] ) )->getData(); }