Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
SiteTableSourceUrlChecker
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 checkSourceUrl
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3namespace FileImporter\Remote\MediaWiki;
4
5use FileImporter\Data\SourceUrl;
6use FileImporter\Interfaces\SourceUrlChecker;
7use Psr\Log\LoggerInterface;
8use Psr\Log\NullLogger;
9
10/**
11 * This SourceUrlChecker implementation will allow files from mediawiki websites that are contained
12 * in the sites table.
13 *
14 * @license GPL-2.0-or-later
15 * @author Addshore
16 */
17class SiteTableSourceUrlChecker implements SourceUrlChecker {
18    use MediaWikiSourceUrlParser;
19
20    private SiteTableSiteLookup $siteTableSiteLookup;
21    private LoggerInterface $logger;
22
23    public function __construct(
24        SiteTableSiteLookup $siteTableSiteLookup,
25        ?LoggerInterface $logger = null
26    ) {
27        $this->siteTableSiteLookup = $siteTableSiteLookup;
28        $this->logger = $logger ?? new NullLogger();
29    }
30
31    /**
32     * @inheritDoc
33     */
34    public function checkSourceUrl( SourceUrl $sourceUrl ): bool {
35        $site = $this->siteTableSiteLookup->getSite( $sourceUrl );
36
37        if ( !$site ) {
38            $this->logger->error( __METHOD__ . ' failed site check for URL: ' . $sourceUrl->getUrl() );
39            return false;
40        }
41
42        if ( $this->parseTitleFromSourceUrl( $sourceUrl ) === null ) {
43            $this->logger->error( __METHOD__ . ' failed title check for URL: ' . $sourceUrl->getUrl() );
44            return false;
45        }
46
47        return true;
48    }
49
50}