Passed
Push — master ( 707ddf...aa8b2f )
by Sebastian
04:56
created

ConvertHelper_URLFinder_Detector_HTMLAttributes   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 14
c 1
b 0
f 0
dl 0
loc 34
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A filterSubject() 0 3 1
A getRunPosition() 0 3 1
A isValidFor() 0 3 1
A detect() 0 15 4
1
<?php
2
/**
3
 * File containing the class {@see ConvertHelper_URLFinder_Detector_HTMLAttributes}.
4
 *
5
 * @package AppUtils
6
 * @subpackage URLInfo
7
 * @see ConvertHelper_URLFinder_Detector_HTMLAttributes
8
 */
9
10
declare(strict_types=1);
11
12
namespace AppUtils;
13
14
/**
15
 *
16
 * @package AppUtils
17
 * @subpackage URLInfo
18
 * @author Sebastian Mordziol <[email protected]>
19
 */
20
class ConvertHelper_URLFinder_Detector_HTMLAttributes extends ConvertHelper_URLFinder_Detector
21
{
22
    const REGEX = '/(href|src)="(.*)"/siU';
23
24
    public function getRunPosition() : string
25
    {
26
        return self::RUN_AFTER;
27
    }
28
29
    public function isValidFor(string $subject) : bool
30
    {
31
        return ConvertHelper::isStringHTML($subject);
32
    }
33
34
    protected function filterSubject(string $subject) : string
35
    {
36
        return $subject;
37
    }
38
39
    protected function detect(string $subject) : array
40
    {
41
        $matches = array();
42
        preg_match_all(self::REGEX, $subject, $matches, PREG_PATTERN_ORDER);
43
44
        $result = array();
45
        $matches = array_unique($matches[2]);
46
        foreach($matches as $match) {
47
            $match = trim($match);
48
            if(!empty($match) && !in_array($match, $result)) {
49
                $result[] = $match;
50
            }
51
        }
52
53
        return $result;
54
    }
55
}
56