URLRegexParser   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
c 1
b 0
f 1
dl 0
loc 28
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 7 2
A __construct() 0 3 1
A isValidUrl() 0 2 1
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
}