URLRegexParser::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Jackal\Downloader\Parser;
4
5
class URLRegexParser
6
{
7
    protected $downloaderClass;
8
9
    public function __construct(string $downloaderClass)
10
    {
11
        $this->downloaderClass = $downloaderClass;
12
    }
13
14
    /**
15
     * @param string $publicWatchUrl
16
     * @return string|null
17
     */
18
    public function parse(string $publicWatchUrl) : ?string{
19
        preg_match($this->downloaderClass::getPublicUrlRegex(), $publicWatchUrl, $matches);
20
        if(isset($matches[1])){
21
            return $matches[1];
22
        }
23
24
        return null;
25
    }
26
27
    /**
28
     * @param string $publicWatchUrl
29
     * @return bool
30
     */
31
    public function isValidUrl(string $publicWatchUrl) : bool {
32
        return $this->parse($publicWatchUrl) == true;
33
    }
34
}