Passed
Push — master ( 9538c8...6c70b1 )
by Dispositif
07:44
created

ExternPageFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 1
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of dispositif/wikibot application (@github)
4
 * 2019-2023 © Philippe M./Irønie  <[email protected]>
5
 * For the full copyright and MIT license information, view the license file.
6
 */
7
8
declare(strict_types=1);
9
10
namespace App\Domain\ExternLink;
11
12
use App\Application\Http\ExternHttpClient;
13
use App\Infrastructure\InternetDomainParser;
14
use App\Infrastructure\TagParser;
15
use DomainException;
16
use Exception;
17
use Psr\Log\LoggerInterface;
18
19
class ExternPageFactory
20
{
21
    private function __construct() { }
22
23
    /**
24
     * @throws Exception
25
     */
26
    public static function fromURL($url, ExternHttpClientInterface $httpClient,LoggerInterface $logger = null): ExternPage
27
    {
28
        if (!ExternHttpClient::isHttpURL($url)) {
29
            throw new Exception('string is not an URL '.$url);
30
        }
31
        $html = $httpClient->getHTML($url, true);
32
        if (empty($html)) {
33
            throw new DomainException('No HTML from requested URL '.$url);
34
        }
35
36
        return new ExternPage($url, $html, new TagParser(), new InternetDomainParser(), $logger);
37
    }
38
39
}
40