Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
SourceSite
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
6 / 6
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
6 / 6
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    private SourceUrlChecker $sourceUrlChecker;
24    private DetailRetriever $detailRetriever;
25    private ImportTitleChecker $importTitleChecker;
26    private SourceUrlNormalizer $sourceUrlNormalizer;
27    private LinkPrefixLookup $linkPrefixLookup;
28    private PostImportHandler $postImportHandler;
29
30    public function __construct(
31        SourceUrlChecker $sourceUrlChecker,
32        DetailRetriever $detailRetriever,
33        ImportTitleChecker $importTitleChecker,
34        SourceUrlNormalizer $sourceUrlNormalizer,
35        LinkPrefixLookup $linkPrefixLookup,
36        PostImportHandler $postImportHandler
37    ) {
38        $this->sourceUrlChecker = $sourceUrlChecker;
39        $this->detailRetriever = $detailRetriever;
40        $this->importTitleChecker = $importTitleChecker;
41        $this->sourceUrlNormalizer = $sourceUrlNormalizer;
42        $this->linkPrefixLookup = $linkPrefixLookup;
43        $this->postImportHandler = $postImportHandler;
44    }
45
46    /**
47     * @return bool is this the source site for the given URL
48     */
49    public function isSourceSiteFor( SourceUrl $sourceUrl ): bool {
50        $sourceUrl = $this->sourceUrlNormalizer->normalize( $sourceUrl );
51        return $this->sourceUrlChecker->checkSourceUrl( $sourceUrl );
52    }
53
54    public function getLinkPrefix( SourceUrl $sourceUrl ): string {
55        $sourceUrl = $this->sourceUrlNormalizer->normalize( $sourceUrl );
56        return $this->linkPrefixLookup->getPrefix( $sourceUrl );
57    }
58
59    public function retrieveImportDetails( SourceUrl $sourceUrl ): ImportDetails {
60        $sourceUrl = $this->sourceUrlNormalizer->normalize( $sourceUrl );
61        return $this->detailRetriever->getImportDetails( $sourceUrl );
62    }
63
64    public function getImportTitleChecker(): ImportTitleChecker {
65        return $this->importTitleChecker;
66    }
67
68    public function getPostImportHandler(): PostImportHandler {
69        return $this->postImportHandler;
70    }
71
72}