Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| SourceSiteLocator | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getSourceSite | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace FileImporter\Services; |
| 4 | |
| 5 | use FileImporter\Data\SourceUrl; |
| 6 | use FileImporter\Exceptions\SourceUrlException; |
| 7 | |
| 8 | /** |
| 9 | * SourceSiteLocator for getting a SourceSite service which can handle a given URL. |
| 10 | * |
| 11 | * @license GPL-2.0-or-later |
| 12 | * @author Addshore |
| 13 | */ |
| 14 | class SourceSiteLocator { |
| 15 | |
| 16 | /** |
| 17 | * @param SourceSite[] $sourceSites |
| 18 | */ |
| 19 | public function __construct( |
| 20 | private readonly array $sourceSites, |
| 21 | ) { |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * @throws SourceUrlException when the URL doesn't match a known site |
| 26 | */ |
| 27 | public function getSourceSite( SourceUrl $sourceUrl ): SourceSite { |
| 28 | foreach ( $this->sourceSites as $site ) { |
| 29 | if ( $site->isSourceSiteFor( $sourceUrl ) ) { |
| 30 | return $site; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | throw new SourceUrlException(); |
| 35 | } |
| 36 | |
| 37 | } |