Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ParsoidWrappingParserOutputProvider
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getParserOutput
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3/**
4 * WikiLambda extension Parsoid wrapper for Wikibase's content injection tracking system
5 *
6 * @file
7 * @ingroup Extensions
8 * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
9 * @license MIT
10 */
11
12namespace MediaWiki\Extension\WikiLambda\ParserFunction;
13
14use MediaWiki\Parser\ParserOutput;
15use Wikibase\Client\ParserOutput\ParserOutputProvider;
16use Wikimedia\Parsoid\Config\StubMetadataCollector;
17use Wikimedia\Parsoid\Core\ContentMetadataCollector;
18
19/**
20 * Provides a ParserOutput for the Parsoid wrapping of the Wikifunctions content.
21 *
22 * @todo This should really be provided by Wikibase, not us, but needs must.
23 */
24class ParsoidWrappingParserOutputProvider implements ParserOutputProvider {
25    public function __construct( private readonly ContentMetadataCollector $contentMetadataCollector ) {
26    }
27
28    public function getParserOutput(): ParserOutput {
29        // In tests, instead of a real ParserOutput Parsoid uses a StubMetadataCollector
30        if ( $this->contentMetadataCollector instanceof StubMetadataCollector ) {
31            $dummyParserOutput = new ParserOutput();
32            $dummyParserOutput->collectMetadata( $this->contentMetadataCollector );
33            return $dummyParserOutput;
34        }
35
36        // ParserOutput implements the ContentMetadataCollector interface, but phan can't
37        // magically know that, so help it out.
38        // @phan-suppress-next-line PhanTypeMismatchReturnSuperType
39        return $this->contentMetadataCollector;
40    }
41}