Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
SourceSite
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
6 / 6
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isSourceSiteFor
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getLinkPrefix
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 retrieveImportDetails
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getImportTitleChecker
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getPostImportHandler
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace FileImporter\Services;
4
5use FileImporter\Data\ImportDetails;
6use FileImporter\Data\SourceUrl;
7use FileImporter\Interfaces\DetailRetriever;
8use FileImporter\Interfaces\ImportTitleChecker;
9use FileImporter\Interfaces\LinkPrefixLookup;
10use FileImporter\Interfaces\PostImportHandler;
11use FileImporter\Interfaces\SourceUrlChecker;
12
13/**
14 * A SourceSite object is composed of services which can import files from configurable URLs. The
15 * SourceUrlChecker provided via the constructor dictates which SourceUrls are going to be processed
16 * by this service.
17 *
18 * @license GPL-2.0-or-later
19 * @author Addshore
20 */
21class SourceSite {
22
23    public function __construct(
24        private readonly SourceUrlChecker $sourceUrlChecker,
25        private readonly DetailRetriever $detailRetriever,
26        private readonly ImportTitleChecker $importTitleChecker,
27        private readonly SourceUrlNormalizer $sourceUrlNormalizer,
28        private readonly LinkPrefixLookup $linkPrefixLookup,
29        private readonly PostImportHandler $postImportHandler,
30    ) {
31    }
32
33    /**
34     * @return bool is this the source site for the given URL
35     */
36    public function isSourceSiteFor( SourceUrl $sourceUrl ): bool {
37        $sourceUrl = $this->sourceUrlNormalizer->normalize( $sourceUrl );
38        return $this->sourceUrlChecker->checkSourceUrl( $sourceUrl );
39    }
40
41    public function getLinkPrefix( SourceUrl $sourceUrl ): string {
42        $sourceUrl = $this->sourceUrlNormalizer->normalize( $sourceUrl );
43        return $this->linkPrefixLookup->getPrefix( $sourceUrl );
44    }
45
46    public function retrieveImportDetails( SourceUrl $sourceUrl ): ImportDetails {
47        $sourceUrl = $this->sourceUrlNormalizer->normalize( $sourceUrl );
48        return $this->detailRetriever->getImportDetails( $sourceUrl );
49    }
50
51    public function getImportTitleChecker(): ImportTitleChecker {
52        return $this->importTitleChecker;
53    }
54
55    public function getPostImportHandler(): PostImportHandler {
56        return $this->postImportHandler;
57    }
58
59}