Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
WikimediaSourceUrlNormalizer
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 normalize
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace FileImporter\Services;
4
5use FileImporter\Data\SourceUrl;
6use MediaWiki\Utils\UrlUtils;
7
8/**
9 * A normalizer for SourceUrls that are known to point to a Wikimedia wiki. In other words: This
10 * class should only encode rules that are exclusive to wikis in the Wikimedia cluster.
11 *
12 * @license GPL-2.0-or-later
13 * @author Thiemo Kreuz
14 */
15class WikimediaSourceUrlNormalizer extends MediaWikiSourceUrlNormalizer {
16
17    /**
18     * @return SourceUrl
19     */
20    public function normalize( SourceUrl $sourceUrl ) {
21        $parts = parent::normalize( $sourceUrl )->getParsedUrl();
22        $parts['host'] = strtr( $parts['host'], [
23            '.m.' => '.',
24        ] );
25        $url = UrlUtils::assemble( $parts );
26
27        return new SourceUrl( $url );
28    }
29
30}