URLRegexParser::parse()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 4
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 7
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
}